@@ -1,1117 +1,2920 @@ |
| 1 | 1 | // game.js - Main game loop and state management |
| 2 | 2 | |
| 3 | 3 | // Game objects |
| 4 | | -let spider; |
| 5 | | -let obstacles = []; |
| 6 | | -let webStrands = []; |
| 7 | | -let flies = []; |
| 8 | | -let foodBoxes = []; |
| 9 | | -let particles = []; |
| 10 | | -let webNodes = []; |
| 4 | +let spider |
| 5 | +let obstacles = [] |
| 6 | +let webStrands = [] |
| 7 | +let flies = [] |
| 8 | +let foodBoxes = [] |
| 9 | +let particles = [] |
| 10 | +let webNodes = [] |
| 11 | 11 | |
| 12 | 12 | // Game state |
| 13 | | -let isDeployingWeb = false; |
| 14 | | -let currentStrand = null; |
| 15 | | -let spacePressed = false; |
| 16 | | -let isMunching = false; |
| 13 | +let isDeployingWeb = false |
| 14 | +let currentStrand = null |
| 15 | +let spacePressed = false |
| 16 | +let isMunching = false |
| 17 | +let gameOver = false |
| 18 | +let gameOverTimer = 0 |
| 19 | +let deathReason = '' |
| 20 | +let finalScore = 0 |
| 17 | 21 | |
| 18 | 22 | // Resources |
| 19 | | -let webSilk = 100; |
| 20 | | -let maxWebSilk = 100; |
| 21 | | -let silkRechargeRate = 0.05; |
| 22 | | -let silkDrainRate = 2; |
| 23 | +let webSilk = 100 |
| 24 | +let maxWebSilk = 100 |
| 25 | +let silkRechargeRate = 0.05 |
| 26 | +let silkDrainRate = 2 |
| 23 | 27 | |
| 24 | 28 | // Game phases - PHASE 1 UPDATES |
| 25 | | -let gamePhase = 'DUSK'; |
| 26 | | -let phaseTimer = 0; |
| 29 | +let gamePhase = 'DUSK' |
| 30 | +let phaseTimer = 0 |
| 27 | 31 | |
| 28 | 32 | // Phase durations (in frames, 60fps) - PHASE 1 NEW |
| 29 | | -let DAWN_DURATION = 1800; // 30 seconds |
| 30 | | -let DAY_DURATION = 2700; // 45 seconds |
| 31 | | -let DUSK_DURATION = 1800; // 30 seconds (was 1500) |
| 32 | | -let NIGHT_DURATION = 3600; // 60 seconds |
| 33 | | -let TRANSITION_DURATION = 180; // 3 seconds |
| 34 | | - |
| 35 | | -let skyColor1, skyColor2, currentSkyColor1, currentSkyColor2; |
| 36 | | -let moonY = 100; |
| 37 | | -let moonOpacity = 0; |
| 38 | | -let sunY = -50; // PHASE 1 NEW |
| 39 | | -let sunOpacity = 0; // PHASE 1 NEW |
| 33 | +let DAWN_DURATION = 1800 // 30 seconds |
| 34 | +let DAY_DURATION = 2700 // 45 seconds |
| 35 | +let DUSK_DURATION = 1800 // 30 seconds (was 1500) |
| 36 | +let NIGHT_DURATION = 3600 // 60 seconds |
| 37 | +let TRANSITION_DURATION = 180 // 3 seconds |
| 38 | + |
| 39 | +let skyColor1, skyColor2, currentSkyColor1, currentSkyColor2 |
| 40 | +let moonY = 100 |
| 41 | +let moonOpacity = 0 |
| 42 | +let sunY = -50 // PHASE 1 NEW |
| 43 | +let sunOpacity = 0 // PHASE 1 NEW |
| 40 | 44 | |
| 41 | 45 | // Progression tracking - PHASE 1 NEW |
| 42 | | -let fliesCaught = 0; |
| 43 | | -let fliesMunched = 0; |
| 44 | | -let totalFliesCaught = 0; // Lifetime counter |
| 45 | | -let nightsSurvived = 0; |
| 46 | | -let currentNight = 1; |
| 47 | | -let baseFlySpeed = 3; |
| 48 | | -let fliesEscaped = []; |
| 46 | +let fliesCaught = 0 |
| 47 | +let fliesMunched = 0 |
| 48 | +let totalFliesCaught = 0 // Lifetime counter |
| 49 | +let nightsSurvived = 0 |
| 50 | +let currentNight = 1 |
| 51 | +let baseFlySpeed = 3 |
| 52 | +let fliesEscaped = [] |
| 49 | 53 | |
| 50 | 54 | // PHASE 2: Special fly notifications |
| 51 | | -let notifications = []; |
| 55 | +let notifications = [] |
| 52 | 56 | |
| 53 | 57 | // PHASE 3: Upgrade System |
| 54 | | -let playerPoints = 0; |
| 55 | | -let shopOpen = false; |
| 58 | +let playerPoints = 0 |
| 59 | +let shopOpen = false |
| 56 | 60 | |
| 57 | 61 | // PHASE 4: Dawn Exhaustion System |
| 58 | | -let jumpStamina = 100; |
| 59 | | -let maxJumpStamina = 100; |
| 60 | | -let jumpCost = 20; |
| 61 | | -let staminaRegenRate = 0.2; |
| 62 | | -let isExhausted = false; |
| 63 | | -let fliesMunchedLastNight = 0; |
| 64 | | -let birds = []; |
| 62 | +let jumpStamina = 100 |
| 63 | +let maxJumpStamina = 100 |
| 64 | +let jumpCost = 20 |
| 65 | +let staminaRegenRate = 0.2 |
| 66 | +let isExhausted = false |
| 67 | +let fliesMunchedLastNight = 0 |
| 68 | +let birds = [] |
| 65 | 69 | |
| 66 | 70 | // PHASE 4B: Wind System |
| 67 | | -let windActive = false; |
| 68 | | -let windDirection = 0; |
| 69 | | -let windStrength = 0; |
| 70 | | -let windTimer = 0; |
| 71 | | -let windDuration = 0; |
| 72 | | -let windParticles = []; |
| 73 | | -let nextWindTime = 0; |
| 71 | +let windActive = false |
| 72 | +let windDirection = 0 |
| 73 | +let windStrength = 0 |
| 74 | +let windTimer = 0 |
| 75 | +let windDuration = 0 |
| 76 | +let windParticles = [] |
| 77 | +let nextWindTime = 0 |
| 74 | 78 | |
| 75 | 79 | // PHASE 4B: Thief bird timer |
| 76 | | -let thiefBirdTimer = 0; |
| 77 | | -let nextThiefTime = 0; |
| 80 | +let thiefBirdTimer = 0 |
| 81 | +let nextThiefTime = 0 |
| 78 | 82 | |
| 79 | 83 | // PHASE 5: Achievements & Stats System |
| 80 | 84 | let achievements = { |
| 81 | | - nightOwl: { name: "Night Owl", desc: "Survive 10 nights", icon: "🦉", unlocked: false, progress: 0, target: 10 }, |
| 82 | | - silkMaster: { name: "Silk Master", desc: "Have 15+ strands at once", icon: "🕸️", unlocked: false, progress: 0, target: 15 }, |
| 83 | | - feast: { name: "Feast", desc: "Munch 20 flies in one night", icon: "🍽️", unlocked: false, progress: 0, target: 20 }, |
| 84 | | - architect: { name: "Architect", desc: "Catch 5 flies without munching", icon: "🏗️", unlocked: false, progress: 0, target: 5 }, |
| 85 | | - untouchable: { name: "Untouchable", desc: "Survive a night without losing a strand", icon: "💎", unlocked: false }, |
| 86 | | - windRider: { name: "Wind Rider", desc: "Jump 10 times during wind", icon: "🌬️", unlocked: false, progress: 0, target: 10 }, |
| 87 | | - thiefDefender: { name: "Thief Defender", desc: "Scare off 10 thief birds", icon: "🛡️", unlocked: false, progress: 0, target: 10 }, |
| 88 | | - exhaustionMaster: { name: "Exhaustion Master", desc: "Survive dawn with < 20 stamina", icon: "😴", unlocked: false }, |
| 89 | | - queenSlayer: { name: "Queen Slayer", desc: "Catch 10 queen flies", icon: "👑", unlocked: false, progress: 0, target: 10 }, |
| 90 | | - perfectDawn: { name: "Perfect Dawn", desc: "No bird hits during dawn", icon: "☀️", unlocked: false }, |
| 91 | | - speedrunner: { name: "Speedrunner", desc: "Catch 30 flies before Night 5", icon: "⚡", unlocked: false }, |
| 92 | | - galaxyUnlock: { name: "Cosmic Spider", desc: "Survive 15 nights", icon: "🌌", unlocked: false, progress: 0, target: 15 }, |
| 93 | | - goldenHunter: { name: "Golden Hunter", desc: "Catch 100 golden flies", icon: "✨", unlocked: false, progress: 0, target: 100 }, |
| 94 | | - shadowPredator: { name: "Shadow Predator", desc: "Catch 50 flies in one night", icon: "🌑", unlocked: false, progress: 0, target: 50 }, |
| 95 | | - webMaster: { name: "Web Master", desc: "500 total flies caught", icon: "🏆", unlocked: false, progress: 0, target: 500 } |
| 96 | | -}; |
| 85 | + nightOwl: { |
| 86 | + name: 'Night Owl', |
| 87 | + desc: 'Survive 10 nights', |
| 88 | + icon: '🦉', |
| 89 | + unlocked: false, |
| 90 | + progress: 0, |
| 91 | + target: 10 |
| 92 | + }, |
| 93 | + silkMaster: { |
| 94 | + name: 'Silk Master', |
| 95 | + desc: 'Have 15+ strands at once', |
| 96 | + icon: '🕸️', |
| 97 | + unlocked: false, |
| 98 | + progress: 0, |
| 99 | + target: 15 |
| 100 | + }, |
| 101 | + feast: { |
| 102 | + name: 'Feast', |
| 103 | + desc: 'Munch 20 flies in one night', |
| 104 | + icon: '🍽️', |
| 105 | + unlocked: false, |
| 106 | + progress: 0, |
| 107 | + target: 20 |
| 108 | + }, |
| 109 | + architect: { |
| 110 | + name: 'Architect', |
| 111 | + desc: 'Catch 5 flies without munching', |
| 112 | + icon: '🏗️', |
| 113 | + unlocked: false, |
| 114 | + progress: 0, |
| 115 | + target: 5 |
| 116 | + }, |
| 117 | + untouchable: { |
| 118 | + name: 'Untouchable', |
| 119 | + desc: 'Survive a night without losing a strand', |
| 120 | + icon: '💎', |
| 121 | + unlocked: false |
| 122 | + }, |
| 123 | + windRider: { |
| 124 | + name: 'Wind Rider', |
| 125 | + desc: 'Jump 10 times during wind', |
| 126 | + icon: '🌬️', |
| 127 | + unlocked: false, |
| 128 | + progress: 0, |
| 129 | + target: 10 |
| 130 | + }, |
| 131 | + thiefDefender: { |
| 132 | + name: 'Thief Defender', |
| 133 | + desc: 'Scare off 10 thief birds', |
| 134 | + icon: '🛡️', |
| 135 | + unlocked: false, |
| 136 | + progress: 0, |
| 137 | + target: 10 |
| 138 | + }, |
| 139 | + exhaustionMaster: { |
| 140 | + name: 'Exhaustion Master', |
| 141 | + desc: 'Survive dawn with < 20 stamina', |
| 142 | + icon: '😴', |
| 143 | + unlocked: false |
| 144 | + }, |
| 145 | + queenSlayer: { |
| 146 | + name: 'Queen Slayer', |
| 147 | + desc: 'Catch 10 queen flies', |
| 148 | + icon: '👑', |
| 149 | + unlocked: false, |
| 150 | + progress: 0, |
| 151 | + target: 10 |
| 152 | + }, |
| 153 | + perfectDawn: { |
| 154 | + name: 'Perfect Dawn', |
| 155 | + desc: 'No bird hits during dawn', |
| 156 | + icon: '☀️', |
| 157 | + unlocked: false |
| 158 | + }, |
| 159 | + speedrunner: { |
| 160 | + name: 'Speedrunner', |
| 161 | + desc: 'Catch 30 flies before Night 5', |
| 162 | + icon: '⚡', |
| 163 | + unlocked: false |
| 164 | + }, |
| 165 | + galaxyUnlock: { |
| 166 | + name: 'Cosmic Spider', |
| 167 | + desc: 'Survive 15 nights', |
| 168 | + icon: '🌌', |
| 169 | + unlocked: false, |
| 170 | + progress: 0, |
| 171 | + target: 15 |
| 172 | + }, |
| 173 | + goldenHunter: { |
| 174 | + name: 'Golden Hunter', |
| 175 | + desc: 'Catch 100 golden flies', |
| 176 | + icon: '✨', |
| 177 | + unlocked: false, |
| 178 | + progress: 0, |
| 179 | + target: 100 |
| 180 | + }, |
| 181 | + shadowPredator: { |
| 182 | + name: 'Shadow Predator', |
| 183 | + desc: 'Catch 50 flies in one night', |
| 184 | + icon: '🌑', |
| 185 | + unlocked: false, |
| 186 | + progress: 0, |
| 187 | + target: 50 |
| 188 | + }, |
| 189 | + webMaster: { |
| 190 | + name: 'Web Master', |
| 191 | + desc: '500 total flies caught', |
| 192 | + icon: '🏆', |
| 193 | + unlocked: false, |
| 194 | + progress: 0, |
| 195 | + target: 500 |
| 196 | + } |
| 197 | +} |
| 97 | 198 | |
| 98 | 199 | // Statistics tracking |
| 99 | 200 | let stats = { |
| 100 | | - totalFliesCaught: 0, |
| 101 | | - regularCaught: 0, |
| 102 | | - goldenCaught: 0, |
| 103 | | - mothsCaught: 0, |
| 104 | | - queensCaught: 0, |
| 105 | | - longestNight: 0, |
| 106 | | - totalSilkSpun: 0, |
| 107 | | - totalJumps: 0, |
| 108 | | - windJumps: 0, |
| 109 | | - thievesScared: 0, |
| 110 | | - birdHitsTaken: 0, |
| 111 | | - strandsCreated: 0, |
| 112 | | - perfectDawns: 0, |
| 113 | | - fliesMunchedInCurrentNight: 0, |
| 114 | | - fliesCaughtWithoutMunch: 0, |
| 115 | | - strandsLostInNight: 0 |
| 116 | | -}; |
| 201 | + totalFliesCaught: 0, |
| 202 | + regularCaught: 0, |
| 203 | + goldenCaught: 0, |
| 204 | + mothsCaught: 0, |
| 205 | + queensCaught: 0, |
| 206 | + longestNight: 0, |
| 207 | + totalSilkSpun: 0, |
| 208 | + totalJumps: 0, |
| 209 | + windJumps: 0, |
| 210 | + thievesScared: 0, |
| 211 | + birdHitsTaken: 0, |
| 212 | + strandsCreated: 0, |
| 213 | + perfectDawns: 0, |
| 214 | + fliesMunchedInCurrentNight: 0, |
| 215 | + fliesCaughtWithoutMunch: 0, |
| 216 | + strandsLostInNight: 0 |
| 217 | +} |
| 117 | 218 | |
| 118 | 219 | // Cosmetics |
| 119 | 220 | let unlockedSkins = { |
| 120 | | - default: true, |
| 121 | | - galaxy: false, |
| 122 | | - golden: false, |
| 123 | | - shadow: false, |
| 124 | | - rainbow: false |
| 125 | | -}; |
| 126 | | - |
| 127 | | -let currentSkin = 'default'; |
| 128 | | -let achievementQueue = []; |
| 129 | | -let showingAchievement = null; |
| 130 | | -let achievementDisplayTimer = 0; |
| 221 | + default: true, |
| 222 | + galaxy: false, |
| 223 | + golden: false, |
| 224 | + shadow: false, |
| 225 | + rainbow: false |
| 226 | +} |
| 227 | + |
| 228 | +let currentSkin = 'default' |
| 229 | +let achievementQueue = [] |
| 230 | +let showingAchievement = null |
| 231 | +let achievementDisplayTimer = 0 |
| 131 | 232 | let upgrades = { |
| 132 | | - // Tier 1 Upgrades |
| 133 | | - strongLegs: { |
| 134 | | - level: 0, |
| 135 | | - maxLevel: 3, |
| 136 | | - cost: 15, |
| 137 | | - name: "Strong Legs", |
| 138 | | - description: "Jump 15% farther", |
| 139 | | - icon: "🦵", |
| 140 | | - tier: 1 |
| 141 | | - }, |
| 142 | | - silkGlands: { |
| 143 | | - level: 0, |
| 144 | | - maxLevel: 3, |
| 145 | | - cost: 20, |
| 146 | | - name: "Silk Glands", |
| 147 | | - description: "+20 max silk capacity", |
| 148 | | - icon: "🕸️", |
| 149 | | - tier: 1 |
| 150 | | - }, |
| 151 | | - efficientSpinning: { |
| 152 | | - level: 0, |
| 153 | | - maxLevel: 3, |
| 154 | | - cost: 15, |
| 155 | | - name: "Efficient Spinning", |
| 156 | | - description: "-20% silk consumption", |
| 157 | | - icon: "♻️", |
| 158 | | - tier: 1 |
| 159 | | - }, |
| 160 | | - quickMunch: { |
| 161 | | - level: 0, |
| 162 | | - maxLevel: 2, |
| 163 | | - cost: 10, |
| 164 | | - name: "Quick Munch", |
| 165 | | - description: "Munch cooldown -30%", |
| 166 | | - icon: "🦷", |
| 167 | | - tier: 1 |
| 168 | | - }, |
| 169 | | - |
| 170 | | - // Tier 2 Upgrades (requires at least 2 Tier 1 upgrades) |
| 171 | | - powerJump: { |
| 172 | | - level: 0, |
| 173 | | - maxLevel: 1, |
| 174 | | - cost: 50, |
| 175 | | - name: "Power Jump", |
| 176 | | - description: "Hold to charge jump (2x distance)", |
| 177 | | - icon: "⚡", |
| 178 | | - tier: 2, |
| 179 | | - requires: 2 // Number of tier 1 upgrades needed |
| 180 | | - }, |
| 181 | | - silkRecycle: { |
| 182 | | - level: 0, |
| 183 | | - maxLevel: 1, |
| 184 | | - cost: 75, |
| 185 | | - name: "Silk Recycle", |
| 186 | | - description: "Press R near old web to recover 50% silk", |
| 187 | | - icon: "🔄", |
| 188 | | - tier: 2, |
| 189 | | - requires: 2 |
| 190 | | - }, |
| 191 | | - spiderSense: { |
| 192 | | - level: 0, |
| 193 | | - maxLevel: 1, |
| 194 | | - cost: 100, |
| 195 | | - name: "Spider Sense", |
| 196 | | - description: "See faint prediction lines for fly paths", |
| 197 | | - icon: "👁️", |
| 198 | | - tier: 2, |
| 199 | | - requires: 3 |
| 200 | | - }, |
| 201 | | - metabolize: { |
| 202 | | - level: 0, |
| 203 | | - maxLevel: 1, |
| 204 | | - cost: 60, |
| 205 | | - name: "Metabolize", |
| 206 | | - description: "Munching heals nearby broken strands", |
| 207 | | - icon: "💚", |
| 208 | | - tier: 2, |
| 209 | | - requires: 2 |
| 210 | | - } |
| 211 | | -}; |
| 233 | + // Tier 1 Upgrades |
| 234 | + strongLegs: { |
| 235 | + level: 0, |
| 236 | + maxLevel: 3, |
| 237 | + cost: 15, |
| 238 | + name: 'Strong Legs', |
| 239 | + description: 'Jump 15% farther', |
| 240 | + icon: '🦵', |
| 241 | + tier: 1 |
| 242 | + }, |
| 243 | + silkGlands: { |
| 244 | + level: 0, |
| 245 | + maxLevel: 3, |
| 246 | + cost: 20, |
| 247 | + name: 'Silk Glands', |
| 248 | + description: '+20 max silk capacity', |
| 249 | + icon: '🕸️', |
| 250 | + tier: 1 |
| 251 | + }, |
| 252 | + efficientSpinning: { |
| 253 | + level: 0, |
| 254 | + maxLevel: 3, |
| 255 | + cost: 15, |
| 256 | + name: 'Efficient Spinning', |
| 257 | + description: '-20% silk consumption', |
| 258 | + icon: '♻️', |
| 259 | + tier: 1 |
| 260 | + }, |
| 261 | + quickMunch: { |
| 262 | + level: 0, |
| 263 | + maxLevel: 2, |
| 264 | + cost: 10, |
| 265 | + name: 'Quick Munch', |
| 266 | + description: 'Munch cooldown -30%', |
| 267 | + icon: '🦷', |
| 268 | + tier: 1 |
| 269 | + }, |
| 270 | + |
| 271 | + // Tier 2 Upgrades (requires at least 2 Tier 1 upgrades) |
| 272 | + powerJump: { |
| 273 | + level: 0, |
| 274 | + maxLevel: 1, |
| 275 | + cost: 50, |
| 276 | + name: 'Power Jump', |
| 277 | + description: 'Hold to charge jump (2x distance)', |
| 278 | + icon: '⚡', |
| 279 | + tier: 2, |
| 280 | + requires: 2 // Number of tier 1 upgrades needed |
| 281 | + }, |
| 282 | + silkRecycle: { |
| 283 | + level: 0, |
| 284 | + maxLevel: 1, |
| 285 | + cost: 75, |
| 286 | + name: 'Silk Recycle', |
| 287 | + description: 'Press R near old web to recover 50% silk', |
| 288 | + icon: '🔄', |
| 289 | + tier: 2, |
| 290 | + requires: 2 |
| 291 | + }, |
| 292 | + spiderSense: { |
| 293 | + level: 0, |
| 294 | + maxLevel: 1, |
| 295 | + cost: 100, |
| 296 | + name: 'Spider Sense', |
| 297 | + description: 'See faint prediction lines for fly paths', |
| 298 | + icon: '👁️', |
| 299 | + tier: 2, |
| 300 | + requires: 3 |
| 301 | + }, |
| 302 | + metabolize: { |
| 303 | + level: 0, |
| 304 | + maxLevel: 1, |
| 305 | + cost: 60, |
| 306 | + name: 'Metabolize', |
| 307 | + description: 'Munching heals nearby broken strands', |
| 308 | + icon: '💚', |
| 309 | + tier: 2, |
| 310 | + requires: 2 |
| 311 | + } |
| 312 | +} |
| 212 | 313 | |
| 213 | 314 | // Track if charging jump (Tier 2 upgrade) |
| 214 | | -let chargingJump = false; |
| 215 | | -let jumpChargeTime = 0; |
| 216 | | -let maxJumpCharge = 60; // 1 second at 60fps |
| 315 | +let chargingJump = false |
| 316 | +let jumpChargeTime = 0 |
| 317 | +let maxJumpCharge = 60 // 1 second at 60fps |
| 217 | 318 | |
| 218 | 319 | class Notification { |
| 219 | | - constructor(text, color) { |
| 220 | | - this.text = text; |
| 221 | | - this.color = color; |
| 222 | | - this.y = height * 0.3; |
| 223 | | - this.alpha = 255; |
| 224 | | - this.lifetime = 180; // 3 seconds |
| 225 | | - } |
| 226 | | - |
| 227 | | - update() { |
| 228 | | - this.lifetime--; |
| 229 | | - if (this.lifetime < 60) { |
| 230 | | - this.alpha = map(this.lifetime, 0, 60, 0, 255); |
| 231 | | - } |
| 232 | | - this.y -= 0.5; // Slowly rise |
| 233 | | - } |
| 234 | | - |
| 235 | | - display() { |
| 236 | | - push(); |
| 237 | | - textAlign(CENTER); |
| 238 | | - textSize(24); |
| 239 | | - strokeWeight(4); |
| 240 | | - stroke(0, 0, 0, this.alpha); |
| 241 | | - fill(red(this.color), green(this.color), blue(this.color), this.alpha); |
| 242 | | - text(this.text, width / 2, this.y); |
| 243 | | - pop(); |
| 244 | | - } |
| 245 | | - |
| 246 | | - isDead() { |
| 247 | | - return this.lifetime <= 0; |
| 320 | + constructor (text, color) { |
| 321 | + this.text = text |
| 322 | + this.color = color |
| 323 | + this.y = height * 0.3 |
| 324 | + this.alpha = 255 |
| 325 | + this.lifetime = 180 // 3 seconds |
| 326 | + } |
| 327 | + |
| 328 | + update () { |
| 329 | + this.lifetime-- |
| 330 | + if (this.lifetime < 60) { |
| 331 | + this.alpha = map(this.lifetime, 0, 60, 0, 255) |
| 248 | 332 | } |
| 333 | + this.y -= 0.5 // Slowly rise |
| 334 | + } |
| 335 | + |
| 336 | + display () { |
| 337 | + push() |
| 338 | + textAlign(CENTER) |
| 339 | + textSize(24) |
| 340 | + strokeWeight(4) |
| 341 | + stroke(0, 0, 0, this.alpha) |
| 342 | + fill(red(this.color), green(this.color), blue(this.color), this.alpha) |
| 343 | + text(this.text, width / 2, this.y) |
| 344 | + pop() |
| 345 | + } |
| 346 | + |
| 347 | + isDead () { |
| 348 | + return this.lifetime <= 0 |
| 349 | + } |
| 249 | 350 | } |
| 250 | 351 | |
| 251 | | -function setup() { |
| 252 | | - let canvas = createCanvas(window.innerWidth, window.innerHeight); |
| 253 | | - canvas.parent('game-container'); |
| 254 | | - |
| 255 | | - skyColor1 = color(135, 206, 235); |
| 256 | | - skyColor2 = color(255, 183, 77); |
| 257 | | - currentSkyColor1 = skyColor1; |
| 258 | | - currentSkyColor2 = skyColor2; |
| 259 | | - |
| 260 | | - // Create home branch for spider |
| 261 | | - let homeBranchSide = random() < 0.5 ? 'left' : 'right'; |
| 262 | | - let homeBranchLength = random(width * 0.33, width * 0.5); |
| 263 | | - let homeBranchY = random(height * 0.7, height * 0.85); |
| 264 | | - let homeBranchThickness = 25; |
| 265 | | - |
| 266 | | - // Calculate start and end positions ONCE |
| 267 | | - let branchStartX = homeBranchSide === 'left' ? -20 : width + 20; |
| 268 | | - let branchEndX = homeBranchSide === 'left' ? homeBranchLength : width - homeBranchLength; |
| 269 | | - |
| 270 | | - // Generate leaves with FIXED positions (simplified) |
| 271 | | - let leaves = []; |
| 272 | | - for (let i = 0; i < 3; i++) { |
| 273 | | - let t = 0.3 + (0.4 * i / 2); |
| 274 | | - let x = lerp(branchStartX, branchEndX, t); |
| 275 | | - leaves.push({ |
| 276 | | - t: t, // Store position as percentage for proper rotation |
| 277 | | - yOffset: -homeBranchThickness - 10, |
| 278 | | - rotation: random(-PI/8, PI/8), |
| 279 | | - width: 16, |
| 280 | | - height: 8 |
| 281 | | - }); |
| 282 | | - } |
| 283 | | - |
| 284 | | - // Generate bark textures with FIXED positions |
| 285 | | - let barkTextures = []; |
| 286 | | - for (let x = Math.min(branchStartX, branchEndX); x < Math.max(branchStartX, branchEndX); x += 16) { |
| 287 | | - barkTextures.push({ |
| 288 | | - x: x, |
| 289 | | - yOff: -5 + (x % 10), // Deterministic offset based on position |
| 290 | | - endYOff: -2 + (x % 5) |
| 291 | | - }); |
| 292 | | - } |
| 293 | | - |
| 294 | | - // Store home branch info for rendering (simplified) |
| 295 | | - window.homeBranch = { |
| 296 | | - side: homeBranchSide, |
| 297 | | - startX: branchStartX, |
| 298 | | - endX: branchEndX, |
| 299 | | - y: homeBranchY, |
| 300 | | - thickness: homeBranchThickness, |
| 301 | | - angle: homeBranchSide === 'left' ? 0.05 : -0.05, |
| 302 | | - leaves: leaves, |
| 303 | | - barkTextures: barkTextures |
| 304 | | - }; |
| 305 | | - |
| 306 | | - // Place spider at the tip of the branch |
| 307 | | - let spiderStartX = branchEndX; // Place at the end/tip |
| 308 | | - |
| 309 | | - // The branch is drawn with a taper - at the tip it's 35% thickness |
| 310 | | - // The branch rendering uses push/translate/rotate, so we need to account for that |
| 311 | | - let branchTopThickness = homeBranchThickness * 0.35; |
| 312 | | - |
| 313 | | - // The branch is drawn centered at branch.y after rotation |
| 314 | | - // Since the rotation is small, we can approximate |
| 315 | | - let branchSurfaceY = homeBranchY - branchTopThickness; |
| 316 | | - |
| 317 | | - // The branch rotates around (0, homeBranchY), so points further from origin rotate more |
| 318 | | - // For small angles: y_rotated ≈ y + x * sin(angle) ≈ y + x * angle |
| 319 | | - let rotationOffset = spiderStartX * window.homeBranch.angle; |
| 320 | | - branchSurfaceY += rotationOffset; |
| 321 | | - |
| 322 | | - // Place spider on top of the visual branch at the tip (8 is spider radius) |
| 323 | | - spider = new Spider(spiderStartX, branchSurfaceY - 8); |
| 324 | | - |
| 325 | | - // PHASE 5: Load saved game (AFTER spider is created) |
| 326 | | - loadGame(); |
| 327 | | - |
| 328 | | - // Add invisible obstacles along the branch for web anchor points |
| 329 | | - let numBranchAnchors = 3; |
| 330 | | - for (let i = 0; i < numBranchAnchors; i++) { |
| 331 | | - let t = (i + 1) / (numBranchAnchors + 1); |
| 332 | | - let x = homeBranchSide === 'left' ? |
| 333 | | - homeBranchLength * t : |
| 334 | | - width - homeBranchLength * t; |
| 335 | | - let y = homeBranchY + sin(t * PI) * 10; // Slight curve |
| 336 | | - obstacles.push(new Obstacle(x, y, 20, 'leaf')); // Use leaf as invisible anchor |
| 337 | | - } |
| 338 | | - |
| 339 | | - // Create more obstacles for denser coverage |
| 340 | | - let numObstacles = Math.floor((width * height) / 60000); // More obstacles |
| 341 | | - numObstacles = constrain(numObstacles, 15, 25); |
| 342 | | - |
| 343 | | - // Create ant balloons (4-6) |
| 344 | | - let numBalloons = Math.floor(random(4, 7)); |
| 345 | | - for (let i = 0; i < numBalloons; i++) { |
| 346 | | - let attempts = 0; |
| 347 | | - let placed = false; |
| 348 | | - |
| 349 | | - while (!placed && attempts < 30) { |
| 350 | | - let x = random(80, width - 80); |
| 351 | | - let y = random(60, height * 0.55); // Balloons float in upper half |
| 352 | | - let radius = random(35, 45); // Good size for hopping |
| 353 | | - |
| 354 | | - let valid = true; |
| 355 | | - // Check distance from other obstacles |
| 356 | | - for (let obstacle of obstacles) { |
| 357 | | - if (dist(x, y, obstacle.x, obstacle.y) < radius + obstacle.radius + 50) { |
| 358 | | - valid = false; |
| 359 | | - break; |
| 360 | | - } |
| 361 | | - } |
| 362 | | - |
| 363 | | - // Check distance from home branch |
| 364 | | - if (valid && window.homeBranch) { |
| 365 | | - let branchY = window.homeBranch.y; |
| 366 | | - if (Math.abs(y - branchY) < radius + 35) { |
| 367 | | - valid = false; |
| 368 | | - } |
| 369 | | - } |
| 370 | | - |
| 371 | | - if (valid) { |
| 372 | | - obstacles.push(new Obstacle(x, y, radius, 'balloon')); |
| 373 | | - placed = true; |
| 374 | | - } |
| 375 | | - attempts++; |
| 352 | +function setup () { |
| 353 | + let canvas = createCanvas(window.innerWidth, window.innerHeight) |
| 354 | + canvas.parent('game-container') |
| 355 | + |
| 356 | + skyColor1 = color(135, 206, 235) |
| 357 | + skyColor2 = color(255, 183, 77) |
| 358 | + currentSkyColor1 = skyColor1 |
| 359 | + currentSkyColor2 = skyColor2 |
| 360 | + |
| 361 | + // Create home branch for spider |
| 362 | + let homeBranchSide = random() < 0.5 ? 'left' : 'right' |
| 363 | + let homeBranchLength = random(width * 0.33, width * 0.5) |
| 364 | + let homeBranchY = random(height * 0.7, height * 0.85) |
| 365 | + let homeBranchThickness = 25 |
| 366 | + |
| 367 | + // Calculate start and end positions ONCE |
| 368 | + let branchStartX = homeBranchSide === 'left' ? -20 : width + 20 |
| 369 | + let branchEndX = |
| 370 | + homeBranchSide === 'left' ? homeBranchLength : width - homeBranchLength |
| 371 | + |
| 372 | + // Generate leaves with FIXED positions (simplified) |
| 373 | + let leaves = [] |
| 374 | + for (let i = 0; i < 3; i++) { |
| 375 | + let t = 0.3 + (0.4 * i) / 2 |
| 376 | + let x = lerp(branchStartX, branchEndX, t) |
| 377 | + leaves.push({ |
| 378 | + t: t, // Store position as percentage for proper rotation |
| 379 | + yOffset: -homeBranchThickness - 10, |
| 380 | + rotation: random(-PI / 8, PI / 8), |
| 381 | + width: 16, |
| 382 | + height: 8 |
| 383 | + }) |
| 384 | + } |
| 385 | + |
| 386 | + // Generate bark textures with FIXED positions |
| 387 | + let barkTextures = [] |
| 388 | + for ( |
| 389 | + let x = Math.min(branchStartX, branchEndX); |
| 390 | + x < Math.max(branchStartX, branchEndX); |
| 391 | + x += 16 |
| 392 | + ) { |
| 393 | + barkTextures.push({ |
| 394 | + x: x, |
| 395 | + yOff: -5 + (x % 10), // Deterministic offset based on position |
| 396 | + endYOff: -2 + (x % 5) |
| 397 | + }) |
| 398 | + } |
| 399 | + |
| 400 | + // Store home branch info for rendering (simplified) |
| 401 | + window.homeBranch = { |
| 402 | + side: homeBranchSide, |
| 403 | + startX: branchStartX, |
| 404 | + endX: branchEndX, |
| 405 | + y: homeBranchY, |
| 406 | + thickness: homeBranchThickness, |
| 407 | + angle: homeBranchSide === 'left' ? 0.05 : -0.05, |
| 408 | + leaves: leaves, |
| 409 | + barkTextures: barkTextures |
| 410 | + } |
| 411 | + |
| 412 | + // Place spider at the tip of the branch |
| 413 | + let spiderStartX = branchEndX // Place at the end/tip |
| 414 | + |
| 415 | + // The branch is drawn with a taper - at the tip it's 35% thickness |
| 416 | + // The branch rendering uses push/translate/rotate, so we need to account for that |
| 417 | + let branchTopThickness = homeBranchThickness * 0.35 |
| 418 | + |
| 419 | + // The branch is drawn centered at branch.y after rotation |
| 420 | + // Since the rotation is small, we can approximate |
| 421 | + let branchSurfaceY = homeBranchY - branchTopThickness |
| 422 | + |
| 423 | + // The branch rotates around (0, homeBranchY), so points further from origin rotate more |
| 424 | + // For small angles: y_rotated ≈ y + x * sin(angle) ≈ y + x * angle |
| 425 | + let rotationOffset = spiderStartX * window.homeBranch.angle |
| 426 | + branchSurfaceY += rotationOffset |
| 427 | + |
| 428 | + // Place spider on top of the visual branch at the tip (8 is spider radius) |
| 429 | + spider = new Spider(spiderStartX, branchSurfaceY - 8) |
| 430 | + |
| 431 | + loadGame() |
| 432 | + |
| 433 | + // PHASE 3: Apply any existing upgrades at start |
| 434 | + // applyUpgradeEffects(); |
| 435 | + |
| 436 | + // Add invisible obstacles along the branch for web anchor points |
| 437 | + let numBranchAnchors = 3 |
| 438 | + for (let i = 0; i < numBranchAnchors; i++) { |
| 439 | + let t = (i + 1) / (numBranchAnchors + 1) |
| 440 | + let x = |
| 441 | + homeBranchSide === 'left' |
| 442 | + ? homeBranchLength * t |
| 443 | + : width - homeBranchLength * t |
| 444 | + let y = homeBranchY + sin(t * PI) * 10 // Slight curve |
| 445 | + obstacles.push(new Obstacle(x, y, 20, 'leaf')) // Use leaf as invisible anchor |
| 446 | + } |
| 447 | + |
| 448 | + // Create more obstacles for denser coverage |
| 449 | + let numObstacles = Math.floor((width * height) / 60000) // More obstacles |
| 450 | + numObstacles = constrain(numObstacles, 15, 25) |
| 451 | + |
| 452 | + // Create ant balloons (4-6) |
| 453 | + let numBalloons = Math.floor(random(4, 7)) |
| 454 | + for (let i = 0; i < numBalloons; i++) { |
| 455 | + let attempts = 0 |
| 456 | + let placed = false |
| 457 | + |
| 458 | + while (!placed && attempts < 30) { |
| 459 | + let x = random(80, width - 80) |
| 460 | + let y = random(60, height * 0.55) // Balloons float in upper half |
| 461 | + let radius = random(35, 45) // Good size for hopping |
| 462 | + |
| 463 | + let valid = true |
| 464 | + // Check distance from other obstacles |
| 465 | + for (let obstacle of obstacles) { |
| 466 | + if ( |
| 467 | + dist(x, y, obstacle.x, obstacle.y) < |
| 468 | + radius + obstacle.radius + 50 |
| 469 | + ) { |
| 470 | + valid = false |
| 471 | + break |
| 376 | 472 | } |
| 377 | | - } |
| 378 | | - |
| 379 | | - // Create beetles (3-5) |
| 380 | | - let numBeetles = Math.floor(random(3, 6)); |
| 381 | | - for (let i = 0; i < numBeetles; i++) { |
| 382 | | - let attempts = 0; |
| 383 | | - let placed = false; |
| 384 | | - |
| 385 | | - while (!placed && attempts < 30) { |
| 386 | | - let x = random(70, width - 70); |
| 387 | | - let y = random(height * 0.2, height * 0.8); // Spread throughout middle/lower |
| 388 | | - let radius = random(30, 40); |
| 389 | | - |
| 390 | | - let valid = true; |
| 391 | | - for (let obstacle of obstacles) { |
| 392 | | - if (dist(x, y, obstacle.x, obstacle.y) < radius + obstacle.radius + 45) { |
| 393 | | - valid = false; |
| 394 | | - break; |
| 395 | | - } |
| 396 | | - } |
| 397 | | - |
| 398 | | - // Check distance from home branch |
| 399 | | - if (valid && window.homeBranch) { |
| 400 | | - let branchY = window.homeBranch.y; |
| 401 | | - if (Math.abs(y - branchY) < radius + 30) { |
| 402 | | - valid = false; |
| 403 | | - } |
| 404 | | - } |
| 405 | | - |
| 406 | | - if (valid) { |
| 407 | | - obstacles.push(new Obstacle(x, y, radius, 'beetle')); |
| 408 | | - placed = true; |
| 409 | | - } |
| 410 | | - attempts++; |
| 473 | + } |
| 474 | + |
| 475 | + // Check distance from home branch |
| 476 | + if (valid && window.homeBranch) { |
| 477 | + let branchY = window.homeBranch.y |
| 478 | + if (Math.abs(y - branchY) < radius + 35) { |
| 479 | + valid = false |
| 411 | 480 | } |
| 481 | + } |
| 482 | + |
| 483 | + if (valid) { |
| 484 | + obstacles.push(new Obstacle(x, y, radius, 'balloon')) |
| 485 | + placed = true |
| 486 | + } |
| 487 | + attempts++ |
| 412 | 488 | } |
| 413 | | - |
| 414 | | - // Create LOTS of leaves (8-12) for excellent hopping coverage |
| 415 | | - let numLeaves = Math.floor(random(8, 13)); |
| 416 | | - for (let i = 0; i < numLeaves; i++) { |
| 417 | | - let attempts = 0; |
| 418 | | - let placed = false; |
| 419 | | - |
| 420 | | - while (!placed && attempts < 30) { |
| 421 | | - // Distribute leaves more evenly across the screen |
| 422 | | - let gridX = (i % 4) * (width / 4) + random(50, width/4 - 50); |
| 423 | | - let gridY = Math.floor(i / 4) * (height / 3) + random(50, height/3 - 50); |
| 424 | | - let x = constrain(gridX, 50, width - 50); |
| 425 | | - let y = constrain(gridY, 60, height - 100); |
| 426 | | - let radius = random(20, 30); |
| 427 | | - |
| 428 | | - let valid = true; |
| 429 | | - for (let obstacle of obstacles) { |
| 430 | | - if (dist(x, y, obstacle.x, obstacle.y) < radius + obstacle.radius + 35) { |
| 431 | | - valid = false; |
| 432 | | - break; |
| 433 | | - } |
| 434 | | - } |
| 435 | | - |
| 436 | | - if (valid) { |
| 437 | | - obstacles.push(new Obstacle(x, y, radius, 'leaf')); |
| 438 | | - placed = true; |
| 439 | | - } |
| 440 | | - attempts++; |
| 489 | + } |
| 490 | + |
| 491 | + // Create beetles (3-5) |
| 492 | + let numBeetles = Math.floor(random(3, 6)) |
| 493 | + for (let i = 0; i < numBeetles; i++) { |
| 494 | + let attempts = 0 |
| 495 | + let placed = false |
| 496 | + |
| 497 | + while (!placed && attempts < 30) { |
| 498 | + let x = random(70, width - 70) |
| 499 | + let y = random(height * 0.2, height * 0.8) // Spread throughout middle/lower |
| 500 | + let radius = random(30, 40) |
| 501 | + |
| 502 | + let valid = true |
| 503 | + for (let obstacle of obstacles) { |
| 504 | + if ( |
| 505 | + dist(x, y, obstacle.x, obstacle.y) < |
| 506 | + radius + obstacle.radius + 45 |
| 507 | + ) { |
| 508 | + valid = false |
| 509 | + break |
| 441 | 510 | } |
| 511 | + } |
| 512 | + |
| 513 | + // Check distance from home branch |
| 514 | + if (valid && window.homeBranch) { |
| 515 | + let branchY = window.homeBranch.y |
| 516 | + if (Math.abs(y - branchY) < radius + 30) { |
| 517 | + valid = false |
| 518 | + } |
| 519 | + } |
| 520 | + |
| 521 | + if (valid) { |
| 522 | + obstacles.push(new Obstacle(x, y, radius, 'beetle')) |
| 523 | + placed = true |
| 524 | + } |
| 525 | + attempts++ |
| 442 | 526 | } |
| 443 | | - |
| 444 | | - // Add even more guaranteed coverage points (smaller leaves) |
| 445 | | - // Corners |
| 446 | | - obstacles.push(new Obstacle(50, 80, 18, 'leaf')); |
| 447 | | - obstacles.push(new Obstacle(width - 50, 80, 18, 'leaf')); |
| 448 | | - obstacles.push(new Obstacle(50, height - 100, 18, 'leaf')); |
| 449 | | - obstacles.push(new Obstacle(width - 50, height - 100, 18, 'leaf')); |
| 450 | | - |
| 451 | | - // Edge midpoints |
| 452 | | - obstacles.push(new Obstacle(35, height/3, 18, 'leaf')); |
| 453 | | - obstacles.push(new Obstacle(35, 2*height/3, 18, 'leaf')); |
| 454 | | - obstacles.push(new Obstacle(width - 35, height/3, 18, 'leaf')); |
| 455 | | - obstacles.push(new Obstacle(width - 35, 2*height/3, 18, 'leaf')); |
| 456 | | - obstacles.push(new Obstacle(width/3, 45, 18, 'leaf')); |
| 457 | | - obstacles.push(new Obstacle(2*width/3, 45, 18, 'leaf')); |
| 458 | | - obstacles.push(new Obstacle(width/3, height - 90, 18, 'leaf')); |
| 459 | | - obstacles.push(new Obstacle(2*width/3, height - 90, 18, 'leaf')); |
| 460 | | - |
| 461 | | - // Fill any remaining gaps for smooth hopping |
| 462 | | - if (width > 600) { |
| 463 | | - // Create a grid of small leaves to ensure no dead zones |
| 464 | | - for (let x = width/5; x < width; x += width/5) { |
| 465 | | - for (let y = height/4; y < height - 100; y += height/4) { |
| 466 | | - // Check if there's already an obstacle nearby |
| 467 | | - let needsLeaf = true; |
| 468 | | - for (let obstacle of obstacles) { |
| 469 | | - if (dist(x, y, obstacle.x, obstacle.y) < 80) { |
| 470 | | - needsLeaf = false; |
| 471 | | - break; |
| 472 | | - } |
| 473 | | - } |
| 474 | | - if (needsLeaf) { |
| 475 | | - obstacles.push(new Obstacle(x + random(-20, 20), y + random(-20, 20), 15, 'leaf')); |
| 476 | | - } |
| 477 | | - } |
| 527 | + } |
| 528 | + |
| 529 | + // Create LOTS of leaves (8-12) for excellent hopping coverage |
| 530 | + let numLeaves = Math.floor(random(8, 13)) |
| 531 | + for (let i = 0; i < numLeaves; i++) { |
| 532 | + let attempts = 0 |
| 533 | + let placed = false |
| 534 | + |
| 535 | + while (!placed && attempts < 30) { |
| 536 | + // Distribute leaves more evenly across the screen |
| 537 | + let gridX = (i % 4) * (width / 4) + random(50, width / 4 - 50) |
| 538 | + let gridY = Math.floor(i / 4) * (height / 3) + random(50, height / 3 - 50) |
| 539 | + let x = constrain(gridX, 50, width - 50) |
| 540 | + let y = constrain(gridY, 60, height - 100) |
| 541 | + let radius = random(20, 30) |
| 542 | + |
| 543 | + let valid = true |
| 544 | + for (let obstacle of obstacles) { |
| 545 | + if ( |
| 546 | + dist(x, y, obstacle.x, obstacle.y) < |
| 547 | + radius + obstacle.radius + 35 |
| 548 | + ) { |
| 549 | + valid = false |
| 550 | + break |
| 478 | 551 | } |
| 552 | + } |
| 553 | + |
| 554 | + if (valid) { |
| 555 | + obstacles.push(new Obstacle(x, y, radius, 'leaf')) |
| 556 | + placed = true |
| 557 | + } |
| 558 | + attempts++ |
| 479 | 559 | } |
| 480 | | - |
| 481 | | - // Spawn initial food boxes |
| 482 | | - let numBoxes = Math.max(3, Math.floor(width / 400)); |
| 483 | | - for (let i = 0; i < numBoxes; i++) { |
| 484 | | - spawnFoodBox(); |
| 560 | + } |
| 561 | + |
| 562 | + // Add even more guaranteed coverage points (smaller leaves) |
| 563 | + // Corners |
| 564 | + obstacles.push(new Obstacle(50, 80, 18, 'leaf')) |
| 565 | + obstacles.push(new Obstacle(width - 50, 80, 18, 'leaf')) |
| 566 | + obstacles.push(new Obstacle(50, height - 100, 18, 'leaf')) |
| 567 | + obstacles.push(new Obstacle(width - 50, height - 100, 18, 'leaf')) |
| 568 | + |
| 569 | + // Edge midpoints |
| 570 | + obstacles.push(new Obstacle(35, height / 3, 18, 'leaf')) |
| 571 | + obstacles.push(new Obstacle(35, (2 * height) / 3, 18, 'leaf')) |
| 572 | + obstacles.push(new Obstacle(width - 35, height / 3, 18, 'leaf')) |
| 573 | + obstacles.push(new Obstacle(width - 35, (2 * height) / 3, 18, 'leaf')) |
| 574 | + obstacles.push(new Obstacle(width / 3, 45, 18, 'leaf')) |
| 575 | + obstacles.push(new Obstacle((2 * width) / 3, 45, 18, 'leaf')) |
| 576 | + obstacles.push(new Obstacle(width / 3, height - 90, 18, 'leaf')) |
| 577 | + obstacles.push(new Obstacle((2 * width) / 3, height - 90, 18, 'leaf')) |
| 578 | + |
| 579 | + // Fill any remaining gaps for smooth hopping |
| 580 | + if (width > 600) { |
| 581 | + // Create a grid of small leaves to ensure no dead zones |
| 582 | + for (let x = width / 5; x < width; x += width / 5) { |
| 583 | + for (let y = height / 4; y < height - 100; y += height / 4) { |
| 584 | + // Check if there's already an obstacle nearby |
| 585 | + let needsLeaf = true |
| 586 | + for (let obstacle of obstacles) { |
| 587 | + if (dist(x, y, obstacle.x, obstacle.y) < 80) { |
| 588 | + needsLeaf = false |
| 589 | + break |
| 590 | + } |
| 591 | + } |
| 592 | + if (needsLeaf) { |
| 593 | + obstacles.push( |
| 594 | + new Obstacle(x + random(-20, 20), y + random(-20, 20), 15, 'leaf') |
| 595 | + ) |
| 596 | + } |
| 597 | + } |
| 485 | 598 | } |
| 599 | + } |
| 600 | + |
| 601 | + // Spawn initial food boxes |
| 602 | + let numBoxes = Math.max(3, Math.floor(width / 400)) |
| 603 | + for (let i = 0; i < numBoxes; i++) { |
| 604 | + spawnFoodBox() |
| 605 | + } |
| 486 | 606 | } |
| 487 | 607 | |
| 488 | | -function draw() { |
| 489 | | - // Update phase timer |
| 490 | | - phaseTimer++; |
| 491 | | - |
| 492 | | - // Phase transitions with endless cycle - PHASE 1 UPDATE |
| 493 | | - if (gamePhase === 'DUSK' && phaseTimer >= DUSK_DURATION) { |
| 494 | | - gamePhase = 'DUSK_TO_NIGHT'; |
| 495 | | - phaseTimer = 0; |
| 496 | | - } else if (gamePhase === 'DUSK_TO_NIGHT' && phaseTimer >= TRANSITION_DURATION) { |
| 497 | | - gamePhase = 'NIGHT'; |
| 498 | | - phaseTimer = 0; |
| 499 | | - // Spawn flies based on difficulty |
| 500 | | - spawnNightFlies(); |
| 501 | | - } else if (gamePhase === 'NIGHT' && phaseTimer >= NIGHT_DURATION) { |
| 502 | | - gamePhase = 'NIGHT_TO_DAWN'; |
| 503 | | - phaseTimer = 0; |
| 504 | | - nightsSurvived++; |
| 505 | | - currentNight++; |
| 506 | | - // PHASE 5: Check night achievements |
| 507 | | - checkNightAchievements(); |
| 508 | | - // PHASE 4: Track flies munched for dawn stamina |
| 509 | | - fliesMunchedLastNight = fliesMunched; |
| 510 | | - fliesMunched = 0; // Reset for next night |
| 511 | | - // PHASE 4B: Clear any thief birds |
| 512 | | - birds = birds.filter(b => !b.isThief); |
| 513 | | - windActive = false; // Stop any active wind |
| 514 | | - } else if (gamePhase === 'NIGHT_TO_DAWN' && phaseTimer >= TRANSITION_DURATION) { |
| 515 | | - gamePhase = 'DAWN'; |
| 516 | | - phaseTimer = 0; |
| 517 | | - // PHASE 4: Calculate dawn stamina and spawn birds |
| 518 | | - maxJumpStamina = 30 + (fliesMunchedLastNight * 10); |
| 519 | | - maxJumpStamina = min(maxJumpStamina, 150); // Cap at 150 |
| 520 | | - jumpStamina = maxJumpStamina; |
| 521 | | - // Spawn birds |
| 522 | | - spawnDawnBirds(); |
| 523 | | - // Flies escape at dawn |
| 524 | | - escapeFlies(); |
| 525 | | - } else if (gamePhase === 'DAWN' && phaseTimer >= DAWN_DURATION) { |
| 526 | | - gamePhase = 'DAWN_TO_DAY'; |
| 527 | | - phaseTimer = 0; |
| 528 | | - // PHASE 5: Check dawn achievements |
| 529 | | - checkDawnAchievements(); |
| 530 | | - // PHASE 4: Clear birds when dawn ends |
| 531 | | - birds = []; |
| 532 | | - // PHASE 3: Open shop at dawn |
| 533 | | - if (currentNight > 1) { |
| 534 | | - openUpgradeShop(); |
| 535 | | - } |
| 536 | | - } else if (gamePhase === 'DAWN_TO_DAY' && phaseTimer >= TRANSITION_DURATION) { |
| 537 | | - gamePhase = 'DAY'; |
| 538 | | - phaseTimer = 0; |
| 539 | | - // Degrade webs by 10% |
| 540 | | - degradeWebs(); |
| 541 | | - // PHASE 5: Open stats panel during day |
| 542 | | - openStatsPanel(); |
| 543 | | - } else if (gamePhase === 'DAY' && phaseTimer >= DAY_DURATION) { |
| 544 | | - gamePhase = 'DAY_TO_DUSK'; |
| 545 | | - phaseTimer = 0; |
| 546 | | - } else if (gamePhase === 'DAY_TO_DUSK' && phaseTimer >= TRANSITION_DURATION) { |
| 547 | | - gamePhase = 'DUSK'; |
| 548 | | - phaseTimer = 0; |
| 549 | | - // Return some flies for next night |
| 550 | | - prepareDusk(); |
| 551 | | - } |
| 552 | | - |
| 553 | | - // Update sky colors |
| 554 | | - updateSkyColors(); |
| 555 | | - |
| 556 | | - // Draw sky gradient |
| 557 | | - drawSkyGradient(); |
| 558 | | - |
| 559 | | - // Draw moon and stars |
| 560 | | - if (moonOpacity > 0) { |
| 561 | | - drawMoon(); |
| 562 | | - } |
| 563 | | - |
| 564 | | - // Draw sun during day phases - PHASE 1 NEW |
| 565 | | - if (sunOpacity > 0) { |
| 566 | | - drawSun(); |
| 567 | | - } |
| 568 | | - |
| 569 | | - // PHASE 4B: Update wind system |
| 570 | | - updateWind(); |
| 571 | | - |
| 572 | | - // PHASE 4B: Apply wind to airborne entities |
| 573 | | - if (windActive) { |
| 574 | | - // Push spider if airborne |
| 575 | | - if (spider.isAirborne) { |
| 576 | | - spider.vel.x += cos(windDirection) * windStrength * 0.1; |
| 608 | +function draw () { |
| 609 | + // apply screen shake if active |
| 610 | + if (screenShake > 0) { |
| 611 | + translate( |
| 612 | + random(-screenShake, screenShake), |
| 613 | + random(-screenShake, screenShake) |
| 614 | + ) |
| 615 | + screenShake *= 0.9 // Decay shake |
| 616 | + } |
| 617 | + |
| 618 | + // Check for game over state |
| 619 | + if (gameOver) { |
| 620 | + // Draw death animation |
| 621 | + push() |
| 622 | + fill(255, 0, 0, 100 - gameOverTimer) |
| 623 | + rect(0, 0, width, height) |
| 624 | + pop() |
| 625 | + |
| 626 | + gameOverTimer++ |
| 627 | + return // Skip normal game updates |
| 628 | + } |
| 629 | + |
| 630 | + // Update phase timer |
| 631 | + phaseTimer++ |
| 632 | + |
| 633 | + // Phase transitions with endless cycle - PHASE 1 UPDATE |
| 634 | + if (gamePhase === 'DUSK' && phaseTimer >= DUSK_DURATION) { |
| 635 | + gamePhase = 'DUSK_TO_NIGHT' |
| 636 | + phaseTimer = 0 |
| 637 | + } else if ( |
| 638 | + gamePhase === 'DUSK_TO_NIGHT' && |
| 639 | + phaseTimer >= TRANSITION_DURATION |
| 640 | + ) { |
| 641 | + gamePhase = 'NIGHT' |
| 642 | + phaseTimer = 0 |
| 643 | + // Spawn flies based on difficulty |
| 644 | + spawnNightFlies() |
| 645 | + } else if (gamePhase === 'NIGHT' && phaseTimer >= NIGHT_DURATION) { |
| 646 | + gamePhase = 'NIGHT_TO_DAWN' |
| 647 | + phaseTimer = 0 |
| 648 | + nightsSurvived++ |
| 649 | + currentNight++ |
| 650 | + // PHASE 5: Check night achievements |
| 651 | + checkNightAchievements() |
| 652 | + // PHASE 4: Track flies munched for dawn stamina |
| 653 | + fliesMunchedLastNight = fliesMunched |
| 654 | + fliesMunched = 0 // Reset for next night |
| 655 | + // PHASE 4B: Clear any thief birds |
| 656 | + birds = birds.filter(b => !b.isThief) |
| 657 | + windActive = false // Stop any active wind |
| 658 | + } else if ( |
| 659 | + gamePhase === 'NIGHT_TO_DAWN' && |
| 660 | + phaseTimer >= TRANSITION_DURATION |
| 661 | + ) { |
| 662 | + gamePhase = 'DAWN' |
| 663 | + phaseTimer = 0 |
| 664 | + |
| 665 | + // ENHANCED: Calculate dawn stamina with CLEAR BONUS DISPLAY |
| 666 | + let baseStamina = 30 |
| 667 | + let flyBonus = fliesMunchedLastNight * 10 |
| 668 | + staminaBonus = flyBonus // Store for display |
| 669 | + |
| 670 | + maxJumpStamina = baseStamina + flyBonus |
| 671 | + maxJumpStamina = min(maxJumpStamina, 200) // Cap at 200 instead of 150 |
| 672 | + jumpStamina = maxJumpStamina |
| 673 | + |
| 674 | + // Clear notification showing stamina calculation |
| 675 | + notifications.push( |
| 676 | + new Notification( |
| 677 | + `Dawn Stamina: ${baseStamina} base + ${flyBonus} (${fliesMunchedLastNight} flies × 10) = ${maxJumpStamina}`, |
| 678 | + color(255, 200, 100) |
| 679 | + ) |
| 680 | + ) |
| 681 | + |
| 682 | + // Warning notifications based on stamina level |
| 683 | + if (maxJumpStamina <= 50) { |
| 684 | + notifications.push( |
| 685 | + new Notification( |
| 686 | + '⚠️ DANGER: Very low stamina! Eat more flies next night!', |
| 687 | + color(255, 50, 50) |
| 688 | + ) |
| 689 | + ) |
| 690 | + } else if (maxJumpStamina <= 80) { |
| 691 | + notifications.push( |
| 692 | + new Notification( |
| 693 | + 'Warning: Low stamina for dawn survival', |
| 694 | + color(255, 150, 50) |
| 695 | + ) |
| 696 | + ) |
| 697 | + } else if (maxJumpStamina >= 150) { |
| 698 | + notifications.push( |
| 699 | + new Notification( |
| 700 | + 'Excellent stamina! Well fed spider!', |
| 701 | + color(100, 255, 100) |
| 702 | + ) |
| 703 | + ) |
| 704 | + } |
| 705 | + |
| 706 | + // Spawn birds |
| 707 | + spawnDawnBirds() |
| 708 | + // Flies escape at dawn |
| 709 | + escapeFlies() |
| 710 | + } else if (gamePhase === 'DAWN' && phaseTimer >= DAWN_DURATION) { |
| 711 | + gamePhase = 'DAWN_TO_DAY' |
| 712 | + phaseTimer = 0 |
| 713 | + // PHASE 5: Check dawn achievements |
| 714 | + checkDawnAchievements() |
| 715 | + // PHASE 4: Clear birds when dawn ends |
| 716 | + birds = [] |
| 717 | + // PHASE 3: Open shop at dawn |
| 718 | + if (currentNight > 1) { |
| 719 | + openUpgradeShop() |
| 720 | + } |
| 721 | + } else if (gamePhase === 'DAWN_TO_DAY' && phaseTimer >= TRANSITION_DURATION) { |
| 722 | + gamePhase = 'DAY' |
| 723 | + phaseTimer = 0 |
| 724 | + // Degrade webs by 10% |
| 725 | + degradeWebs() |
| 726 | + // PHASE 5: Open stats panel during day |
| 727 | + openStatsPanel() |
| 728 | + } else if (gamePhase === 'DAY' && phaseTimer >= DAY_DURATION) { |
| 729 | + gamePhase = 'DAY_TO_DUSK' |
| 730 | + phaseTimer = 0 |
| 731 | + } else if (gamePhase === 'DAY_TO_DUSK' && phaseTimer >= TRANSITION_DURATION) { |
| 732 | + gamePhase = 'DUSK' |
| 733 | + phaseTimer = 0 |
| 734 | + // Return some flies for next night |
| 735 | + prepareDusk() |
| 736 | + } |
| 737 | + |
| 738 | + // Update sky colors |
| 739 | + updateSkyColors() |
| 740 | + |
| 741 | + // Draw sky gradient |
| 742 | + drawSkyGradient() |
| 743 | + |
| 744 | + // Draw moon and stars |
| 745 | + if (moonOpacity > 0) { |
| 746 | + drawMoon() |
| 747 | + } |
| 748 | + |
| 749 | + // Draw sun during day phases - PHASE 1 NEW |
| 750 | + if (sunOpacity > 0) { |
| 751 | + drawSun() |
| 752 | + } |
| 753 | + |
| 754 | + // PHASE 4B: Update wind system |
| 755 | + updateWind() |
| 756 | + |
| 757 | + // PHASE 4B: Apply wind to airborne entities |
| 758 | + if (windActive) { |
| 759 | + // Push spider if airborne |
| 760 | + if (spider.isAirborne) { |
| 761 | + spider.vel.x += cos(windDirection) * windStrength * 0.1 |
| 762 | + } |
| 763 | + |
| 764 | + // Push flies |
| 765 | + for (let fly of flies) { |
| 766 | + if (!fly.stuck && !fly.caught) { |
| 767 | + fly.vel.x += cos(windDirection) * windStrength * 0.05 |
| 768 | + } |
| 769 | + } |
| 770 | + |
| 771 | + // Make webs sway |
| 772 | + for (let strand of webStrands) { |
| 773 | + if (!strand.broken) { |
| 774 | + strand.vibrate(windStrength * 0.5) |
| 775 | + // Check if strand is overstretched and should break |
| 776 | + if (strand.tension > 1.2 && windStrength > 3) { |
| 777 | + if (random() < 0.01) { |
| 778 | + // Small chance per frame |
| 779 | + strand.broken = true |
| 780 | + notifications.push( |
| 781 | + new Notification('Wind snapped a web!', color(255, 150, 100)) |
| 782 | + ) |
| 783 | + } |
| 577 | 784 | } |
| 578 | | - |
| 579 | | - // Push flies |
| 580 | | - for (let fly of flies) { |
| 581 | | - if (!fly.stuck && !fly.caught) { |
| 582 | | - fly.vel.x += cos(windDirection) * windStrength * 0.05; |
| 583 | | - } |
| 785 | + } |
| 786 | + } |
| 787 | + |
| 788 | + // Update wind particles |
| 789 | + for (let i = windParticles.length - 1; i >= 0; i--) { |
| 790 | + let p = windParticles[i] |
| 791 | + p.x += cos(windDirection) * windStrength * 3 |
| 792 | + p.life-- |
| 793 | + if (p.life <= 0 || p.x < -50 || p.x > width + 50) { |
| 794 | + windParticles.splice(i, 1) |
| 795 | + } |
| 796 | + } |
| 797 | + |
| 798 | + // Spawn new wind particles |
| 799 | + if (frameCount % 5 === 0) { |
| 800 | + windParticles.push({ |
| 801 | + x: windDirection > 0 ? -20 : width + 20, |
| 802 | + y: random(height), |
| 803 | + life: 120, |
| 804 | + size: random(2, 4) |
| 805 | + }) |
| 806 | + } |
| 807 | + } |
| 808 | + |
| 809 | + // Update and display game objects |
| 810 | + for (let obstacle of obstacles) { |
| 811 | + obstacle.update() // Update movement and animations |
| 812 | + obstacle.display() |
| 813 | + } |
| 814 | + |
| 815 | + for (let box of foodBoxes) { |
| 816 | + box.display() |
| 817 | + } |
| 818 | + |
| 819 | + // PHASE 4B: Display wind effects |
| 820 | + if (windActive) { |
| 821 | + push() |
| 822 | + noStroke() |
| 823 | + for (let p of windParticles) { |
| 824 | + fill(255, 255, 255, p.life * 0.5) |
| 825 | + ellipse(p.x, p.y, p.size) |
| 826 | + } |
| 827 | + |
| 828 | + // Wind indicator |
| 829 | + push() |
| 830 | + translate(width / 2, 50) |
| 831 | + stroke(255, 255, 255, 100) |
| 832 | + strokeWeight(3) |
| 833 | + let arrowLength = windStrength * 10 |
| 834 | + line(0, 0, cos(windDirection) * arrowLength, 0) |
| 835 | + // Arrowhead |
| 836 | + push() |
| 837 | + translate(cos(windDirection) * arrowLength, 0) |
| 838 | + rotate(windDirection) |
| 839 | + line(0, 0, -5, -3) |
| 840 | + line(0, 0, -5, 3) |
| 841 | + pop() |
| 842 | + |
| 843 | + // Wind strength text |
| 844 | + fill(255, 255, 255, 150) |
| 845 | + noStroke() |
| 846 | + textAlign(CENTER) |
| 847 | + textSize(12) |
| 848 | + text('WIND: ' + Math.round(windStrength), 0, 20) |
| 849 | + pop() |
| 850 | + pop() |
| 851 | + } |
| 852 | + |
| 853 | + for (let i = particles.length - 1; i >= 0; i--) { |
| 854 | + particles[i].update() |
| 855 | + particles[i].display() |
| 856 | + if (particles[i].isDead()) { |
| 857 | + particles.splice(i, 1) |
| 858 | + } |
| 859 | + } |
| 860 | + |
| 861 | + // PHASE 1 UPDATE - Handle broken strands |
| 862 | + for (let i = webStrands.length - 1; i >= 0; i--) { |
| 863 | + let strand = webStrands[i] |
| 864 | + strand.update() |
| 865 | + |
| 866 | + // Remove broken strands |
| 867 | + if (strand.broken) { |
| 868 | + // Create particles for breaking effect |
| 869 | + if (strand.path && strand.path.length > 0) { |
| 870 | + let midPoint = strand.path[Math.floor(strand.path.length / 2)] |
| 871 | + for (let j = 0; j < 5; j++) { |
| 872 | + let p = new Particle(midPoint.x, midPoint.y) |
| 873 | + p.color = color(255, 255, 255) |
| 874 | + p.vel = createVector(random(-2, 2), random(-3, 0)) |
| 875 | + particles.push(p) |
| 584 | 876 | } |
| 585 | | - |
| 586 | | - // Make webs sway |
| 587 | | - for (let strand of webStrands) { |
| 588 | | - if (!strand.broken) { |
| 589 | | - strand.vibrate(windStrength * 0.5); |
| 590 | | - // Check if strand is overstretched and should break |
| 591 | | - if (strand.tension > 1.2 && windStrength > 3) { |
| 592 | | - if (random() < 0.01) { // Small chance per frame |
| 593 | | - strand.broken = true; |
| 594 | | - notifications.push(new Notification("Wind snapped a web!", color(255, 150, 100))); |
| 595 | | - } |
| 877 | + } |
| 878 | + |
| 879 | + // Check all stuck/caught flies to see if they need to be released |
| 880 | + for (let fly of flies) { |
| 881 | + if (fly.stuck || fly.caught) { |
| 882 | + // Check if this fly still has valid web support |
| 883 | + let hasSupport = false |
| 884 | + for (let otherStrand of webStrands) { |
| 885 | + if (otherStrand !== strand && !otherStrand.broken) { |
| 886 | + // Check if fly is on this other strand |
| 887 | + if (otherStrand.path && otherStrand.path.length > 1) { |
| 888 | + for (let k = 0; k < otherStrand.path.length - 1; k++) { |
| 889 | + let p1 = otherStrand.path[k] |
| 890 | + let p2 = otherStrand.path[k + 1] |
| 891 | + let d = fly.pointToLineDistance(fly.pos, p1, p2) |
| 892 | + if (d < fly.radius + 5) { |
| 893 | + hasSupport = true |
| 894 | + break |
| 895 | + } |
| 596 | 896 | } |
| 897 | + } |
| 898 | + if (hasSupport) break |
| 597 | 899 | } |
| 598 | | - } |
| 599 | | - |
| 600 | | - // Update wind particles |
| 601 | | - for (let i = windParticles.length - 1; i >= 0; i--) { |
| 602 | | - let p = windParticles[i]; |
| 603 | | - p.x += cos(windDirection) * windStrength * 3; |
| 604 | | - p.life--; |
| 605 | | - if (p.life <= 0 || p.x < -50 || p.x > width + 50) { |
| 606 | | - windParticles.splice(i, 1); |
| 900 | + } |
| 901 | + |
| 902 | + // If no support, release the fly |
| 903 | + if (!hasSupport) { |
| 904 | + fly.stuck = false |
| 905 | + fly.caught = false |
| 906 | + fly.currentSpeed = fly.baseSpeed |
| 907 | + fly.touchedStrands.clear() |
| 908 | + fly.slowedBy.clear() |
| 909 | + fly.vel = createVector(random(-0.5, 0.5), 1.5) |
| 910 | + |
| 911 | + // Create release particles |
| 912 | + for (let j = 0; j < 3; j++) { |
| 913 | + let p = new Particle(fly.pos.x, fly.pos.y) |
| 914 | + p.color = color(255, 255, 0, 100) |
| 915 | + p.vel = createVector(random(-1, 1), random(0, 1)) |
| 916 | + p.size = 2 |
| 917 | + particles.push(p) |
| 607 | 918 | } |
| 919 | + } |
| 608 | 920 | } |
| 609 | | - |
| 610 | | - // Spawn new wind particles |
| 611 | | - if (frameCount % 5 === 0) { |
| 612 | | - windParticles.push({ |
| 613 | | - x: windDirection > 0 ? -20 : width + 20, |
| 614 | | - y: random(height), |
| 615 | | - life: 120, |
| 616 | | - size: random(2, 4) |
| 617 | | - }); |
| 618 | | - } |
| 921 | + } |
| 922 | + |
| 923 | + webStrands.splice(i, 1) |
| 924 | + } else { |
| 925 | + strand.display() |
| 619 | 926 | } |
| 620 | | - |
| 621 | | - // Update and display game objects |
| 622 | | - for (let obstacle of obstacles) { |
| 623 | | - obstacle.update(); // Update movement and animations |
| 624 | | - obstacle.display(); |
| 625 | | - } |
| 626 | | - |
| 627 | | - for (let box of foodBoxes) { |
| 628 | | - box.display(); |
| 629 | | - } |
| 630 | | - |
| 631 | | - // PHASE 4B: Display wind effects |
| 632 | | - if (windActive) { |
| 633 | | - push(); |
| 634 | | - noStroke(); |
| 635 | | - for (let p of windParticles) { |
| 636 | | - fill(255, 255, 255, p.life * 0.5); |
| 637 | | - ellipse(p.x, p.y, p.size); |
| 638 | | - } |
| 639 | | - |
| 640 | | - // Wind indicator |
| 641 | | - push(); |
| 642 | | - translate(width / 2, 50); |
| 643 | | - stroke(255, 255, 255, 100); |
| 644 | | - strokeWeight(3); |
| 645 | | - let arrowLength = windStrength * 10; |
| 646 | | - line(0, 0, cos(windDirection) * arrowLength, 0); |
| 647 | | - // Arrowhead |
| 648 | | - push(); |
| 649 | | - translate(cos(windDirection) * arrowLength, 0); |
| 650 | | - rotate(windDirection); |
| 651 | | - line(0, 0, -5, -3); |
| 652 | | - line(0, 0, -5, 3); |
| 653 | | - pop(); |
| 654 | | - |
| 655 | | - // Wind strength text |
| 656 | | - fill(255, 255, 255, 150); |
| 657 | | - noStroke(); |
| 658 | | - textAlign(CENTER); |
| 659 | | - textSize(12); |
| 660 | | - text("WIND: " + Math.round(windStrength), 0, 20); |
| 661 | | - pop(); |
| 662 | | - pop(); |
| 663 | | - } |
| 664 | | - |
| 665 | | - for (let i = particles.length - 1; i >= 0; i--) { |
| 666 | | - particles[i].update(); |
| 667 | | - particles[i].display(); |
| 668 | | - if (particles[i].isDead()) { |
| 669 | | - particles.splice(i, 1); |
| 670 | | - } |
| 927 | + } |
| 928 | + |
| 929 | + for (let node of webNodes) { |
| 930 | + node.update() |
| 931 | + } |
| 932 | + |
| 933 | + // Display current strand being created |
| 934 | + if (currentStrand && isDeployingWeb && spider.isAirborne) { |
| 935 | + let opacity = map(webSilk, 0, 20, 50, 150) |
| 936 | + stroke(255, 255, 255, opacity) |
| 937 | + strokeWeight(1.5) |
| 938 | + |
| 939 | + if (currentStrand.path && currentStrand.path.length > 0) { |
| 940 | + noFill() |
| 941 | + beginShape() |
| 942 | + curveVertex(currentStrand.path[0].x, currentStrand.path[0].y) |
| 943 | + for (let point of currentStrand.path) { |
| 944 | + curveVertex(point.x, point.y) |
| 945 | + } |
| 946 | + curveVertex(spider.pos.x, spider.pos.y) |
| 947 | + curveVertex(spider.pos.x, spider.pos.y) |
| 948 | + endShape() |
| 949 | + } else { |
| 950 | + line( |
| 951 | + currentStrand.start.x, |
| 952 | + currentStrand.start.y, |
| 953 | + spider.pos.x, |
| 954 | + spider.pos.y |
| 955 | + ) |
| 671 | 956 | } |
| 672 | | - |
| 673 | | - // PHASE 1 UPDATE - Handle broken strands |
| 674 | | - for (let i = webStrands.length - 1; i >= 0; i--) { |
| 675 | | - let strand = webStrands[i]; |
| 676 | | - strand.update(); |
| 677 | | - |
| 678 | | - // Remove broken strands |
| 679 | | - if (strand.broken) { |
| 680 | | - // Create particles for breaking effect |
| 681 | | - if (strand.path && strand.path.length > 0) { |
| 682 | | - let midPoint = strand.path[Math.floor(strand.path.length / 2)]; |
| 683 | | - for (let j = 0; j < 5; j++) { |
| 684 | | - let p = new Particle(midPoint.x, midPoint.y); |
| 685 | | - p.color = color(255, 255, 255); |
| 686 | | - p.vel = createVector(random(-2, 2), random(-3, 0)); |
| 687 | | - particles.push(p); |
| 688 | | - } |
| 689 | | - } |
| 690 | | - |
| 691 | | - // Check all stuck/caught flies to see if they need to be released |
| 692 | | - for (let fly of flies) { |
| 693 | | - if (fly.stuck || fly.caught) { |
| 694 | | - // Check if this fly still has valid web support |
| 695 | | - let hasSupport = false; |
| 696 | | - for (let otherStrand of webStrands) { |
| 697 | | - if (otherStrand !== strand && !otherStrand.broken) { |
| 698 | | - // Check if fly is on this other strand |
| 699 | | - if (otherStrand.path && otherStrand.path.length > 1) { |
| 700 | | - for (let k = 0; k < otherStrand.path.length - 1; k++) { |
| 701 | | - let p1 = otherStrand.path[k]; |
| 702 | | - let p2 = otherStrand.path[k + 1]; |
| 703 | | - let d = fly.pointToLineDistance(fly.pos, p1, p2); |
| 704 | | - if (d < fly.radius + 5) { |
| 705 | | - hasSupport = true; |
| 706 | | - break; |
| 707 | | - } |
| 708 | | - } |
| 709 | | - } |
| 710 | | - if (hasSupport) break; |
| 711 | | - } |
| 712 | | - } |
| 713 | | - |
| 714 | | - // If no support, release the fly |
| 715 | | - if (!hasSupport) { |
| 716 | | - fly.stuck = false; |
| 717 | | - fly.caught = false; |
| 718 | | - fly.currentSpeed = fly.baseSpeed; |
| 719 | | - fly.touchedStrands.clear(); |
| 720 | | - fly.slowedBy.clear(); |
| 721 | | - fly.vel = createVector(random(-0.5, 0.5), 1.5); |
| 722 | | - |
| 723 | | - // Create release particles |
| 724 | | - for (let j = 0; j < 3; j++) { |
| 725 | | - let p = new Particle(fly.pos.x, fly.pos.y); |
| 726 | | - p.color = color(255, 255, 0, 100); |
| 727 | | - p.vel = createVector(random(-1, 1), random(0, 1)); |
| 728 | | - p.size = 2; |
| 729 | | - particles.push(p); |
| 730 | | - } |
| 731 | | - } |
| 732 | | - } |
| 733 | | - } |
| 734 | | - |
| 735 | | - webStrands.splice(i, 1); |
| 736 | | - } else { |
| 737 | | - strand.display(); |
| 738 | | - } |
| 957 | + } |
| 958 | + |
| 959 | + for (let i = flies.length - 1; i >= 0; i--) { |
| 960 | + flies[i].update() |
| 961 | + flies[i].display() |
| 962 | + } |
| 963 | + |
| 964 | + spider.update() |
| 965 | + spider.display() |
| 966 | + |
| 967 | + // PHASE 4: Exhaustion indicator |
| 968 | + if (gamePhase === 'DAWN' && isExhausted) { |
| 969 | + push() |
| 970 | + textAlign(CENTER) |
| 971 | + textSize(16) |
| 972 | + fill(255, 100, 100, 200 + sin(frameCount * 0.2) * 55) |
| 973 | + stroke(0) |
| 974 | + strokeWeight(2) |
| 975 | + text('NO STAMINA!', spider.pos.x, spider.pos.y - 30) |
| 976 | + pop() |
| 977 | + } |
| 978 | + |
| 979 | + // PHASE 4: Update and display birds during dawn |
| 980 | + if (gamePhase === 'DAWN') { |
| 981 | + // Update stamina |
| 982 | + if (!spider.isAirborne && spider.vel.mag() < 0.1) { |
| 983 | + // Resting - faster regen |
| 984 | + jumpStamina += staminaRegenRate * 2.5 |
| 985 | + } else { |
| 986 | + // Moving - normal regen |
| 987 | + jumpStamina += staminaRegenRate |
| 739 | 988 | } |
| 740 | | - |
| 741 | | - for (let node of webNodes) { |
| 742 | | - node.update(); |
| 743 | | - } |
| 744 | | - |
| 745 | | - // Display current strand being created |
| 746 | | - if (currentStrand && isDeployingWeb && spider.isAirborne) { |
| 747 | | - let opacity = map(webSilk, 0, 20, 50, 150); |
| 748 | | - stroke(255, 255, 255, opacity); |
| 749 | | - strokeWeight(1.5); |
| 750 | | - |
| 751 | | - if (currentStrand.path && currentStrand.path.length > 0) { |
| 752 | | - noFill(); |
| 753 | | - beginShape(); |
| 754 | | - curveVertex(currentStrand.path[0].x, currentStrand.path[0].y); |
| 755 | | - for (let point of currentStrand.path) { |
| 756 | | - curveVertex(point.x, point.y); |
| 757 | | - } |
| 758 | | - curveVertex(spider.pos.x, spider.pos.y); |
| 759 | | - curveVertex(spider.pos.x, spider.pos.y); |
| 760 | | - endShape(); |
| 761 | | - } else { |
| 762 | | - line(currentStrand.start.x, currentStrand.start.y, spider.pos.x, spider.pos.y); |
| 989 | + jumpStamina = min(jumpStamina, maxJumpStamina) |
| 990 | + isExhausted = jumpStamina < jumpCost |
| 991 | + |
| 992 | + // Update and display birds |
| 993 | + for (let i = birds.length - 1; i >= 0; i--) { |
| 994 | + let bird = birds[i] |
| 995 | + if (bird) { |
| 996 | + bird.update() |
| 997 | + bird.display() |
| 998 | + |
| 999 | + // Remove birds that have flown off screen |
| 1000 | + if ( |
| 1001 | + bird.y < -100 || |
| 1002 | + bird.y > height + 100 || |
| 1003 | + bird.x < -100 || |
| 1004 | + bird.x > width + 100 |
| 1005 | + ) { |
| 1006 | + if (bird.state === 'retreating' && !bird.active) { |
| 1007 | + birds.splice(i, 1) |
| 1008 | + } |
| 763 | 1009 | } |
| 1010 | + } |
| 764 | 1011 | } |
| 765 | | - |
| 766 | | - for (let i = flies.length - 1; i >= 0; i--) { |
| 767 | | - flies[i].update(); |
| 768 | | - flies[i].display(); |
| 769 | | - } |
| 770 | | - |
| 771 | | - spider.update(); |
| 772 | | - spider.display(); |
| 773 | | - |
| 774 | | - // PHASE 4: Exhaustion indicator |
| 775 | | - if (gamePhase === 'DAWN' && isExhausted) { |
| 776 | | - push(); |
| 777 | | - textAlign(CENTER); |
| 778 | | - textSize(16); |
| 779 | | - fill(255, 100, 100, 200 + sin(frameCount * 0.2) * 55); |
| 780 | | - stroke(0); |
| 781 | | - strokeWeight(2); |
| 782 | | - text("NO STAMINA!", spider.pos.x, spider.pos.y - 30); |
| 783 | | - pop(); |
| 784 | | - } |
| 785 | | - |
| 786 | | - // PHASE 4: Update and display birds during dawn |
| 787 | | - if (gamePhase === 'DAWN') { |
| 788 | | - // Update stamina |
| 789 | | - if (!spider.isAirborne && spider.vel.mag() < 0.1) { |
| 790 | | - // Resting - faster regen |
| 791 | | - jumpStamina += staminaRegenRate * 2.5; |
| 792 | | - } else { |
| 793 | | - // Moving - normal regen |
| 794 | | - jumpStamina += staminaRegenRate; |
| 795 | | - } |
| 796 | | - jumpStamina = min(jumpStamina, maxJumpStamina); |
| 797 | | - isExhausted = jumpStamina < jumpCost; |
| 798 | | - |
| 799 | | - // Update birds |
| 800 | | - for (let bird of birds) { |
| 801 | | - bird.update(); |
| 802 | | - bird.display(); |
| 803 | | - } |
| 1012 | + |
| 1013 | + // Debug: Show bird count |
| 1014 | + if (frameCount % 60 === 0) { |
| 1015 | + console.log(`Dawn birds active: ${birds.length}`) |
| 804 | 1016 | } |
| 805 | | - |
| 806 | | - // PHASE 4B: Update thief birds during night |
| 807 | | - if (gamePhase === 'NIGHT') { |
| 808 | | - for (let i = birds.length - 1; i >= 0; i--) { |
| 809 | | - let bird = birds[i]; |
| 810 | | - bird.update(); |
| 811 | | - bird.display(); |
| 812 | | - |
| 813 | | - // Remove inactive thief birds |
| 814 | | - if (bird.isThief && !bird.active) { |
| 815 | | - birds.splice(i, 1); |
| 816 | | - } |
| 817 | | - } |
| 1017 | + } |
| 1018 | + |
| 1019 | + // PHASE 4B: Update thief birds during night |
| 1020 | + if (gamePhase === 'NIGHT') { |
| 1021 | + for (let i = birds.length - 1; i >= 0; i--) { |
| 1022 | + let bird = birds[i] |
| 1023 | + bird.update() |
| 1024 | + bird.display() |
| 1025 | + |
| 1026 | + // Remove inactive thief birds |
| 1027 | + if (bird.isThief && !bird.active) { |
| 1028 | + birds.splice(i, 1) |
| 1029 | + } |
| 818 | 1030 | } |
| 819 | | - |
| 820 | | - // PHASE 3: Spider Sense - show fly path predictions |
| 821 | | - if (upgrades.spiderSense && upgrades.spiderSense.level > 0) { |
| 822 | | - push(); |
| 823 | | - strokeWeight(1); |
| 824 | | - for (let fly of flies) { |
| 825 | | - if (!fly.stuck && !fly.caught) { |
| 826 | | - // Predict future position |
| 827 | | - let futurePos = p5.Vector.add(fly.pos, p5.Vector.mult(fly.vel, 30)); |
| 828 | | - stroke(255, 255, 255, 30); |
| 829 | | - line(fly.pos.x, fly.pos.y, futurePos.x, futurePos.y); |
| 830 | | - noFill(); |
| 831 | | - stroke(255, 255, 255, 20); |
| 832 | | - ellipse(futurePos.x, futurePos.y, 10); |
| 833 | | - } |
| 834 | | - } |
| 835 | | - pop(); |
| 836 | | - } |
| 837 | | - |
| 838 | | - // PHASE 2: Display notifications |
| 839 | | - for (let i = notifications.length - 1; i >= 0; i--) { |
| 840 | | - notifications[i].update(); |
| 841 | | - notifications[i].display(); |
| 842 | | - if (notifications[i].isDead()) { |
| 843 | | - notifications.splice(i, 1); |
| 844 | | - } |
| 1031 | + } |
| 1032 | + |
| 1033 | + // PHASE 3: Spider Sense - show fly path predictions |
| 1034 | + if (upgrades.spiderSense && upgrades.spiderSense.level > 0) { |
| 1035 | + push() |
| 1036 | + strokeWeight(1) |
| 1037 | + for (let fly of flies) { |
| 1038 | + if (!fly.stuck && !fly.caught) { |
| 1039 | + // Predict future position |
| 1040 | + let futurePos = p5.Vector.add(fly.pos, p5.Vector.mult(fly.vel, 30)) |
| 1041 | + stroke(255, 255, 255, 30) |
| 1042 | + line(fly.pos.x, fly.pos.y, futurePos.x, futurePos.y) |
| 1043 | + noFill() |
| 1044 | + stroke(255, 255, 255, 20) |
| 1045 | + ellipse(futurePos.x, futurePos.y, 10) |
| 1046 | + } |
| 845 | 1047 | } |
| 846 | | - |
| 847 | | - // PHASE 5: Display achievements |
| 848 | | - displayAchievements(); |
| 849 | | - |
| 850 | | - // Update resources |
| 851 | | - updateResources(); |
| 852 | | - |
| 853 | | - // PHASE 5: Check achievements continuously |
| 854 | | - checkAchievements(); |
| 855 | | - |
| 856 | | - // PHASE 3: Update jump charging |
| 857 | | - if (chargingJump && !spider.isAirborne) { |
| 858 | | - jumpChargeTime++; |
| 859 | | - spider.jumpChargeVisual = min(jumpChargeTime / maxJumpCharge, 1); |
| 860 | | - } else { |
| 861 | | - spider.jumpChargeVisual = 0; |
| 862 | | - } |
| 863 | | - |
| 864 | | - // Handle web deployment |
| 865 | | - handleWebDeployment(); |
| 866 | | - |
| 867 | | - // Update UI |
| 868 | | - updateUI(); |
| 869 | | - |
| 870 | | - // Spawn entities during night - PHASE 1 UPDATE |
| 871 | | - if (gamePhase === 'NIGHT') { |
| 872 | | - // Dynamic spawn rate based on difficulty |
| 873 | | - let spawnRate = max(90, 120 - currentNight * 5); // Faster spawning over time |
| 874 | | - if (phaseTimer % spawnRate === 0 && flies.length < 10 + currentNight * 2) { |
| 875 | | - // PHASE 2: Spawn different types during the night too |
| 876 | | - let flyType = 'regular'; |
| 877 | | - let roll = random(); |
| 878 | | - |
| 879 | | - if (currentNight >= 5 && roll < 0.03) { |
| 880 | | - flyType = 'queen'; |
| 881 | | - } else if (roll < 0.08) { |
| 882 | | - flyType = 'golden'; |
| 883 | | - } else if (roll < 0.20) { |
| 884 | | - flyType = 'moth'; |
| 885 | | - } |
| 886 | | - |
| 887 | | - let fly = new Fly(flyType); |
| 888 | | - let speedMult = 1 + Math.floor((currentNight - 1) / 3) * 0.1; |
| 889 | | - fly.baseSpeed = baseFlySpeed * speedMult; |
| 890 | | - if (flyType === 'golden') fly.baseSpeed *= 1.3; |
| 891 | | - if (flyType === 'moth') fly.baseSpeed *= 0.8; |
| 892 | | - if (flyType === 'queen') fly.baseSpeed *= 0.5; |
| 893 | | - fly.currentSpeed = fly.baseSpeed; |
| 894 | | - flies.push(fly); |
| 895 | | - } |
| 896 | | - if (phaseTimer % 300 === 0 && foodBoxes.length < 6) { |
| 897 | | - spawnFoodBox(); |
| 898 | | - } |
| 899 | | - |
| 900 | | - // PHASE 4B: Spawn thief birds at night (after Night 5) |
| 901 | | - if (currentNight >= 5) { |
| 902 | | - thiefBirdTimer++; |
| 903 | | - if (thiefBirdTimer >= nextThiefTime) { |
| 904 | | - spawnThiefBird(); |
| 905 | | - thiefBirdTimer = 0; |
| 906 | | - nextThiefTime = random(2700, 3600); // 45-60 seconds |
| 907 | | - } |
| 908 | | - } |
| 909 | | - |
| 910 | | - // PHASE 4B: Random wind gusts at night |
| 911 | | - if (!windActive && frameCount > nextWindTime) { |
| 912 | | - startWindGust(); |
| 913 | | - } |
| 1048 | + pop() |
| 1049 | + } |
| 1050 | + |
| 1051 | + // PHASE 2: Display notifications |
| 1052 | + for (let i = notifications.length - 1; i >= 0; i--) { |
| 1053 | + notifications[i].update() |
| 1054 | + notifications[i].display() |
| 1055 | + if (notifications[i].isDead()) { |
| 1056 | + notifications.splice(i, 1) |
| 914 | 1057 | } |
| 915 | | -} |
| 1058 | + } |
| 1059 | + |
| 1060 | + // PHASE 5: Display achievements |
| 1061 | + displayAchievements() |
| 1062 | + |
| 1063 | + // Update resources |
| 1064 | + updateResources() |
| 1065 | + |
| 1066 | + // PHASE 5: Check achievements continuously |
| 1067 | + checkAchievements() |
| 1068 | + |
| 1069 | + // PHASE 3: Update jump charging |
| 1070 | + if (chargingJump && !spider.isAirborne) { |
| 1071 | + jumpChargeTime++ |
| 1072 | + spider.jumpChargeVisual = min(jumpChargeTime / maxJumpCharge, 1) |
| 1073 | + } else { |
| 1074 | + spider.jumpChargeVisual = 0 |
| 1075 | + } |
| 916 | 1076 | |
| 917 | | -// Continue with all the remaining functions... |
| 918 | | -function openStatsPanel() { |
| 919 | | - // Implementation continues from original file |
| 1077 | + // Handle web deployment |
| 1078 | + handleWebDeployment() |
| 1079 | + |
| 1080 | + // Update UI |
| 1081 | + updateUI() |
| 1082 | + |
| 1083 | + // Spawn entities during night - PHASE 1 UPDATE |
| 1084 | + if (gamePhase === 'NIGHT') { |
| 1085 | + // Dynamic spawn rate based on difficulty |
| 1086 | + let spawnRate = max(90, 120 - currentNight * 5) // Faster spawning over time |
| 1087 | + if (phaseTimer % spawnRate === 0 && flies.length < 10 + currentNight * 2) { |
| 1088 | + // PHASE 2: Spawn different types during the night too |
| 1089 | + let flyType = 'regular' |
| 1090 | + let roll = random() |
| 1091 | + |
| 1092 | + if (currentNight >= 5 && roll < 0.03) { |
| 1093 | + flyType = 'queen' |
| 1094 | + } else if (roll < 0.08) { |
| 1095 | + flyType = 'golden' |
| 1096 | + } else if (roll < 0.2) { |
| 1097 | + flyType = 'moth' |
| 1098 | + } |
| 1099 | + |
| 1100 | + let fly = new Fly(flyType) |
| 1101 | + let speedMult = 1 + Math.floor((currentNight - 1) / 3) * 0.1 |
| 1102 | + fly.baseSpeed = baseFlySpeed * speedMult |
| 1103 | + if (flyType === 'golden') fly.baseSpeed *= 1.3 |
| 1104 | + if (flyType === 'moth') fly.baseSpeed *= 0.8 |
| 1105 | + if (flyType === 'queen') fly.baseSpeed *= 0.5 |
| 1106 | + fly.currentSpeed = fly.baseSpeed |
| 1107 | + flies.push(fly) |
| 1108 | + } |
| 1109 | + if (phaseTimer % 300 === 0 && foodBoxes.length < 6) { |
| 1110 | + spawnFoodBox() |
| 1111 | + } |
| 1112 | + |
| 1113 | + // PHASE 4B: Spawn thief birds at night (after Night 5) |
| 1114 | + if (currentNight >= 5) { |
| 1115 | + thiefBirdTimer++ |
| 1116 | + if (thiefBirdTimer >= nextThiefTime) { |
| 1117 | + spawnThiefBird() |
| 1118 | + thiefBirdTimer = 0 |
| 1119 | + nextThiefTime = random(2700, 3600) // 45-60 seconds |
| 1120 | + } |
| 1121 | + } |
| 1122 | + |
| 1123 | + // PHASE 4B: Random wind gusts at night |
| 1124 | + if (!windActive && frameCount > nextWindTime) { |
| 1125 | + startWindGust() |
| 1126 | + } |
| 1127 | + } |
| 920 | 1128 | } |
| 921 | 1129 | |
| 922 | | -function checkAchievements() { |
| 923 | | - // Implementation continues from original file |
| 1130 | +function openStatsPanel () { |
| 1131 | + // Update stats display |
| 1132 | + let statsHTML = ` |
| 1133 | + <div>Total Flies Caught: ${stats.totalFliesCaught}</div> |
| 1134 | + <div>Regular: ${stats.regularCaught}</div> |
| 1135 | + <div>Golden: ${stats.goldenCaught}</div> |
| 1136 | + <div>Moths: ${stats.mothsCaught}</div> |
| 1137 | + <div>Queens: ${stats.queensCaught}</div> |
| 1138 | + <div>Longest Night: ${stats.longestNight}</div> |
| 1139 | + <div>Total Jumps: ${stats.totalJumps}</div> |
| 1140 | + <div>Wind Jumps: ${stats.windJumps}</div> |
| 1141 | + <div>Thieves Scared: ${stats.thievesScared}</div> |
| 1142 | + <div>Perfect Dawns: ${stats.perfectDawns}</div> |
| 1143 | + ` |
| 1144 | + document.getElementById('stats-list').innerHTML = statsHTML |
| 1145 | + |
| 1146 | + // Update skins display |
| 1147 | + let skinsHTML = '' |
| 1148 | + let skins = [ |
| 1149 | + { id: 'default', name: 'Classic', icon: '🕷️', unlocked: true }, |
| 1150 | + { |
| 1151 | + id: 'galaxy', |
| 1152 | + name: 'Galaxy', |
| 1153 | + icon: '🌌', |
| 1154 | + unlocked: unlockedSkins.galaxy |
| 1155 | + }, |
| 1156 | + { |
| 1157 | + id: 'golden', |
| 1158 | + name: 'Golden', |
| 1159 | + icon: '✨', |
| 1160 | + unlocked: unlockedSkins.golden |
| 1161 | + }, |
| 1162 | + { |
| 1163 | + id: 'shadow', |
| 1164 | + name: 'Shadow', |
| 1165 | + icon: '🌑', |
| 1166 | + unlocked: unlockedSkins.shadow |
| 1167 | + }, |
| 1168 | + { |
| 1169 | + id: 'rainbow', |
| 1170 | + name: 'Rainbow', |
| 1171 | + icon: '🌈', |
| 1172 | + unlocked: unlockedSkins.rainbow |
| 1173 | + } |
| 1174 | + ] |
| 1175 | + |
| 1176 | + for (let skin of skins) { |
| 1177 | + let selected = currentSkin === skin.id |
| 1178 | + let locked = !skin.unlocked |
| 1179 | + skinsHTML += ` |
| 1180 | + <div onclick="selectSkin('${skin.id}')" |
| 1181 | + style="padding: 10px; background: ${ |
| 1182 | + selected ? '#FFD700' : locked ? '#444' : '#666' |
| 1183 | + }; |
| 1184 | + border-radius: 10px; cursor: ${ |
| 1185 | + locked ? 'not-allowed' : 'pointer' |
| 1186 | + }; |
| 1187 | + opacity: ${locked ? '0.5' : '1'}; text-align: center;"> |
| 1188 | + <div style="font-size: 30px;">${skin.icon}</div> |
| 1189 | + <div style="font-size: 12px; color: ${ |
| 1190 | + selected ? '#000' : '#FFF' |
| 1191 | + };"> |
| 1192 | + ${skin.name}${locked ? ' 🔒' : ''} |
| 1193 | + </div> |
| 1194 | + </div> |
| 1195 | + ` |
| 1196 | + } |
| 1197 | + document.getElementById('skins-list').innerHTML = skinsHTML |
| 1198 | + |
| 1199 | + // Update achievements display |
| 1200 | + let achievementsHTML = '' |
| 1201 | + for (let key in achievements) { |
| 1202 | + let ach = achievements[key] |
| 1203 | + let progress = |
| 1204 | + ach.progress !== undefined ? ` (${ach.progress}/${ach.target})` : '' |
| 1205 | + achievementsHTML += ` |
| 1206 | + <div style="padding: 8px; background: ${ |
| 1207 | + ach.unlocked ? '#4CAF50' : '#444' |
| 1208 | + }; |
| 1209 | + border-radius: 5px; opacity: ${ |
| 1210 | + ach.unlocked ? '1' : '0.6' |
| 1211 | + };"> |
| 1212 | + ${ach.icon} ${ach.name}${!ach.unlocked ? progress : ' ✓'} |
| 1213 | + </div> |
| 1214 | + ` |
| 1215 | + } |
| 1216 | + document.getElementById('achievements-list').innerHTML = achievementsHTML |
| 1217 | + |
| 1218 | + // Show panel |
| 1219 | + document.getElementById('stats-panel').style.display = 'block' |
| 1220 | + |
| 1221 | + // Add close button listener |
| 1222 | + document.getElementById('close-stats-btn').onclick = () => { |
| 1223 | + document.getElementById('stats-panel').style.display = 'none' |
| 1224 | + |
| 1225 | + // IMMEDIATELY transition to dusk after closing stats |
| 1226 | + if (gamePhase === 'DAY') { |
| 1227 | + gamePhase = 'DAY_TO_DUSK' |
| 1228 | + phaseTimer = 0 |
| 1229 | + } |
| 1230 | + } |
| 924 | 1231 | } |
| 925 | 1232 | |
| 926 | | -function checkNightAchievements() { |
| 927 | | - // Implementation continues from original file |
| 1233 | +// Make selectSkin global |
| 1234 | +window.selectSkin = function (skinId) { |
| 1235 | + if (unlockedSkins[skinId]) { |
| 1236 | + currentSkin = skinId |
| 1237 | + saveGame() |
| 1238 | + openStatsPanel() // Refresh display |
| 1239 | + notifications.push( |
| 1240 | + new Notification(`Skin changed to ${skinId}!`, color(100, 255, 100)) |
| 1241 | + ) |
| 1242 | + } |
| 928 | 1243 | } |
| 929 | 1244 | |
| 930 | | -function checkDawnAchievements() { |
| 931 | | - // Implementation continues from original file |
| 1245 | +// ============================================ |
| 1246 | +// PHASE 5: ACHIEVEMENTS & COSMETICS |
| 1247 | +// ============================================ |
| 1248 | + |
| 1249 | +function checkAchievements () { |
| 1250 | + // Night Owl - Survive X nights |
| 1251 | + if (!achievements.nightOwl.unlocked) { |
| 1252 | + achievements.nightOwl.progress = nightsSurvived |
| 1253 | + if (nightsSurvived >= achievements.nightOwl.target) { |
| 1254 | + unlockAchievement('nightOwl') |
| 1255 | + } |
| 1256 | + } |
| 1257 | + |
| 1258 | + // Silk Master - 15+ strands at once |
| 1259 | + if (!achievements.silkMaster.unlocked) { |
| 1260 | + let activeStrands = webStrands.filter(s => !s.broken).length |
| 1261 | + achievements.silkMaster.progress = max( |
| 1262 | + achievements.silkMaster.progress, |
| 1263 | + activeStrands |
| 1264 | + ) |
| 1265 | + if (activeStrands >= achievements.silkMaster.target) { |
| 1266 | + unlockAchievement('silkMaster') |
| 1267 | + } |
| 1268 | + } |
| 1269 | + |
| 1270 | + // Wind Rider - Jump during wind |
| 1271 | + if ( |
| 1272 | + !achievements.windRider.unlocked && |
| 1273 | + achievements.windRider.progress >= achievements.windRider.target |
| 1274 | + ) { |
| 1275 | + unlockAchievement('windRider') |
| 1276 | + } |
| 1277 | + |
| 1278 | + // Thief Defender |
| 1279 | + if ( |
| 1280 | + !achievements.thiefDefender.unlocked && |
| 1281 | + stats.thievesScared >= achievements.thiefDefender.target |
| 1282 | + ) { |
| 1283 | + achievements.thiefDefender.progress = stats.thievesScared |
| 1284 | + unlockAchievement('thiefDefender') |
| 1285 | + } |
| 1286 | + |
| 1287 | + // Queen Slayer |
| 1288 | + if (!achievements.queenSlayer.unlocked) { |
| 1289 | + achievements.queenSlayer.progress = stats.queensCaught |
| 1290 | + if (stats.queensCaught >= achievements.queenSlayer.target) { |
| 1291 | + unlockAchievement('queenSlayer') |
| 1292 | + } |
| 1293 | + } |
| 1294 | + |
| 1295 | + // Galaxy Unlock - 15 nights |
| 1296 | + if (!achievements.galaxyUnlock.unlocked) { |
| 1297 | + achievements.galaxyUnlock.progress = nightsSurvived |
| 1298 | + if (nightsSurvived >= achievements.galaxyUnlock.target) { |
| 1299 | + unlockAchievement('galaxyUnlock') |
| 1300 | + unlockedSkins.galaxy = true |
| 1301 | + } |
| 1302 | + } |
| 1303 | + |
| 1304 | + // Golden Hunter - 100 golden flies |
| 1305 | + if (!achievements.goldenHunter.unlocked) { |
| 1306 | + achievements.goldenHunter.progress = stats.goldenCaught |
| 1307 | + if (stats.goldenCaught >= achievements.goldenHunter.target) { |
| 1308 | + unlockAchievement('goldenHunter') |
| 1309 | + unlockedSkins.golden = true |
| 1310 | + } |
| 1311 | + } |
| 1312 | + |
| 1313 | + // Web Master - 500 total flies |
| 1314 | + if (!achievements.webMaster.unlocked) { |
| 1315 | + achievements.webMaster.progress = stats.totalFliesCaught |
| 1316 | + if (stats.totalFliesCaught >= achievements.webMaster.target) { |
| 1317 | + unlockAchievement('webMaster') |
| 1318 | + unlockedSkins.rainbow = true |
| 1319 | + } |
| 1320 | + } |
| 1321 | + |
| 1322 | + // Speedrunner - 30 flies before night 5 |
| 1323 | + if ( |
| 1324 | + !achievements.speedrunner.unlocked && |
| 1325 | + currentNight < 5 && |
| 1326 | + stats.totalFliesCaught >= 30 |
| 1327 | + ) { |
| 1328 | + unlockAchievement('speedrunner') |
| 1329 | + } |
| 932 | 1330 | } |
| 933 | 1331 | |
| 934 | | -function unlockAchievement(achievementKey) { |
| 935 | | - // Implementation continues from original file |
| 1332 | +function checkNightAchievements () { |
| 1333 | + // Called at end of night |
| 1334 | + |
| 1335 | + // Feast - 20 flies munched in one night |
| 1336 | + if ( |
| 1337 | + !achievements.feast.unlocked && |
| 1338 | + stats.fliesMunchedInCurrentNight >= achievements.feast.target |
| 1339 | + ) { |
| 1340 | + achievements.feast.progress = stats.fliesMunchedInCurrentNight |
| 1341 | + unlockAchievement('feast') |
| 1342 | + } |
| 1343 | + |
| 1344 | + // Architect - Catch 5 flies without munching |
| 1345 | + if ( |
| 1346 | + !achievements.architect.unlocked && |
| 1347 | + stats.fliesCaughtWithoutMunch >= achievements.architect.target |
| 1348 | + ) { |
| 1349 | + achievements.architect.progress = stats.fliesCaughtWithoutMunch |
| 1350 | + unlockAchievement('architect') |
| 1351 | + } |
| 1352 | + |
| 1353 | + // Untouchable - No strands lost |
| 1354 | + if (!achievements.untouchable.unlocked && stats.strandsLostInNight === 0) { |
| 1355 | + unlockAchievement('untouchable') |
| 1356 | + } |
| 1357 | + |
| 1358 | + // Shadow Predator - 50 flies in one night |
| 1359 | + if ( |
| 1360 | + !achievements.shadowPredator.unlocked && |
| 1361 | + fliesCaught >= achievements.shadowPredator.target |
| 1362 | + ) { |
| 1363 | + achievements.shadowPredator.progress = fliesCaught |
| 1364 | + unlockAchievement('shadowPredator') |
| 1365 | + unlockedSkins.shadow = true |
| 1366 | + } |
| 1367 | + |
| 1368 | + // Reset night-specific counters |
| 1369 | + stats.fliesMunchedInCurrentNight = 0 |
| 1370 | + stats.fliesCaughtWithoutMunch = fliesCaught |
| 1371 | + stats.strandsLostInNight = 0 |
| 936 | 1372 | } |
| 937 | 1373 | |
| 938 | | -function displayAchievements() { |
| 939 | | - // Implementation continues from original file |
| 1374 | +function checkDawnAchievements () { |
| 1375 | + // Perfect Dawn - no bird hits |
| 1376 | + if (!achievements.perfectDawn.unlocked && stats.birdHitsTaken === 0) { |
| 1377 | + unlockAchievement('perfectDawn') |
| 1378 | + stats.perfectDawns++ |
| 1379 | + } |
| 1380 | + |
| 1381 | + // Exhaustion Master - survive with < 20 stamina |
| 1382 | + if (!achievements.exhaustionMaster.unlocked && jumpStamina < 20) { |
| 1383 | + unlockAchievement('exhaustionMaster') |
| 1384 | + } |
| 1385 | + |
| 1386 | + // Reset dawn counter |
| 1387 | + stats.birdHitsTaken = 0 |
| 940 | 1388 | } |
| 941 | 1389 | |
| 942 | | -function saveGame() { |
| 943 | | - // Implementation continues from original file |
| 1390 | +function unlockAchievement (achievementKey) { |
| 1391 | + let achievement = achievements[achievementKey] |
| 1392 | + if (achievement.unlocked) return |
| 1393 | + |
| 1394 | + achievement.unlocked = true |
| 1395 | + achievementQueue.push(achievement) |
| 1396 | + |
| 1397 | + // Save to localStorage |
| 1398 | + saveGame() |
| 944 | 1399 | } |
| 945 | 1400 | |
| 946 | | -function loadGame() { |
| 947 | | - let saveData = localStorage.getItem('cobGameSave'); |
| 948 | | - if (saveData) { |
| 949 | | - let data = JSON.parse(saveData); |
| 950 | | - achievements = data.achievements || achievements; |
| 951 | | - stats = data.stats || stats; |
| 952 | | - unlockedSkins = data.unlockedSkins || unlockedSkins; |
| 953 | | - currentSkin = data.currentSkin || 'default'; |
| 954 | | - upgrades = data.upgrades || upgrades; |
| 955 | | - playerPoints = data.playerPoints || 0; |
| 956 | | - nightsSurvived = data.nightsSurvived || 0; |
| 957 | | - currentNight = data.currentNight || 1; |
| 958 | | - |
| 959 | | - // Apply upgrades (spider exists now) |
| 960 | | - applyUpgradeEffects(); |
| 1401 | +function displayAchievements () { |
| 1402 | + // Show queued achievements |
| 1403 | + if (!showingAchievement && achievementQueue.length > 0) { |
| 1404 | + showingAchievement = achievementQueue.shift() |
| 1405 | + achievementDisplayTimer = 240 // 4 seconds |
| 1406 | + } |
| 1407 | + |
| 1408 | + // Display current achievement |
| 1409 | + if (showingAchievement && achievementDisplayTimer > 0) { |
| 1410 | + push() |
| 1411 | + |
| 1412 | + // Background |
| 1413 | + let alpha = |
| 1414 | + achievementDisplayTimer > 200 |
| 1415 | + ? 255 |
| 1416 | + : map(achievementDisplayTimer, 0, 40, 0, 255) |
| 1417 | + fill(20, 20, 40, alpha * 0.9) |
| 1418 | + stroke(255, 215, 0, alpha) |
| 1419 | + strokeWeight(3) |
| 1420 | + rectMode(CENTER) |
| 1421 | + rect(width / 2, 100, 400, 80, 10) |
| 1422 | + |
| 1423 | + // Icon |
| 1424 | + textAlign(CENTER) |
| 1425 | + textSize(30) |
| 1426 | + fill(255, 255, 255, alpha) |
| 1427 | + text(showingAchievement.icon, width / 2 - 150, 105) |
| 1428 | + |
| 1429 | + // Text |
| 1430 | + textSize(20) |
| 1431 | + fill(255, 215, 0, alpha) |
| 1432 | + text('ACHIEVEMENT UNLOCKED!', width / 2, 85) |
| 1433 | + |
| 1434 | + textSize(16) |
| 1435 | + fill(255, 255, 255, alpha) |
| 1436 | + text(showingAchievement.name, width / 2, 105) |
| 1437 | + |
| 1438 | + textSize(12) |
| 1439 | + fill(200, 200, 200, alpha) |
| 1440 | + text(showingAchievement.desc, width / 2, 125) |
| 1441 | + |
| 1442 | + pop() |
| 1443 | + |
| 1444 | + achievementDisplayTimer-- |
| 1445 | + if (achievementDisplayTimer <= 0) { |
| 1446 | + showingAchievement = null |
| 961 | 1447 | } |
| 1448 | + } |
| 962 | 1449 | } |
| 963 | 1450 | |
| 964 | | -function spawnThiefBird() { |
| 965 | | - // Implementation continues from original file |
| 1451 | +function saveGame () { |
| 1452 | + // Save to localStorage |
| 1453 | + let saveData = { |
| 1454 | + achievements: achievements, |
| 1455 | + stats: stats, |
| 1456 | + unlockedSkins: unlockedSkins, |
| 1457 | + currentSkin: currentSkin, |
| 1458 | + upgrades: upgrades, |
| 1459 | + playerPoints: playerPoints, |
| 1460 | + nightsSurvived: nightsSurvived, |
| 1461 | + currentNight: currentNight |
| 1462 | + } |
| 1463 | + |
| 1464 | + localStorage.setItem('cobGameSave', JSON.stringify(saveData)) |
| 966 | 1465 | } |
| 967 | 1466 | |
| 968 | | -function startWindGust() { |
| 969 | | - // Implementation continues from original file |
| 1467 | +function loadGame () { |
| 1468 | + let saveData = localStorage.getItem('cobGameSave') |
| 1469 | + if (saveData) { |
| 1470 | + let data = JSON.parse(saveData) |
| 1471 | + achievements = data.achievements || achievements |
| 1472 | + stats = data.stats || stats |
| 1473 | + unlockedSkins = data.unlockedSkins || unlockedSkins |
| 1474 | + currentSkin = data.currentSkin || 'default' |
| 1475 | + upgrades = data.upgrades || upgrades |
| 1476 | + playerPoints = data.playerPoints || 0 |
| 1477 | + nightsSurvived = data.nightsSurvived || 0 |
| 1478 | + currentNight = data.currentNight || 1 |
| 1479 | + |
| 1480 | + // Apply upgrades |
| 1481 | + applyUpgradeEffects() |
| 1482 | + } |
| 970 | 1483 | } |
| 971 | 1484 | |
| 972 | | -function updateWind() { |
| 973 | | - // Implementation continues from original file |
| 1485 | +// ============================================ |
| 1486 | +// PHASE 4B: NIGHT THREATS |
| 1487 | +// ============================================ |
| 1488 | + |
| 1489 | +function spawnThiefBird () { |
| 1490 | + // Check if there are caught flies to steal |
| 1491 | + let caughtFlies = flies.filter(f => f.stuck || f.caught) |
| 1492 | + if (caughtFlies.length === 0) return |
| 1493 | + |
| 1494 | + // Create a thief bird |
| 1495 | + let thief = new Bird('swoop', true) |
| 1496 | + thief.active = true |
| 1497 | + thief.attackDelay = 60 // Attack quickly |
| 1498 | + birds.push(thief) |
| 1499 | + |
| 1500 | + // PHASE 5: Track thief scared if spider is near |
| 1501 | + if ( |
| 1502 | + dist( |
| 1503 | + spider.pos.x, |
| 1504 | + spider.pos.y, |
| 1505 | + caughtFlies[0].pos.x, |
| 1506 | + caughtFlies[0].pos.y |
| 1507 | + ) < 80 |
| 1508 | + ) { |
| 1509 | + stats.thievesScared++ |
| 1510 | + } |
| 1511 | + |
| 1512 | + // Visual warning |
| 1513 | + push() |
| 1514 | + textAlign(CENTER) |
| 1515 | + textSize(30) |
| 1516 | + fill(200, 50, 200) |
| 1517 | + stroke(0) |
| 1518 | + strokeWeight(3) |
| 1519 | + text('THIEF!', width / 2, height / 2) |
| 1520 | + pop() |
| 974 | 1521 | } |
| 975 | 1522 | |
| 976 | | -function spawnDawnBirds() { |
| 977 | | - // Implementation continues from original file |
| 1523 | +function startWindGust () { |
| 1524 | + windActive = true |
| 1525 | + windDirection = random() < 0.5 ? 0 : PI // Left or right |
| 1526 | + windStrength = random(2, 5) // Variable strength |
| 1527 | + windDuration = random(300, 600) // 5-10 seconds |
| 1528 | + windTimer = 0 |
| 1529 | + windParticles = [] |
| 1530 | + |
| 1531 | + // Notification |
| 1532 | + let direction = windDirection === 0 ? '→' : '←' |
| 1533 | + notifications.push( |
| 1534 | + new Notification(`Wind gust ${direction}`, color(200, 200, 255)) |
| 1535 | + ) |
| 978 | 1536 | } |
| 979 | 1537 | |
| 980 | | -function openUpgradeShop() { |
| 981 | | - // Implementation continues from original file |
| 1538 | +function updateWind () { |
| 1539 | + if (!windActive) return |
| 1540 | + |
| 1541 | + windTimer++ |
| 1542 | + |
| 1543 | + // Fade in and out |
| 1544 | + if (windTimer < 60) { |
| 1545 | + // Fade in |
| 1546 | + windStrength = lerp(0, windStrength, windTimer / 60) |
| 1547 | + } else if (windTimer > windDuration - 60) { |
| 1548 | + // Fade out |
| 1549 | + windStrength = lerp(windStrength, 0, (windTimer - (windDuration - 60)) / 60) |
| 1550 | + } |
| 1551 | + |
| 1552 | + // End wind |
| 1553 | + if (windTimer >= windDuration) { |
| 1554 | + windActive = false |
| 1555 | + windTimer = 0 |
| 1556 | + windParticles = [] |
| 1557 | + nextWindTime = frameCount + random(1800, 3600) // 30-60 seconds until next wind |
| 1558 | + } |
| 982 | 1559 | } |
| 983 | 1560 | |
| 984 | | -function closeUpgradeShop() { |
| 985 | | - // Implementation continues from original file |
| 1561 | +// ============================================ |
| 1562 | +// PHASE 4: DAWN SURVIVAL FUNCTIONS |
| 1563 | +// ============================================ |
| 1564 | + |
| 1565 | +function spawnDawnBirds () { |
| 1566 | + birds = [] |
| 1567 | + |
| 1568 | + // Start with 3 birds, add 1 every 3 nights (capped at 6) |
| 1569 | + let numBirds = min(3 + Math.floor((currentNight - 1) / 3), 6) |
| 1570 | + |
| 1571 | + // Mix of attack patterns |
| 1572 | + let patterns = ['dive', 'dive', 'glide'] // More dive birds |
| 1573 | + if (currentNight >= 3) patterns.push('circle') |
| 1574 | + if (currentNight >= 6) patterns.push('dive', 'glide') |
| 1575 | + |
| 1576 | + for (let i = 0; i < numBirds; i++) { |
| 1577 | + let pattern = random(patterns) |
| 1578 | + let bird = new Bird(pattern, false) // false = not a thief |
| 1579 | + bird.active = false // Will activate after delay |
| 1580 | + bird.attackDelay = 60 + i * 60 // Stagger attack delays |
| 1581 | + birds.push(bird) |
| 1582 | + } |
| 1583 | + |
| 1584 | + // Notification |
| 1585 | + notifications.push( |
| 1586 | + new Notification(`DAWN! ${numBirds} birds hunting!`, color(255, 150, 100)) |
| 1587 | + ) |
| 1588 | + |
| 1589 | + // Debug log to confirm birds are spawning |
| 1590 | + console.log(`Spawned ${numBirds} dawn birds`) |
| 986 | 1591 | } |
| 987 | 1592 | |
| 988 | | -function updateShopDisplay() { |
| 989 | | - // Implementation continues from original file |
| 1593 | +// ============================================ |
| 1594 | +// PHASE 3: UPGRADE SHOP FUNCTIONS |
| 1595 | +// ============================================ |
| 1596 | + |
| 1597 | +function openUpgradeShop () { |
| 1598 | + if (currentNight <= 1) return // No shop on first night |
| 1599 | + |
| 1600 | + shopOpen = true |
| 1601 | + noLoop() // Pause the game |
| 1602 | + |
| 1603 | + // Calculate points from flies caught this session |
| 1604 | + playerPoints = totalFliesCaught |
| 1605 | + |
| 1606 | + // Update shop UI |
| 1607 | + document.getElementById('upgrade-shop').style.display = 'block' |
| 1608 | + document.getElementById('available-points').textContent = playerPoints |
| 1609 | + |
| 1610 | + // Populate upgrade lists |
| 1611 | + updateShopDisplay() |
| 1612 | + |
| 1613 | + // Add continue button listener |
| 1614 | + document.getElementById('continue-btn').onclick = closeUpgradeShop |
| 990 | 1615 | } |
| 991 | 1616 | |
| 992 | | -function applyUpgradeEffects() { |
| 993 | | - // Check if spider exists before applying upgrades |
| 994 | | - if (!spider) return; |
| 995 | | - |
| 996 | | - // Reset to base values |
| 997 | | - spider.jumpPower = 12; |
| 998 | | - maxWebSilk = 100; |
| 999 | | - silkDrainRate = 2; |
| 1000 | | - spider.munchCooldownMax = 30; // Add this property to spider |
| 1001 | | - |
| 1002 | | - // Apply Tier 1 upgrades |
| 1003 | | - if (upgrades.strongLegs.level > 0) { |
| 1004 | | - spider.jumpPower = 12 * (1 + 0.15 * upgrades.strongLegs.level); |
| 1005 | | - } |
| 1006 | | - |
| 1007 | | - if (upgrades.silkGlands.level > 0) { |
| 1008 | | - maxWebSilk = 100 + (20 * upgrades.silkGlands.level); |
| 1009 | | - webSilk = min(webSilk, maxWebSilk); // Cap current silk to new max |
| 1010 | | - } |
| 1011 | | - |
| 1012 | | - if (upgrades.efficientSpinning.level > 0) { |
| 1013 | | - silkDrainRate = 2 * (1 - 0.2 * upgrades.efficientSpinning.level); |
| 1014 | | - } |
| 1015 | | - |
| 1016 | | - if (upgrades.quickMunch.level > 0) { |
| 1017 | | - spider.munchCooldownMax = 30 * (1 - 0.3 * upgrades.quickMunch.level); |
| 1018 | | - } |
| 1019 | | - |
| 1020 | | - // Tier 2 upgrades are handled in their respective functions |
| 1617 | +function closeUpgradeShop () { |
| 1618 | + shopOpen = false |
| 1619 | + document.getElementById('upgrade-shop').style.display = 'none' |
| 1620 | + |
| 1621 | + // IMMEDIATELY transition to dusk after closing shop |
| 1622 | + if (gamePhase === 'DAY') { |
| 1623 | + gamePhase = 'DAY_TO_DUSK' |
| 1624 | + phaseTimer = 0 |
| 1625 | + } |
| 1626 | + |
| 1627 | + loop() // Resume the game |
| 1021 | 1628 | } |
| 1022 | 1629 | |
| 1023 | | -function spawnNightFlies() { |
| 1024 | | - // Implementation continues from original file |
| 1630 | +function updateShopDisplay () { |
| 1631 | + let tier1HTML = '' |
| 1632 | + let tier2HTML = '' |
| 1633 | + let tier1Count = 0 |
| 1634 | + |
| 1635 | + // Count tier 1 upgrades |
| 1636 | + for (let key in upgrades) { |
| 1637 | + if (upgrades[key].tier === 1 && upgrades[key].level > 0) { |
| 1638 | + tier1Count++ |
| 1639 | + } |
| 1640 | + } |
| 1641 | + |
| 1642 | + // Display Tier 1 upgrades |
| 1643 | + for (let key in upgrades) { |
| 1644 | + let upgrade = upgrades[key] |
| 1645 | + if (upgrade.tier === 1) { |
| 1646 | + let canAfford = playerPoints >= upgrade.cost |
| 1647 | + let maxed = upgrade.level >= upgrade.maxLevel |
| 1648 | + let buttonText = maxed ? 'MAXED' : `Buy (${upgrade.cost} pts)` |
| 1649 | + let buttonDisabled = maxed || !canAfford ? 'disabled' : '' |
| 1650 | + let opacity = maxed ? '0.5' : '1' |
| 1651 | + |
| 1652 | + tier1HTML += ` |
| 1653 | + <div style="margin: 10px 0; padding: 10px; background: rgba(0,0,0,0.3); |
| 1654 | + border-radius: 10px; opacity: ${opacity};"> |
| 1655 | + <div style="display: flex; justify-content: space-between; align-items: center;"> |
| 1656 | + <div> |
| 1657 | + <span style="font-size: 24px;">${ |
| 1658 | + upgrade.icon |
| 1659 | + }</span> |
| 1660 | + <strong>${upgrade.name}</strong> (${ |
| 1661 | + upgrade.level |
| 1662 | + }/${upgrade.maxLevel}) |
| 1663 | + <br><small>${upgrade.description}</small> |
| 1664 | + </div> |
| 1665 | + <button onclick="buyUpgrade('${key}')" ${buttonDisabled} |
| 1666 | + style="padding: 5px 15px; background: ${ |
| 1667 | + canAfford && !maxed ? '#4CAF50' : '#666' |
| 1668 | + }; |
| 1669 | + color: white; border: none; border-radius: 5px; cursor: ${ |
| 1670 | + canAfford && !maxed |
| 1671 | + ? 'pointer' |
| 1672 | + : 'not-allowed' |
| 1673 | + };"> |
| 1674 | + ${buttonText} |
| 1675 | + </button> |
| 1676 | + </div> |
| 1677 | + </div> |
| 1678 | + ` |
| 1679 | + } |
| 1680 | + } |
| 1681 | + |
| 1682 | + // Display Tier 2 upgrades |
| 1683 | + for (let key in upgrades) { |
| 1684 | + let upgrade = upgrades[key] |
| 1685 | + if (upgrade.tier === 2) { |
| 1686 | + let unlocked = tier1Count >= upgrade.requires |
| 1687 | + let canAfford = playerPoints >= upgrade.cost && unlocked |
| 1688 | + let maxed = upgrade.level >= upgrade.maxLevel |
| 1689 | + let buttonText = maxed |
| 1690 | + ? 'MAXED' |
| 1691 | + : !unlocked |
| 1692 | + ? `Needs ${upgrade.requires} Tier 1` |
| 1693 | + : `Buy (${upgrade.cost} pts)` |
| 1694 | + let buttonDisabled = maxed || !canAfford ? 'disabled' : '' |
| 1695 | + let opacity = !unlocked ? '0.3' : maxed ? '0.5' : '1' |
| 1696 | + |
| 1697 | + tier2HTML += ` |
| 1698 | + <div style="margin: 10px 0; padding: 10px; background: rgba(0,0,0,0.3); |
| 1699 | + border-radius: 10px; opacity: ${opacity};"> |
| 1700 | + <div style="display: flex; justify-content: space-between; align-items: center;"> |
| 1701 | + <div> |
| 1702 | + <span style="font-size: 24px;">${ |
| 1703 | + upgrade.icon |
| 1704 | + }</span> |
| 1705 | + <strong>${upgrade.name}</strong> (${ |
| 1706 | + upgrade.level |
| 1707 | + }/${upgrade.maxLevel}) |
| 1708 | + <br><small>${upgrade.description}</small> |
| 1709 | + </div> |
| 1710 | + <button onclick="buyUpgrade('${key}')" ${buttonDisabled} |
| 1711 | + style="padding: 5px 15px; background: ${ |
| 1712 | + canAfford && !maxed ? '#FF69B4' : '#666' |
| 1713 | + }; |
| 1714 | + color: white; border: none; border-radius: 5px; cursor: ${ |
| 1715 | + canAfford && !maxed |
| 1716 | + ? 'pointer' |
| 1717 | + : 'not-allowed' |
| 1718 | + };"> |
| 1719 | + ${buttonText} |
| 1720 | + </button> |
| 1721 | + </div> |
| 1722 | + </div> |
| 1723 | + ` |
| 1724 | + } |
| 1725 | + } |
| 1726 | + |
| 1727 | + document.getElementById('upgrade-list-tier1').innerHTML = tier1HTML |
| 1728 | + document.getElementById('upgrade-list-tier2').innerHTML = tier2HTML |
| 1729 | + |
| 1730 | + // Update tier 2 section opacity |
| 1731 | + document.getElementById('tier2-upgrades').style.opacity = |
| 1732 | + tier1Count >= 2 ? '1' : '0.5' |
| 1025 | 1733 | } |
| 1026 | 1734 | |
| 1027 | | -function escapeFlies() { |
| 1028 | | - // Implementation continues from original file |
| 1735 | +// Make buyUpgrade global so onclick can access it |
| 1736 | +window.buyUpgrade = function (upgradeKey) { |
| 1737 | + let upgrade = upgrades[upgradeKey] |
| 1738 | + if (!upgrade) return |
| 1739 | + |
| 1740 | + // Check tier requirements |
| 1741 | + if (upgrade.tier === 2) { |
| 1742 | + let tier1Count = 0 |
| 1743 | + for (let key in upgrades) { |
| 1744 | + if (upgrades[key].tier === 1 && upgrades[key].level > 0) { |
| 1745 | + tier1Count++ |
| 1746 | + } |
| 1747 | + } |
| 1748 | + if (tier1Count < upgrade.requires) return |
| 1749 | + } |
| 1750 | + |
| 1751 | + // Check if can afford and not maxed |
| 1752 | + if (playerPoints >= upgrade.cost && upgrade.level < upgrade.maxLevel) { |
| 1753 | + playerPoints -= upgrade.cost |
| 1754 | + upgrade.level++ |
| 1755 | + |
| 1756 | + // Apply upgrade effects immediately |
| 1757 | + applyUpgradeEffects() |
| 1758 | + |
| 1759 | + // Update display |
| 1760 | + document.getElementById('available-points').textContent = playerPoints |
| 1761 | + updateShopDisplay() |
| 1762 | + |
| 1763 | + // Show notification |
| 1764 | + notifications.push( |
| 1765 | + new Notification(`Upgraded ${upgrade.name}!`, color(100, 255, 100)) |
| 1766 | + ) |
| 1767 | + } |
| 1768 | +} |
| 1769 | + |
| 1770 | +function applyUpgradeEffects () { |
| 1771 | + if (!spider) return // Ensure spider exists |
| 1772 | + |
| 1773 | + // Reset to base values |
| 1774 | + spider.jumpPower = 12 |
| 1775 | + maxWebSilk = 100 |
| 1776 | + silkDrainRate = 2 |
| 1777 | + spider.munchCooldownMax = 30 // Add this property to spider |
| 1778 | + |
| 1779 | + // Apply Tier 1 upgrades |
| 1780 | + if (upgrades.strongLegs.level > 0) { |
| 1781 | + spider.jumpPower = 12 * (1 + 0.15 * upgrades.strongLegs.level) |
| 1782 | + } |
| 1783 | + |
| 1784 | + if (upgrades.silkGlands.level > 0) { |
| 1785 | + maxWebSilk = 100 + 20 * upgrades.silkGlands.level |
| 1786 | + webSilk = min(webSilk, maxWebSilk) // Cap current silk to new max |
| 1787 | + } |
| 1788 | + |
| 1789 | + if (upgrades.efficientSpinning.level > 0) { |
| 1790 | + silkDrainRate = 2 * (1 - 0.2 * upgrades.efficientSpinning.level) |
| 1791 | + } |
| 1792 | + |
| 1793 | + if (upgrades.quickMunch.level > 0) { |
| 1794 | + spider.munchCooldownMax = 30 * (1 - 0.3 * upgrades.quickMunch.level) |
| 1795 | + } |
| 1796 | + |
| 1797 | + // Tier 2 upgrades are handled in their respective functions |
| 1798 | +} |
| 1799 | + |
| 1800 | +function spawnNightFlies () { |
| 1801 | + // Base flies + more per night |
| 1802 | + let numFlies = 5 + currentNight |
| 1803 | + |
| 1804 | + // Apply difficulty scaling |
| 1805 | + let flySpeedMultiplier = 1 + Math.floor((currentNight - 1) / 3) * 0.1 // +10% every 3 nights |
| 1806 | + |
| 1807 | + for (let i = 0; i < numFlies; i++) { |
| 1808 | + // PHASE 2: Spawn different fly types with rarity |
| 1809 | + let flyType = 'regular' |
| 1810 | + let roll = random() |
| 1811 | + |
| 1812 | + if (currentNight >= 5 && roll < 0.05) { |
| 1813 | + // Queen flies: 5% chance after night 5 |
| 1814 | + flyType = 'queen' |
| 1815 | + } else if (roll < 0.1) { |
| 1816 | + // Golden flies: 10% chance |
| 1817 | + flyType = 'golden' |
| 1818 | + } else if (roll < 0.25) { |
| 1819 | + // Moths: 15% chance |
| 1820 | + flyType = 'moth' |
| 1821 | + } |
| 1822 | + |
| 1823 | + let fly = new Fly(flyType) |
| 1824 | + fly.baseSpeed = baseFlySpeed * flySpeedMultiplier |
| 1825 | + if (flyType === 'golden') fly.baseSpeed *= 1.3 // Golden are always faster |
| 1826 | + if (flyType === 'moth') fly.baseSpeed *= 0.8 // Moths are slower |
| 1827 | + if (flyType === 'queen') fly.baseSpeed *= 0.5 // Queens are much slower |
| 1828 | + fly.currentSpeed = fly.baseSpeed |
| 1829 | + flies.push(fly) |
| 1830 | + } |
| 1831 | + |
| 1832 | + // PHASE 2: Guarantee at least 1 golden fly per night |
| 1833 | + if (flies.filter(f => f.type === 'golden').length === 0) { |
| 1834 | + let goldenFly = new Fly('golden') |
| 1835 | + goldenFly.baseSpeed = baseFlySpeed * flySpeedMultiplier * 1.3 |
| 1836 | + goldenFly.currentSpeed = goldenFly.baseSpeed |
| 1837 | + flies.push(goldenFly) |
| 1838 | + // Add notification |
| 1839 | + notifications.push( |
| 1840 | + new Notification('Golden Firefly Appeared! ✨', color(255, 215, 0)) |
| 1841 | + ) |
| 1842 | + } |
| 1843 | + |
| 1844 | + // PHASE 2: Guarantee a queen on nights 10+ |
| 1845 | + if ( |
| 1846 | + currentNight >= 10 && |
| 1847 | + flies.filter(f => f.type === 'queen').length === 0 |
| 1848 | + ) { |
| 1849 | + let queenFly = new Fly('queen') |
| 1850 | + queenFly.baseSpeed = baseFlySpeed * flySpeedMultiplier * 0.5 |
| 1851 | + queenFly.currentSpeed = queenFly.baseSpeed |
| 1852 | + flies.push(queenFly) |
| 1853 | + // Add notification |
| 1854 | + notifications.push( |
| 1855 | + new Notification('Queen Firefly Arrived! 👑', color(200, 100, 255)) |
| 1856 | + ) |
| 1857 | + } |
| 1858 | + |
| 1859 | + // Spawn some food boxes |
| 1860 | + for (let i = 0; i < 3; i++) { |
| 1861 | + spawnFoodBox() |
| 1862 | + } |
| 1863 | +} |
| 1864 | + |
| 1865 | +function escapeFlies () { |
| 1866 | + // Store escaping flies (could be used for visual effect later) |
| 1867 | + fliesEscaped = [] |
| 1868 | + |
| 1869 | + for (let fly of flies) { |
| 1870 | + if (!fly.stuck) { |
| 1871 | + fliesEscaped.push({ |
| 1872 | + x: fly.pos.x, |
| 1873 | + y: fly.pos.y, |
| 1874 | + type: fly.type // PHASE 2: Store actual type |
| 1875 | + }) |
| 1876 | + } |
| 1877 | + } |
| 1878 | + |
| 1879 | + // Clear all flies |
| 1880 | + flies = [] |
| 1881 | +} |
| 1882 | + |
| 1883 | +function degradeWebs () { |
| 1884 | + // Degrade each web strand by 10% |
| 1885 | + for (let strand of webStrands) { |
| 1886 | + strand.strength *= 0.9 |
| 1887 | + |
| 1888 | + // Very weak strands break |
| 1889 | + if (strand.strength < 0.3) { |
| 1890 | + strand.broken = true |
| 1891 | + } |
| 1892 | + |
| 1893 | + // Add slight sag to simulate aging |
| 1894 | + if (strand.path && strand.path.length > 2) { |
| 1895 | + for (let i = 1; i < strand.path.length - 1; i++) { |
| 1896 | + strand.path[i].y += random(2, 5) |
| 1897 | + } |
| 1898 | + } |
| 1899 | + } |
| 1900 | + |
| 1901 | + // Create some particles to show degradation |
| 1902 | + for (let i = 0; i < 10; i++) { |
| 1903 | + let p = new Particle(random(width), random(height)) |
| 1904 | + p.color = color(255, 255, 255, 100) |
| 1905 | + p.vel = createVector(0, random(0.5, 2)) |
| 1906 | + p.size = 2 |
| 1907 | + particles.push(p) |
| 1908 | + } |
| 1909 | +} |
| 1910 | + |
| 1911 | +function prepareDusk () { |
| 1912 | + // Return some flies for the next night (visual continuity) |
| 1913 | + let returnCount = min(3, fliesEscaped.length) |
| 1914 | + for (let i = 0; i < returnCount; i++) { |
| 1915 | + // PHASE 2: Recreate the same type of fly that escaped |
| 1916 | + let fly = new Fly(fliesEscaped[i].type) |
| 1917 | + // Start from edge but move toward previous positions |
| 1918 | + fly.wanderAngle = atan2( |
| 1919 | + fliesEscaped[i].y - fly.pos.y, |
| 1920 | + fliesEscaped[i].x - fly.pos.x |
| 1921 | + ) |
| 1922 | + flies.push(fly) |
| 1923 | + } |
| 1029 | 1924 | } |
| 1030 | 1925 | |
| 1031 | | -function degradeWebs() { |
| 1032 | | - // Implementation continues from original file |
| 1926 | +function drawSun () { |
| 1927 | + push() |
| 1928 | + noStroke() |
| 1929 | + |
| 1930 | + // Sun glow |
| 1931 | + fill(255, 230, 100, sunOpacity * 0.3) |
| 1932 | + ellipse(width - 150, sunY, 120) |
| 1933 | + fill(255, 220, 50, sunOpacity * 0.5) |
| 1934 | + ellipse(width - 150, sunY, 80) |
| 1935 | + fill(255, 200, 0, sunOpacity) |
| 1936 | + ellipse(width - 150, sunY, 50) |
| 1937 | + |
| 1938 | + pop() |
| 1939 | +} |
| 1940 | + |
| 1941 | +function propagateVibration (sourceStrand, vibrationAmount) { |
| 1942 | + // FIX: Instead of checking all strand pairs, use a limited propagation |
| 1943 | + // Only check strands that share endpoints (actually connected) |
| 1944 | + |
| 1945 | + let vibratedStrands = new Set() |
| 1946 | + vibratedStrands.add(sourceStrand) |
| 1947 | + |
| 1948 | + // Find directly connected strands only |
| 1949 | + for (let strand of webStrands) { |
| 1950 | + if (strand === sourceStrand || strand.broken) continue |
| 1951 | + |
| 1952 | + // Check if strands share an endpoint (much faster than distance checks) |
| 1953 | + let connected = false |
| 1954 | + |
| 1955 | + // Check if endpoints are very close (essentially the same point) |
| 1956 | + if (sourceStrand.start && strand.start) { |
| 1957 | + if ( |
| 1958 | + dist( |
| 1959 | + sourceStrand.start.x, |
| 1960 | + sourceStrand.start.y, |
| 1961 | + strand.start.x, |
| 1962 | + strand.start.y |
| 1963 | + ) < 5 |
| 1964 | + ) { |
| 1965 | + connected = true |
| 1966 | + } |
| 1967 | + } |
| 1968 | + if (!connected && sourceStrand.start && strand.end) { |
| 1969 | + if ( |
| 1970 | + dist( |
| 1971 | + sourceStrand.start.x, |
| 1972 | + sourceStrand.start.y, |
| 1973 | + strand.end.x, |
| 1974 | + strand.end.y |
| 1975 | + ) < 5 |
| 1976 | + ) { |
| 1977 | + connected = true |
| 1978 | + } |
| 1979 | + } |
| 1980 | + if (!connected && sourceStrand.end && strand.start) { |
| 1981 | + if ( |
| 1982 | + dist( |
| 1983 | + sourceStrand.end.x, |
| 1984 | + sourceStrand.end.y, |
| 1985 | + strand.start.x, |
| 1986 | + strand.start.y |
| 1987 | + ) < 5 |
| 1988 | + ) { |
| 1989 | + connected = true |
| 1990 | + } |
| 1991 | + } |
| 1992 | + if (!connected && sourceStrand.end && strand.end) { |
| 1993 | + if ( |
| 1994 | + dist( |
| 1995 | + sourceStrand.end.x, |
| 1996 | + sourceStrand.end.y, |
| 1997 | + strand.end.x, |
| 1998 | + strand.end.y |
| 1999 | + ) < 5 |
| 2000 | + ) { |
| 2001 | + connected = true |
| 2002 | + } |
| 2003 | + } |
| 2004 | + |
| 2005 | + if (connected) { |
| 2006 | + strand.vibrate(vibrationAmount) |
| 2007 | + vibratedStrands.add(strand) |
| 2008 | + |
| 2009 | + // Stop after vibrating 5 strands to prevent performance issues |
| 2010 | + if (vibratedStrands.size >= 5) break |
| 2011 | + } |
| 2012 | + } |
| 1033 | 2013 | } |
| 1034 | 2014 | |
| 1035 | | -function prepareDusk() { |
| 1036 | | - // Implementation continues from original file |
| 2015 | +// ============================================ |
| 2016 | +// ORIGINAL FUNCTIONS WITH PHASE 1 UPDATES |
| 2017 | +// ============================================ |
| 2018 | + |
| 2019 | +function updateSkyColors () { |
| 2020 | + // PHASE 1 - Complete rewrite for full cycle |
| 2021 | + if (gamePhase === 'DAWN') { |
| 2022 | + // Dawn: dark purple/blue to soft orange/pink |
| 2023 | + currentSkyColor1 = lerpColor( |
| 2024 | + color(70, 70, 120), |
| 2025 | + color(255, 200, 150), |
| 2026 | + phaseTimer / DAWN_DURATION |
| 2027 | + ) |
| 2028 | + currentSkyColor2 = lerpColor( |
| 2029 | + color(30, 30, 60), |
| 2030 | + color(255, 150, 100), |
| 2031 | + phaseTimer / DAWN_DURATION |
| 2032 | + ) |
| 2033 | + moonOpacity = lerp(255, 0, phaseTimer / DAWN_DURATION) |
| 2034 | + moonY = lerp(60, -50, phaseTimer / DAWN_DURATION) |
| 2035 | + sunY = lerp(height + 50, height - 100, phaseTimer / DAWN_DURATION) |
| 2036 | + sunOpacity = lerp(0, 100, phaseTimer / DAWN_DURATION) |
| 2037 | + } else if (gamePhase === 'DAWN_TO_DAY') { |
| 2038 | + let t = phaseTimer / TRANSITION_DURATION |
| 2039 | + currentSkyColor1 = lerpColor(color(255, 200, 150), color(135, 206, 235), t) |
| 2040 | + currentSkyColor2 = lerpColor(color(255, 150, 100), color(255, 255, 200), t) |
| 2041 | + sunY = lerp(height - 100, height * 0.3, t) |
| 2042 | + sunOpacity = lerp(100, 255, t) |
| 2043 | + } else if (gamePhase === 'DAY') { |
| 2044 | + // Day: bright blue sky |
| 2045 | + currentSkyColor1 = color(135, 206, 235) |
| 2046 | + currentSkyColor2 = color(255, 255, 200) |
| 2047 | + sunY = lerp(height * 0.3, 100, phaseTimer / DAY_DURATION) |
| 2048 | + sunOpacity = 255 |
| 2049 | + } else if (gamePhase === 'DAY_TO_DUSK') { |
| 2050 | + let t = phaseTimer / TRANSITION_DURATION |
| 2051 | + currentSkyColor1 = lerpColor(color(135, 206, 235), color(255, 140, 90), t) |
| 2052 | + currentSkyColor2 = lerpColor(color(255, 255, 200), color(255, 183, 77), t) |
| 2053 | + sunY = lerp(100, 60, t) |
| 2054 | + sunOpacity = lerp(255, 150, t) |
| 2055 | + } else if (gamePhase === 'DUSK') { |
| 2056 | + // Dusk: orange/purple sunset |
| 2057 | + currentSkyColor1 = lerpColor( |
| 2058 | + color(255, 140, 90), |
| 2059 | + color(200, 100, 120), |
| 2060 | + phaseTimer / DUSK_DURATION |
| 2061 | + ) |
| 2062 | + currentSkyColor2 = lerpColor( |
| 2063 | + color(255, 183, 77), |
| 2064 | + color(120, 60, 120), |
| 2065 | + phaseTimer / DUSK_DURATION |
| 2066 | + ) |
| 2067 | + sunY = lerp(60, -50, phaseTimer / DUSK_DURATION) |
| 2068 | + sunOpacity = lerp(150, 0, phaseTimer / DUSK_DURATION) |
| 2069 | + } else if (gamePhase === 'DUSK_TO_NIGHT') { |
| 2070 | + let t = phaseTimer / TRANSITION_DURATION |
| 2071 | + currentSkyColor1 = lerpColor(color(200, 100, 120), color(25, 25, 112), t) |
| 2072 | + currentSkyColor2 = lerpColor(color(120, 60, 120), color(0, 0, 40), t) |
| 2073 | + moonOpacity = t * 255 |
| 2074 | + moonY = lerp(100, 60, t) |
| 2075 | + } else if (gamePhase === 'NIGHT') { |
| 2076 | + // Night: dark blue/purple |
| 2077 | + currentSkyColor1 = color(25, 25, 112) |
| 2078 | + currentSkyColor2 = color(0, 0, 40) |
| 2079 | + moonOpacity = 255 |
| 2080 | + moonY = 60 |
| 2081 | + } else if (gamePhase === 'NIGHT_TO_DAWN') { |
| 2082 | + let t = phaseTimer / TRANSITION_DURATION |
| 2083 | + currentSkyColor1 = lerpColor(color(25, 25, 112), color(70, 70, 120), t) |
| 2084 | + currentSkyColor2 = lerpColor(color(0, 0, 40), color(30, 30, 60), t) |
| 2085 | + } |
| 1037 | 2086 | } |
| 1038 | 2087 | |
| 1039 | | -function drawSun() { |
| 1040 | | - // Implementation continues from original file |
| 2088 | +function drawSkyGradient () { |
| 2089 | + for (let i = 0; i <= height; i++) { |
| 2090 | + let inter = map(i, 0, height, 0, 1) |
| 2091 | + let c = lerpColor(currentSkyColor1, currentSkyColor2, inter) |
| 2092 | + stroke(c) |
| 2093 | + line(0, i, width, i) |
| 2094 | + } |
| 2095 | + |
| 2096 | + // Draw home branch |
| 2097 | + if (window.homeBranch) { |
| 2098 | + push() |
| 2099 | + let branch = window.homeBranch |
| 2100 | + |
| 2101 | + // Branch shadow |
| 2102 | + push() |
| 2103 | + translate(0, branch.y + 5) |
| 2104 | + rotate(branch.angle) |
| 2105 | + noStroke() |
| 2106 | + fill(0, 0, 0, 30) |
| 2107 | + |
| 2108 | + // Shadow with taper |
| 2109 | + beginShape() |
| 2110 | + vertex(branch.startX, 10) |
| 2111 | + bezierVertex( |
| 2112 | + branch.startX + (branch.endX - branch.startX) * 0.3, |
| 2113 | + 8, |
| 2114 | + branch.startX + (branch.endX - branch.startX) * 0.7, |
| 2115 | + 5, |
| 2116 | + branch.endX, |
| 2117 | + 3 |
| 2118 | + ) |
| 2119 | + vertex(branch.endX, -3) |
| 2120 | + bezierVertex( |
| 2121 | + branch.startX + (branch.endX - branch.startX) * 0.7, |
| 2122 | + -5, |
| 2123 | + branch.startX + (branch.endX - branch.startX) * 0.3, |
| 2124 | + -8, |
| 2125 | + branch.startX, |
| 2126 | + -10 |
| 2127 | + ) |
| 2128 | + endShape(CLOSE) |
| 2129 | + pop() |
| 2130 | + |
| 2131 | + // Main branch with organic shape and taper |
| 2132 | + push() |
| 2133 | + translate(0, branch.y) |
| 2134 | + rotate(branch.angle) |
| 2135 | + |
| 2136 | + noStroke() |
| 2137 | + |
| 2138 | + // Base color - PHASE 1: Update for all phases |
| 2139 | + if (gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN') { |
| 2140 | + fill(30, 15, 5) |
| 2141 | + } else { |
| 2142 | + fill(92, 51, 23) |
| 2143 | + } |
| 2144 | + |
| 2145 | + // Branch body with taper |
| 2146 | + beginShape() |
| 2147 | + vertex(branch.startX, -branch.thickness) |
| 2148 | + bezierVertex( |
| 2149 | + branch.startX + (branch.endX - branch.startX) * 0.3, |
| 2150 | + -branch.thickness * 0.9, |
| 2151 | + branch.startX + (branch.endX - branch.startX) * 0.7, |
| 2152 | + -branch.thickness * 0.6, |
| 2153 | + branch.endX, |
| 2154 | + -branch.thickness * 0.35 |
| 2155 | + ) |
| 2156 | + vertex(branch.endX, branch.thickness * 0.35) |
| 2157 | + bezierVertex( |
| 2158 | + branch.startX + (branch.endX - branch.startX) * 0.7, |
| 2159 | + branch.thickness * 0.6, |
| 2160 | + branch.startX + (branch.endX - branch.startX) * 0.3, |
| 2161 | + branch.thickness * 0.9, |
| 2162 | + branch.startX, |
| 2163 | + branch.thickness |
| 2164 | + ) |
| 2165 | + endShape(CLOSE) |
| 2166 | + |
| 2167 | + // Add a fork around 70% down the branch |
| 2168 | + push() |
| 2169 | + let forkX = branch.startX + (branch.endX - branch.startX) * 0.7 |
| 2170 | + let forkY = 0 |
| 2171 | + translate(forkX, forkY) |
| 2172 | + rotate(((branch.side === 'right' ? -1 : 1) * PI) / 6) |
| 2173 | + |
| 2174 | + // Fork branch |
| 2175 | + if (gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN') { |
| 2176 | + fill(35, 18, 6) |
| 2177 | + } else { |
| 2178 | + fill(102, 58, 28) |
| 2179 | + } |
| 2180 | + |
| 2181 | + beginShape() |
| 2182 | + vertex(0, -8) |
| 2183 | + bezierVertex(20, -7, 35, -5, 50, -3) |
| 2184 | + vertex(50, 3) |
| 2185 | + bezierVertex(35, 5, 20, 7, 0, 8) |
| 2186 | + endShape(CLOSE) |
| 2187 | + pop() |
| 2188 | + |
| 2189 | + // Add lighter highlights |
| 2190 | + if (gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN') { |
| 2191 | + fill(50, 25, 10, 150) |
| 2192 | + } else { |
| 2193 | + fill(139, 90, 43, 180) |
| 2194 | + } |
| 2195 | + |
| 2196 | + // Highlight on top ridge |
| 2197 | + beginShape() |
| 2198 | + vertex(branch.startX + 20, -branch.thickness * 0.8) |
| 2199 | + bezierVertex( |
| 2200 | + branch.startX + (branch.endX - branch.startX) * 0.4, |
| 2201 | + -branch.thickness * 0.7, |
| 2202 | + branch.startX + (branch.endX - branch.startX) * 0.6, |
| 2203 | + -branch.thickness * 0.5, |
| 2204 | + branch.endX - 20, |
| 2205 | + -branch.thickness * 0.25 |
| 2206 | + ) |
| 2207 | + vertex(branch.endX - 20, -branch.thickness * 0.15) |
| 2208 | + bezierVertex( |
| 2209 | + branch.startX + (branch.endX - branch.startX) * 0.6, |
| 2210 | + -branch.thickness * 0.4, |
| 2211 | + branch.startX + (branch.endX - branch.startX) * 0.4, |
| 2212 | + -branch.thickness * 0.6, |
| 2213 | + branch.startX + 20, |
| 2214 | + -branch.thickness * 0.7 |
| 2215 | + ) |
| 2216 | + endShape(CLOSE) |
| 2217 | + |
| 2218 | + // Bark texture lines |
| 2219 | + stroke(60, 30, 10, 100) |
| 2220 | + strokeWeight(1) |
| 2221 | + for (let texture of branch.barkTextures) { |
| 2222 | + if (texture.x % 20 < 10) { |
| 2223 | + line(texture.x, texture.yOff, texture.x + 3, texture.endYOff) |
| 2224 | + } |
| 2225 | + } |
| 2226 | + |
| 2227 | + // Knots |
| 2228 | + noStroke() |
| 2229 | + if (gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN') { |
| 2230 | + fill(40, 20, 5) |
| 2231 | + } else { |
| 2232 | + fill(80, 40, 15) |
| 2233 | + } |
| 2234 | + ellipse(branch.startX + (branch.endX - branch.startX) * 0.3, -5, 12, 8) |
| 2235 | + ellipse(branch.startX + (branch.endX - branch.startX) * 0.65, 3, 8, 10) |
| 2236 | + |
| 2237 | + pop() |
| 2238 | + |
| 2239 | + // Small twigs - properly attached to the rotated branch |
| 2240 | + stroke( |
| 2241 | + gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN' |
| 2242 | + ? color(40, 20, 0) |
| 2243 | + : color(101, 67, 33) |
| 2244 | + ) |
| 2245 | + |
| 2246 | + // Just add a couple simple twigs for visual interest |
| 2247 | + strokeWeight(3) |
| 2248 | + line( |
| 2249 | + branch.startX + (branch.endX - branch.startX) * 0.3, |
| 2250 | + -5, |
| 2251 | + branch.startX + (branch.endX - branch.startX) * 0.3 - 10, |
| 2252 | + -15 |
| 2253 | + ) |
| 2254 | + line( |
| 2255 | + branch.startX + (branch.endX - branch.startX) * 0.6, |
| 2256 | + 0, |
| 2257 | + branch.startX + (branch.endX - branch.startX) * 0.6 + 8, |
| 2258 | + -12 |
| 2259 | + ) |
| 2260 | + |
| 2261 | + // Add leaves (properly positioned within rotated branch) |
| 2262 | + for (let leaf of branch.leaves) { |
| 2263 | + let leafX = branch.startX + (branch.endX - branch.startX) * leaf.t |
| 2264 | + push() |
| 2265 | + translate(leafX, leaf.yOffset) |
| 2266 | + rotate(leaf.rotation) |
| 2267 | + |
| 2268 | + // Leaf shadow |
| 2269 | + noStroke() |
| 2270 | + fill(0, 0, 0, 20) |
| 2271 | + ellipse(2, 2, leaf.width, leaf.height) |
| 2272 | + |
| 2273 | + // Leaf body |
| 2274 | + if (gamePhase === 'NIGHT' || gamePhase === 'NIGHT_TO_DAWN') { |
| 2275 | + fill(20, 40, 20) |
| 2276 | + } else { |
| 2277 | + fill(34, 139, 34) |
| 2278 | + } |
| 2279 | + ellipse(0, 0, leaf.width, leaf.height) |
| 2280 | + |
| 2281 | + // Leaf vein |
| 2282 | + stroke(25, 100, 25, 100) |
| 2283 | + strokeWeight(0.5) |
| 2284 | + line(-leaf.width / 2 + 2, 0, leaf.width / 2 - 2, 0) |
| 2285 | + pop() |
| 2286 | + } |
| 2287 | + |
| 2288 | + pop() |
| 2289 | + } |
| 1041 | 2290 | } |
| 1042 | 2291 | |
| 1043 | | -function updateSkyColors() { |
| 1044 | | - // Implementation continues from original file |
| 2292 | +function drawMoon () { |
| 2293 | + push() |
| 2294 | + noStroke() |
| 2295 | + |
| 2296 | + // Brighter, farther-reaching moon glow |
| 2297 | + fill(255, 255, 240, moonOpacity) |
| 2298 | + ellipse(width - 100, moonY, 52) |
| 2299 | + |
| 2300 | + // Multi-layer radial glow for reach |
| 2301 | + push() |
| 2302 | + blendMode(ADD) |
| 2303 | + fill(255, 255, 230, moonOpacity * 0.55) |
| 2304 | + ellipse(width - 100, moonY, 90) |
| 2305 | + fill(255, 255, 210, moonOpacity * 0.35) |
| 2306 | + ellipse(width - 100, moonY, 140) |
| 2307 | + fill(220, 230, 255, moonOpacity * 0.22) |
| 2308 | + ellipse(width - 100, moonY, 200) |
| 2309 | + pop() |
| 2310 | + |
| 2311 | + // Moon craters with better contrast |
| 2312 | + fill(240, 240, 210, moonOpacity * 0.7) |
| 2313 | + ellipse(width - 105, moonY - 5, 8) |
| 2314 | + ellipse(width - 95, moonY + 8, 12) |
| 2315 | + ellipse(width - 110, moonY + 10, 6) |
| 2316 | + |
| 2317 | + // Subtle "godrays" emanating from the moon |
| 2318 | + push() |
| 2319 | + blendMode(ADD) |
| 2320 | + let baseA = frameCount * 0.0023 // slow drift |
| 2321 | + let rayCount = 8 |
| 2322 | + for (let i = 0; i < rayCount; i++) { |
| 2323 | + let a = |
| 2324 | + baseA + |
| 2325 | + i * ((Math.PI * 2) / rayCount) + |
| 2326 | + (noise(i * 0.2, frameCount * 0.005) - 0.5) * 0.2 |
| 2327 | + let len = 140 + noise(i * 1.7, frameCount * 0.003) * 120 // 140-260px |
| 2328 | + let w0 = 6 + noise(i * 0.9) * 6 // near width |
| 2329 | + let w1 = 18 + noise(i * 0.7) * 16 // far width |
| 2330 | + let cx = width - 100 |
| 2331 | + let cy = moonY |
| 2332 | + fill(220, 230, 255, moonOpacity * 0.18) |
| 2333 | + noStroke() |
| 2334 | + beginShape() |
| 2335 | + vertex(cx + Math.cos(a + 0.03) * w0, cy + Math.sin(a + 0.03) * w0) |
| 2336 | + vertex(cx + Math.cos(a - 0.03) * w0, cy + Math.sin(a - 0.03) * w0) |
| 2337 | + vertex( |
| 2338 | + cx + Math.cos(a) * len + Math.cos(a + 0.12) * w1, |
| 2339 | + cy + Math.sin(a) * len + Math.sin(a + 0.12) * w1 |
| 2340 | + ) |
| 2341 | + vertex( |
| 2342 | + cx + Math.cos(a) * len + Math.cos(a - 0.12) * w1, |
| 2343 | + cy + Math.sin(a) * len + Math.sin(a - 0.12) * w1 |
| 2344 | + ) |
| 2345 | + endShape(CLOSE) |
| 2346 | + } |
| 2347 | + pop() |
| 2348 | + |
| 2349 | + pop() |
| 1045 | 2350 | } |
| 1046 | 2351 | |
| 1047 | | -function drawSkyGradient() { |
| 1048 | | - // Implementation continues from original file |
| 2352 | +function updateResources () { |
| 2353 | + // PHASE 1 - Apply difficulty scaling to silk regen |
| 2354 | + let silkPenalty = Math.floor((currentNight - 1) / 5) * 0.05 |
| 2355 | + let adjustedRegenRate = silkRechargeRate * (1 - silkPenalty) |
| 2356 | + |
| 2357 | + webSilk = min(webSilk + adjustedRegenRate, maxWebSilk) |
| 2358 | + |
| 2359 | + // Handle silk drain for both keyboard and touch |
| 2360 | + if ( |
| 2361 | + isDeployingWeb && |
| 2362 | + spider.isAirborne && |
| 2363 | + (spacePressed || touchHolding) && |
| 2364 | + webSilk > 0 |
| 2365 | + ) { |
| 2366 | + webSilk = max(0, webSilk - silkDrainRate) |
| 2367 | + if (webSilk <= 0) { |
| 2368 | + isDeployingWeb = false |
| 2369 | + spacePressed = false |
| 2370 | + touchHolding = false |
| 2371 | + if (currentStrand) { |
| 2372 | + webStrands.pop() |
| 2373 | + currentStrand = null |
| 2374 | + } |
| 2375 | + } |
| 2376 | + } |
| 2377 | + |
| 2378 | + if (!spacePressed && !touchHolding && isDeployingWeb) { |
| 2379 | + isDeployingWeb = false |
| 2380 | + } |
| 1049 | 2381 | } |
| 1050 | 2382 | |
| 1051 | | -function drawMoon() { |
| 1052 | | - // Implementation continues from original file |
| 2383 | +function handleWebDeployment () { |
| 2384 | + // Handle keyboard-based web deployment |
| 2385 | + if (spacePressed && spider.isAirborne && !isDeployingWeb && webSilk > 10) { |
| 2386 | + isDeployingWeb = true |
| 2387 | + currentStrand = new WebStrand(spider.lastAnchorPoint.copy(), null) |
| 2388 | + currentStrand.path = [spider.lastAnchorPoint.copy()] |
| 2389 | + webStrands.push(currentStrand) |
| 2390 | + webNodes.push( |
| 2391 | + new WebNode(spider.lastAnchorPoint.x, spider.lastAnchorPoint.y) |
| 2392 | + ) |
| 2393 | + } |
| 2394 | + |
| 2395 | + // Update web for keyboard controls |
| 2396 | + if (currentStrand && isDeployingWeb && spider.isAirborne && spacePressed) { |
| 2397 | + currentStrand.end = spider.pos.copy() |
| 2398 | + if (frameCount % 2 === 0) { |
| 2399 | + currentStrand.path.push(spider.pos.copy()) |
| 2400 | + } |
| 2401 | + } |
| 2402 | + |
| 2403 | + // Touch-based web deployment is handled in touchMoved() |
| 1053 | 2404 | } |
| 1054 | 2405 | |
| 1055 | | -function updateResources() { |
| 1056 | | - // Implementation continues from original file |
| 2406 | +function updateUI () { |
| 2407 | + // Update control instructions based on device |
| 2408 | + let isMobile = |
| 2409 | + /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( |
| 2410 | + navigator.userAgent |
| 2411 | + ) |
| 2412 | + |
| 2413 | + // PHASE 3: Add upgrade-specific controls |
| 2414 | + let controls = [] |
| 2415 | + if (isMobile) { |
| 2416 | + controls.push( |
| 2417 | + 'Tap to jump • Hold mid-air for web • Double-tap spider to munch!' |
| 2418 | + ) |
| 2419 | + } else { |
| 2420 | + controls.push('Click to jump • Space to spin web • Shift to munch!') |
| 2421 | + } |
| 2422 | + |
| 2423 | + // Add upgrade controls |
| 2424 | + if (upgrades.powerJump && upgrades.powerJump.level > 0) { |
| 2425 | + controls.push('Hold click to charge jump!') |
| 2426 | + } |
| 2427 | + if (upgrades.silkRecycle && upgrades.silkRecycle.level > 0) { |
| 2428 | + controls.push('Press R to recycle web!') |
| 2429 | + } |
| 2430 | + |
| 2431 | + document.getElementById('info').innerHTML = |
| 2432 | + controls.join('<br>') + |
| 2433 | + '<br>' + |
| 2434 | + 'Web Strands: <span id="strand-count">0</span><br>' + |
| 2435 | + 'Flies Caught: <span id="flies-caught">0</span> | Munched: <span id="flies-munched">0</span><br>' + |
| 2436 | + 'Total Score: <span id="total-score">0</span>' |
| 2437 | + |
| 2438 | + // PHASE 1 UPDATES |
| 2439 | + document.getElementById('strand-count').textContent = webStrands.filter( |
| 2440 | + s => !s.broken |
| 2441 | + ).length |
| 2442 | + document.getElementById('flies-caught').textContent = fliesCaught |
| 2443 | + document.getElementById('flies-munched').textContent = fliesMunched |
| 2444 | + document.getElementById('total-score').textContent = totalFliesCaught |
| 2445 | + |
| 2446 | + // Update phase display |
| 2447 | + let phaseDisplay = gamePhase |
| 2448 | + if (gamePhase === 'DUSK_TO_NIGHT') phaseDisplay = 'NIGHTFALL' |
| 2449 | + else if (gamePhase === 'NIGHT_TO_DAWN') phaseDisplay = 'DAWN BREAKS' |
| 2450 | + else if (gamePhase === 'DAWN_TO_DAY') phaseDisplay = 'SUNRISE' |
| 2451 | + else if (gamePhase === 'DAY_TO_DUSK') phaseDisplay = 'SUNSET' |
| 2452 | + document.getElementById('phase').textContent = phaseDisplay |
| 2453 | + |
| 2454 | + // Update night counter |
| 2455 | + document.getElementById('night-counter').textContent = `Night ${currentNight}` |
| 2456 | + |
| 2457 | + // Update timer based on phase |
| 2458 | + let timerText = '' |
| 2459 | + let potentialStamina = 30 + fliesMunched * 10 |
| 2460 | + potentialStamina = min(potentialStamina, 200) |
| 2461 | + |
| 2462 | + let staminaColor = '' |
| 2463 | + if (potentialStamina <= 50) { |
| 2464 | + staminaColor = 'style="color: #ff4444;"' |
| 2465 | + } else if (potentialStamina <= 80) { |
| 2466 | + staminaColor = 'style="color: #ffaa44;"' |
| 2467 | + } else { |
| 2468 | + staminaColor = 'style="color: #44ff44;"' |
| 2469 | + } |
| 2470 | + |
| 2471 | + document.getElementById('timer').innerHTML = |
| 2472 | + timerText + |
| 2473 | + `<br><small ${staminaColor}>Dawn Stamina: ${potentialStamina}</small>` |
| 2474 | + |
| 2475 | + if (gamePhase === 'DUSK') { |
| 2476 | + let timeLeft = Math.ceil((DUSK_DURATION - phaseTimer) / 60) |
| 2477 | + timerText = `${timeLeft}s to prepare!` |
| 2478 | + } else if (gamePhase === 'NIGHT') { |
| 2479 | + let timeLeft = Math.ceil((NIGHT_DURATION - phaseTimer) / 60) |
| 2480 | + // PHASE 2: Count different fly types |
| 2481 | + let regularCount = flies.filter(f => f.type === 'regular').length |
| 2482 | + let goldenCount = flies.filter(f => f.type === 'golden').length |
| 2483 | + let mothCount = flies.filter(f => f.type === 'moth').length |
| 2484 | + let queenCount = flies.filter(f => f.type === 'queen').length |
| 2485 | + |
| 2486 | + timerText = `${timeLeft}s • ${flies.length} flies` |
| 2487 | + |
| 2488 | + // Show special fly counts if any |
| 2489 | + if (goldenCount > 0 || mothCount > 0 || queenCount > 0) { |
| 2490 | + let specialCounts = [] |
| 2491 | + if (queenCount > 0) specialCounts.push(`${queenCount}👑`) |
| 2492 | + if (goldenCount > 0) specialCounts.push(`${goldenCount}✨`) |
| 2493 | + if (mothCount > 0) specialCounts.push(`${mothCount}🦋`) |
| 2494 | + timerText += ` (${specialCounts.join(' ')})` |
| 2495 | + } |
| 2496 | + } else if (gamePhase === 'DAWN') { |
| 2497 | + let timeLeft = Math.ceil((DAWN_DURATION - phaseTimer) / 60) |
| 2498 | + // PHASE 4: Show birds and exhaustion status |
| 2499 | + let activeBirds = birds.filter(b => b.attacking).length |
| 2500 | + timerText = `${timeLeft}s • ${birds.length} birds` |
| 2501 | + if (activeBirds > 0) timerText += ` (${activeBirds} attacking!)` |
| 2502 | + if (isExhausted) timerText += ' EXHAUSTED!' |
| 2503 | + if (phaseTimer < 180) { |
| 2504 | + document.getElementById('timer').innerHTML = |
| 2505 | + timerText + |
| 2506 | + `<br><small style="color: #FFD700;">+${staminaBonus} from flies!</small>` |
| 2507 | + } |
| 2508 | + if (jumpStamina <= 20 && frameCount % 30 < 15) { |
| 2509 | + document.getElementById('web-meter-fill').style.opacity = '0.5' |
| 2510 | + } else { |
| 2511 | + document.getElementById('web-meter-fill').style.opacity = '1' |
| 2512 | + } |
| 2513 | + } else if (gamePhase === 'DAY') { |
| 2514 | + timerText = 'Rest & repair' |
| 2515 | + } else if (gamePhase.includes('TO')) { |
| 2516 | + timerText = '...' |
| 2517 | + } |
| 2518 | + document.getElementById('timer').textContent = timerText |
| 2519 | + |
| 2520 | + // Show difficulty indicators |
| 2521 | + if (currentNight > 1) { |
| 2522 | + let speedBonus = Math.floor((currentNight - 1) / 3) * 10 |
| 2523 | + let silkPenalty = Math.floor((currentNight - 1) / 5) * 5 |
| 2524 | + |
| 2525 | + if (speedBonus > 0 || silkPenalty > 0) { |
| 2526 | + let diffText = [] |
| 2527 | + if (speedBonus > 0) diffText.push(`Flies +${speedBonus}% speed`) |
| 2528 | + if (silkPenalty > 0) diffText.push(`Silk -${silkPenalty}% regen`) |
| 2529 | + |
| 2530 | + // Add a small difficulty indicator if needed |
| 2531 | + if (gamePhase === 'DUSK' && phaseTimer < 180) { |
| 2532 | + document.getElementById('timer').textContent += ` (${diffText.join( |
| 2533 | + ', ' |
| 2534 | + )})` |
| 2535 | + } |
| 2536 | + } |
| 2537 | + } |
| 2538 | + |
| 2539 | + // PHASE 4: Update meter based on phase |
| 2540 | + if (gamePhase === 'DAWN') { |
| 2541 | + // Show stamina instead of silk during dawn |
| 2542 | + document.getElementById('web-meter-label').textContent = 'STAMINA' |
| 2543 | + let staminaPercent = (jumpStamina / maxJumpStamina) * 100 |
| 2544 | + document.getElementById('web-meter-fill').style.width = staminaPercent + '%' |
| 2545 | + |
| 2546 | + // Color based on stamina level |
| 2547 | + if (jumpStamina < jumpCost) { |
| 2548 | + // Exhausted - red flash |
| 2549 | + let flash = sin(frameCount * 0.3) * 0.5 + 0.5 |
| 2550 | + document.getElementById( |
| 2551 | + 'web-meter-fill' |
| 2552 | + ).style.background = `linear-gradient(90deg, rgb(255, ${ |
| 2553 | + 50 + flash * 50 |
| 2554 | + }, ${50 + flash * 50}), rgb(200, ${30 + flash * 30}, ${30 + flash * 30}))` |
| 2555 | + } else if (jumpStamina < maxJumpStamina * 0.3) { |
| 2556 | + // Very tired - orange-red |
| 2557 | + document.getElementById('web-meter-fill').style.background = |
| 2558 | + 'linear-gradient(90deg, #FF6B35, #FF4444)' |
| 2559 | + } else if (jumpStamina < maxJumpStamina * 0.5) { |
| 2560 | + // Tired - orange |
| 2561 | + document.getElementById('web-meter-fill').style.background = |
| 2562 | + 'linear-gradient(90deg, #FFA500, #FF8C00)' |
| 2563 | + } else { |
| 2564 | + // Good stamina - yellow-orange |
| 2565 | + document.getElementById('web-meter-fill').style.background = |
| 2566 | + 'linear-gradient(90deg, #FFD700, #FFA500)' |
| 2567 | + } |
| 2568 | + if (jumpStamina <= 0 && !gameOver) { |
| 2569 | + push() |
| 2570 | + fill(255, 0, 0, 50 + sin(frameCount * 0.3) * 50) |
| 2571 | + rect(0, 0, width, height) |
| 2572 | + |
| 2573 | + textAlign(CENTER) |
| 2574 | + textSize(32) |
| 2575 | + fill(255, 50, 50) |
| 2576 | + stroke(0) |
| 2577 | + strokeWeight(3) |
| 2578 | + text('NO STAMINA - AVOID BIRDS!', width / 2, height / 2) |
| 2579 | + pop() |
| 2580 | + } |
| 2581 | + } else { |
| 2582 | + // Normal silk meter |
| 2583 | + document.getElementById('web-meter-label').textContent = 'SILK' |
| 2584 | + let meterPercent = (webSilk / maxWebSilk) * 100 |
| 2585 | + document.getElementById('web-meter-fill').style.width = meterPercent + '%' |
| 2586 | + |
| 2587 | + if (webSilk < 20) { |
| 2588 | + let flash = sin(frameCount * 0.2) * 0.5 + 0.5 |
| 2589 | + document.getElementById( |
| 2590 | + 'web-meter-fill' |
| 2591 | + ).style.background = `linear-gradient(90deg, rgb(255, ${ |
| 2592 | + 100 + flash * 100 |
| 2593 | + }, ${100 + flash * 100}), rgb(255, ${150 + flash * 50}, ${ |
| 2594 | + 150 + flash * 50 |
| 2595 | + }))` |
| 2596 | + } else { |
| 2597 | + document.getElementById('web-meter-fill').style.background = |
| 2598 | + 'linear-gradient(90deg, #87CEEB, #E0F6FF)' |
| 2599 | + } |
| 2600 | + } |
| 1057 | 2601 | } |
| 1058 | 2602 | |
| 1059 | | -function handleWebDeployment() { |
| 1060 | | - // Implementation continues from original file |
| 2603 | +function triggerGameOver (reason) { |
| 2604 | + if (gameOver) return // Already game over |
| 2605 | + |
| 2606 | + gameOver = true |
| 2607 | + gameOverTimer = 0 |
| 2608 | + deathReason = reason |
| 2609 | + finalScore = totalFliesCaught |
| 2610 | + |
| 2611 | + // Save high score |
| 2612 | + let highScore = localStorage.getItem('cobHighScore') || 0 |
| 2613 | + if (finalScore > highScore) { |
| 2614 | + localStorage.setItem('cobHighScore', finalScore) |
| 2615 | + } |
| 2616 | + |
| 2617 | + // Stop game music/sounds if any |
| 2618 | + noLoop() // Pause the game |
| 2619 | + |
| 2620 | + // Show game over screen after a short delay |
| 2621 | + setTimeout(showGameOverScreen, 1000) |
| 1061 | 2622 | } |
| 1062 | 2623 | |
| 1063 | | -function updateUI() { |
| 1064 | | - // Implementation continues from original file |
| 2624 | +// Add game over screen function: |
| 2625 | +function showGameOverScreen () { |
| 2626 | + // Create game over overlay |
| 2627 | + let gameOverHTML = ` |
| 2628 | + <div id="game-over-screen" style=" |
| 2629 | + position: fixed; |
| 2630 | + top: 0; |
| 2631 | + left: 0; |
| 2632 | + width: 100%; |
| 2633 | + height: 100%; |
| 2634 | + background: rgba(0, 0, 0, 0.9); |
| 2635 | + display: flex; |
| 2636 | + flex-direction: column; |
| 2637 | + justify-content: center; |
| 2638 | + align-items: center; |
| 2639 | + z-index: 1000; |
| 2640 | + color: white; |
| 2641 | + font-family: Arial, sans-serif; |
| 2642 | + "> |
| 2643 | + <h1 style="color: #ff4444; font-size: 48px; margin-bottom: 20px;">GAME OVER</h1> |
| 2644 | + <p style="font-size: 24px; color: #ffaaaa; margin-bottom: 30px;">${deathReason}</p> |
| 2645 | + |
| 2646 | + <div style="background: rgba(255,255,255,0.1); padding: 20px; border-radius: 10px; margin-bottom: 30px;"> |
| 2647 | + <h2 style="color: #FFD700; margin-bottom: 15px;">Final Stats</h2> |
| 2648 | + <p style="font-size: 20px;">Nights Survived: ${nightsSurvived}</p> |
| 2649 | + <p style="font-size: 20px;">Total Flies Caught: ${finalScore}</p> |
| 2650 | + <p style="font-size: 20px;">High Score: ${ |
| 2651 | + localStorage.getItem('cobHighScore') || 0 |
| 2652 | + }</p> |
| 2653 | + </div> |
| 2654 | + |
| 2655 | + <button onclick="restartGame()" style=" |
| 2656 | + padding: 15px 40px; |
| 2657 | + font-size: 24px; |
| 2658 | + background: #4CAF50; |
| 2659 | + color: white; |
| 2660 | + border: none; |
| 2661 | + border-radius: 10px; |
| 2662 | + cursor: pointer; |
| 2663 | + transition: all 0.3s; |
| 2664 | + " onmouseover="this.style.background='#5CBF60'" onmouseout="this.style.background='#4CAF50'"> |
| 2665 | + Try Again |
| 2666 | + </button> |
| 2667 | + </div> |
| 2668 | + ` |
| 2669 | + |
| 2670 | + document.body.insertAdjacentHTML('beforeend', gameOverHTML) |
| 1065 | 2671 | } |
| 1066 | 2672 | |
| 1067 | | -function recycleNearbyWeb() { |
| 1068 | | - // Implementation continues from original file |
| 2673 | +// Add restart game function: |
| 2674 | +window.restartGame = function () { |
| 2675 | + // Remove game over screen |
| 2676 | + let gameOverScreen = document.getElementById('game-over-screen') |
| 2677 | + if (gameOverScreen) { |
| 2678 | + gameOverScreen.remove() |
| 2679 | + } |
| 2680 | + |
| 2681 | + // Reset game state |
| 2682 | + gameOver = false |
| 2683 | + gameOverTimer = 0 |
| 2684 | + deathReason = '' |
| 2685 | + |
| 2686 | + // Reset to initial values |
| 2687 | + gamePhase = 'DUSK' |
| 2688 | + phaseTimer = 0 |
| 2689 | + nightsSurvived = 0 |
| 2690 | + currentNight = 1 |
| 2691 | + fliesCaught = 0 |
| 2692 | + fliesMunched = 0 |
| 2693 | + totalFliesCaught = 0 |
| 2694 | + jumpStamina = 100 |
| 2695 | + maxJumpStamina = 100 |
| 2696 | + webSilk = 100 |
| 2697 | + |
| 2698 | + // Clear entities |
| 2699 | + flies = [] |
| 2700 | + birds = [] |
| 2701 | + webStrands = [] |
| 2702 | + particles = [] |
| 2703 | + notifications = [] |
| 2704 | + |
| 2705 | + // Restart the game loop |
| 2706 | + loop() |
| 2707 | + |
| 2708 | + // Respawn spider at home |
| 2709 | + if (window.homeBranch) { |
| 2710 | + let spiderStartX = window.homeBranch.endX |
| 2711 | + let branchSurfaceY = |
| 2712 | + window.homeBranch.y - window.homeBranch.thickness * 0.35 |
| 2713 | + spider.pos.x = spiderStartX |
| 2714 | + spider.pos.y = branchSurfaceY - 8 |
| 2715 | + spider.vel.mult(0) |
| 2716 | + spider.isAirborne = false |
| 2717 | + } |
| 1069 | 2718 | } |
| 1070 | 2719 | |
| 1071 | 2720 | // Input handlers |
| 1072 | | -let touchStartTime = 0; |
| 1073 | | -let lastTapTime = 0; |
| 1074 | | -let touchHolding = false; |
| 1075 | | -let touchStartX = 0; |
| 1076 | | -let touchStartY = 0; |
| 1077 | | - |
| 1078 | | -function keyPressed() { |
| 1079 | | - // Implementation continues from original file |
| 1080 | | -} |
| 2721 | +let touchStartTime = 0 |
| 2722 | +let lastTapTime = 0 |
| 2723 | +let touchHolding = false |
| 2724 | +let touchStartX = 0 |
| 2725 | +let touchStartY = 0 |
| 1081 | 2726 | |
| 1082 | | -function keyReleased() { |
| 1083 | | - // Implementation continues from original file |
| 2727 | +function keyPressed () { |
| 2728 | + if (key === ' ') { |
| 2729 | + spacePressed = true |
| 2730 | + return false |
| 2731 | + } |
| 2732 | + if (keyCode === SHIFT) { |
| 2733 | + spider.munch() |
| 2734 | + return false |
| 2735 | + } |
| 2736 | + // PHASE 3: Silk Recycle with R key |
| 2737 | + if (key === 'r' || key === 'R') { |
| 2738 | + if (upgrades.silkRecycle && upgrades.silkRecycle.level > 0) { |
| 2739 | + recycleNearbyWeb() |
| 2740 | + } |
| 2741 | + return false |
| 2742 | + } |
| 2743 | + // PHASE 5: Stats panel with S key |
| 2744 | + if (key === 's' || key === 'S') { |
| 2745 | + if (gamePhase === 'DAY' || gamePhase === 'DUSK') { |
| 2746 | + openStatsPanel() |
| 2747 | + } |
| 2748 | + return false |
| 2749 | + } |
| 1084 | 2750 | } |
| 1085 | 2751 | |
| 1086 | | -function mousePressed() { |
| 1087 | | - // Implementation continues from original file |
| 2752 | +function keyReleased () { |
| 2753 | + if (key === ' ') { |
| 2754 | + spacePressed = false |
| 2755 | + isDeployingWeb = false |
| 2756 | + return false |
| 2757 | + } |
| 1088 | 2758 | } |
| 1089 | 2759 | |
| 1090 | | -function mouseReleased() { |
| 1091 | | - // Implementation continues from original file |
| 2760 | +function mousePressed () { |
| 2761 | + // Only handle mouse on desktop (not touch devices) |
| 2762 | + if (touches.length === 0) { |
| 2763 | + if (!spider.isAirborne) { |
| 2764 | + // PHASE 3: Power Jump - start charging if upgrade unlocked |
| 2765 | + if (upgrades.powerJump && upgrades.powerJump.level > 0) { |
| 2766 | + chargingJump = true |
| 2767 | + jumpChargeTime = 0 |
| 2768 | + } else { |
| 2769 | + spider.jump(mouseX, mouseY) |
| 2770 | + } |
| 2771 | + } |
| 2772 | + } |
| 1092 | 2773 | } |
| 1093 | 2774 | |
| 1094 | | -function touchStarted() { |
| 1095 | | - // Implementation continues from original file |
| 2775 | +function mouseReleased () { |
| 2776 | + // PHASE 3: Power Jump - release charged jump |
| 2777 | + if (chargingJump && !spider.isAirborne) { |
| 2778 | + let chargeRatio = min(jumpChargeTime / maxJumpCharge, 1) |
| 2779 | + let chargeMultiplier = 1 + chargeRatio // 1x to 2x multiplier |
| 2780 | + spider.jumpChargeVisual = 0 |
| 2781 | + spider.jump(mouseX, mouseY, chargeMultiplier) |
| 2782 | + |
| 2783 | + // Create charge release particles |
| 2784 | + if (chargeRatio > 0.5) { |
| 2785 | + for (let i = 0; i < 10; i++) { |
| 2786 | + let p = new Particle(spider.pos.x, spider.pos.y) |
| 2787 | + p.color = color(255, 255, 100) |
| 2788 | + p.vel = createVector(random(-3, 3), random(-1, 2)) |
| 2789 | + p.size = 5 |
| 2790 | + particles.push(p) |
| 2791 | + } |
| 2792 | + } |
| 2793 | + } |
| 2794 | + chargingJump = false |
| 2795 | + jumpChargeTime = 0 |
| 1096 | 2796 | } |
| 1097 | 2797 | |
| 1098 | | -function touchMoved() { |
| 1099 | | - // Implementation continues from original file |
| 2798 | +// PHASE 3: Silk Recycle function |
| 2799 | +function recycleNearbyWeb () { |
| 2800 | + let recycled = false |
| 2801 | + |
| 2802 | + for (let i = webStrands.length - 1; i >= 0; i--) { |
| 2803 | + let strand = webStrands[i] |
| 2804 | + if (strand.broken) continue |
| 2805 | + |
| 2806 | + // Check if spider is near any part of the strand |
| 2807 | + let nearStrand = false |
| 2808 | + if (strand.path && strand.path.length > 0) { |
| 2809 | + for (let point of strand.path) { |
| 2810 | + if (dist(spider.pos.x, spider.pos.y, point.x, point.y) < 50) { |
| 2811 | + nearStrand = true |
| 2812 | + break |
| 2813 | + } |
| 2814 | + } |
| 2815 | + } |
| 2816 | + |
| 2817 | + if (nearStrand) { |
| 2818 | + // Recycle the strand |
| 2819 | + webSilk = min(webSilk + 10, maxWebSilk) // Recover 50% of typical strand cost |
| 2820 | + |
| 2821 | + // Create recycling particles |
| 2822 | + for (let j = 0; j < strand.path.length; j += 3) { |
| 2823 | + let point = strand.path[j] |
| 2824 | + let p = new Particle(point.x, point.y) |
| 2825 | + p.color = color(150, 255, 150) |
| 2826 | + p.vel = createVector( |
| 2827 | + (spider.pos.x - point.x) * 0.02, |
| 2828 | + (spider.pos.y - point.y) * 0.02 |
| 2829 | + ) |
| 2830 | + p.size = 3 |
| 2831 | + particles.push(p) |
| 2832 | + } |
| 2833 | + |
| 2834 | + // Remove the strand |
| 2835 | + webStrands.splice(i, 1) |
| 2836 | + recycled = true |
| 2837 | + |
| 2838 | + // Show notification |
| 2839 | + notifications.push( |
| 2840 | + new Notification('Web Recycled +10 Silk', color(150, 255, 150)) |
| 2841 | + ) |
| 2842 | + break // Only recycle one strand at a time |
| 2843 | + } |
| 2844 | + } |
| 2845 | + |
| 2846 | + if (!recycled) { |
| 2847 | + notifications.push( |
| 2848 | + new Notification('No web nearby to recycle', color(255, 100, 100)) |
| 2849 | + ) |
| 2850 | + } |
| 1100 | 2851 | } |
| 1101 | 2852 | |
| 1102 | | -function touchEnded() { |
| 1103 | | - // Implementation continues from original file |
| 2853 | +function touchStarted () { |
| 2854 | + if (touches.length > 0) { |
| 2855 | + touchStartTime = millis() |
| 2856 | + touchStartX = touches[0].x |
| 2857 | + touchStartY = touches[0].y |
| 2858 | + |
| 2859 | + // Check for double tap on spider to munch |
| 2860 | + let touchOnSpider = |
| 2861 | + dist(touches[0].x, touches[0].y, spider.pos.x, spider.pos.y) < 30 |
| 2862 | + |
| 2863 | + if (touchOnSpider && millis() - lastTapTime < 300) { |
| 2864 | + // Double tap detected on spider - MUNCH! |
| 2865 | + spider.munch() |
| 2866 | + lastTapTime = 0 // Reset to prevent triple tap |
| 2867 | + } else if (!spider.isAirborne) { |
| 2868 | + // Single tap while on ground - jump |
| 2869 | + spider.jump(touches[0].x, touches[0].y) |
| 2870 | + lastTapTime = millis() |
| 2871 | + } else if (spider.isAirborne && webSilk > 10 && !isDeployingWeb) { |
| 2872 | + // Start web deployment if airborne (only if not already deploying) |
| 2873 | + touchHolding = true |
| 2874 | + isDeployingWeb = true |
| 2875 | + currentStrand = new WebStrand(spider.lastAnchorPoint.copy(), null) |
| 2876 | + currentStrand.path = [spider.lastAnchorPoint.copy()] |
| 2877 | + webStrands.push(currentStrand) |
| 2878 | + webNodes.push( |
| 2879 | + new WebNode(spider.lastAnchorPoint.x, spider.lastAnchorPoint.y) |
| 2880 | + ) |
| 2881 | + } else if (spider.isAirborne && isDeployingWeb) { |
| 2882 | + // If already deploying and user taps again, just continue (don't create new strand) |
| 2883 | + touchHolding = true |
| 2884 | + } |
| 2885 | + } |
| 2886 | + return false // Prevent default |
| 1104 | 2887 | } |
| 1105 | 2888 | |
| 1106 | | -function windowResized() { |
| 1107 | | - resizeCanvas(window.innerWidth, window.innerHeight); |
| 2889 | +function touchMoved () { |
| 2890 | + // Update web deployment target while holding |
| 2891 | + if ( |
| 2892 | + touchHolding && |
| 2893 | + spider.isAirborne && |
| 2894 | + isDeployingWeb && |
| 2895 | + currentStrand && |
| 2896 | + webSilk > 0 |
| 2897 | + ) { |
| 2898 | + // Web follows spider while deploying (not finger position) |
| 2899 | + currentStrand.end = spider.pos.copy() |
| 2900 | + if (frameCount % 2 === 0) { |
| 2901 | + currentStrand.path.push(spider.pos.copy()) |
| 2902 | + } |
| 2903 | + } |
| 2904 | + return false // Prevent default |
| 1108 | 2905 | } |
| 1109 | 2906 | |
| 1110 | | -// Make functions globally accessible |
| 1111 | | -window.selectSkin = function(skinId) { |
| 1112 | | - // Implementation continues from original file |
| 2907 | +function touchEnded () { |
| 2908 | + touchHolding = false |
| 2909 | + |
| 2910 | + // Stop web deployment when releasing touch |
| 2911 | + if (isDeployingWeb && spider.isAirborne) { |
| 2912 | + isDeployingWeb = false |
| 2913 | + } |
| 2914 | + |
| 2915 | + return false // Prevent default |
| 1113 | 2916 | } |
| 1114 | 2917 | |
| 1115 | | -window.buyUpgrade = function(upgradeKey) { |
| 1116 | | - // Implementation continues from original file |
| 1117 | | -} |
| 2918 | +function windowResized () { |
| 2919 | + resizeCanvas(window.innerWidth, window.innerHeight) |
| 2920 | +} |