-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpowerups.js
More file actions
566 lines (483 loc) · 19.9 KB
/
powerups.js
File metadata and controls
566 lines (483 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
import * as THREE from 'three';
import { LANES, COLORS, POWER_UP_DURATIONS, PHYSICS } from './constants.js';
export class PowerUpManager {
constructor(scene, player) {
this.scene = scene;
this.player = player;
this.collectableManager = null; // Will be set by game.js
this.obstacleManager = null; // Will be set by game.js
// Power-up states
this.isInvincible = false;
this.invincibilityTimer = 0;
this.isFlying = false;
this.flyingTimer = 0;
this.hasSolarBoost = false;
this.solarBoostTimer = 0;
this.hasWindPower = false;
this.windPowerTimer = 0;
this.hasWaterSlide = false;
this.waterSlideTimer = 0;
this.waterSlideObjects = [];
this.gameSpeed = null; // Will be set by reference
this.pushedObstacles = []; // Track obstacles being pushed by flood
}
setGameSpeedReference(gameSpeedRef) {
this.gameSpeed = gameSpeedRef;
}
setCollectableManager(collectableManager) {
this.collectableManager = collectableManager;
}
setObstacleManager(obstacleManager) {
this.obstacleManager = obstacleManager;
}
activateInvincibility(duration = POWER_UP_DURATIONS.INVINCIBILITY) {
this.isInvincible = true;
this.invincibilityTimer = duration;
this.player.setColor(COLORS.PLAYER.INVINCIBLE);
// Hard Hat Shield activated
}
deactivateInvincibility() {
this.isInvincible = false;
this.updatePlayerColor();
// Hard Hat Shield deactivated
}
activateHelicopter(duration = POWER_UP_DURATIONS.HELICOPTER) {
// Activating Jetpack with specified duration
this.isFlying = true;
this.flyingTimer = duration;
this.player.setPosition(
this.player.getPosition().x,
PHYSICS.FLYING_HEIGHT,
this.player.getPosition().z
);
this.player.setColor(COLORS.PLAYER.FLYING);
// Jetpack activated
}
deactivateHelicopter() {
this.isFlying = false;
// Remove all aerial stars when helicopter ends
if (this.collectableManager) {
this.collectableManager.removeAerialStars();
}
// Initiate controlled fall
this.player.isJumping = true;
this.player.velocityY = 0;
this.updatePlayerColor();
// Jetpack deactivated
}
activateSolarPower(duration = POWER_UP_DURATIONS.SOLAR_BOOST) {
this.hasSolarBoost = true;
this.solarBoostTimer = duration;
if (this.gameSpeed) {
this.gameSpeed.value *= 1.5;
}
this.player.setColor(COLORS.PLAYER.SOLAR_BOOST);
// Solar Power Boost activated
}
deactivateSolarPower() {
this.hasSolarBoost = false;
// Remove all solar orbs when solar boost ends
if (this.collectableManager) {
this.collectableManager.removeSolarOrbs();
}
if (this.gameSpeed) {
this.gameSpeed.value /= 1.5;
}
this.updatePlayerColor();
// Solar Power Boost deactivated
}
activateWindPower(duration = POWER_UP_DURATIONS.WIND_POWER) {
this.hasWindPower = true;
this.windPowerTimer = duration;
this.player.setDoubleJumpAbility(true);
this.player.setColor(COLORS.PLAYER.WIND_POWER);
// Wind Power activated
}
deactivateWindPower() {
this.hasWindPower = false;
this.player.setDoubleJumpAbility(false);
this.updatePlayerColor();
// Wind Power deactivated
}
activateWaterSlide(duration = POWER_UP_DURATIONS.WATER_SLIDE) {
// Activating fire-hydrant with specified duration
this.hasWaterSlide = true;
this.waterSlideTimer = duration;
this.createWaterSlidePath();
this.player.setColor(COLORS.PLAYER.WATER_SLIDE);
// Fire-hydrant activated
}
deactivateWaterSlide() {
this.hasWaterSlide = false;
this.removeWaterSlidePath();
this.updatePlayerColor();
// Fire-hydrant deactivated
}
createWaterSlidePath() {
this.removeWaterSlidePath();
if (!this.obstacleManager) {
// ObstacleManager not available for water pipe targeting
return;
}
// Create continuous water stream effect across all lanes
const playerPos = this.player.getPosition();
const streamLength = 50; // Number of segments per lane
const streamGeometry = new THREE.BoxGeometry(0.8, 0.2, 2);
const streamMaterial = new THREE.MeshStandardMaterial({
color: 0x00aaff,
transparent: true,
opacity: 0.7,
emissive: 0x0066cc,
emissiveIntensity: 0.3
});
// Create water stream segments across all lanes for continuous clearing
for (let lane = 0; lane < LANES.COUNT; lane++) {
for (let i = 0; i < streamLength; i++) {
const streamSegment = new THREE.Mesh(streamGeometry, streamMaterial);
streamSegment.position.set(
LANES.POSITIONS[lane],
0.1,
playerPos.z - 10 - (i * 2) // 2 unit spacing between segments
);
streamSegment.lane = lane;
streamSegment.segmentIndex = i;
this.scene.add(streamSegment);
this.waterSlideObjects.push(streamSegment);
}
}
// Water pipe streams created for continuous obstacle clearing
}
removeWaterSlidePath() {
for (const obj of this.waterSlideObjects) {
this.scene.remove(obj);
}
this.waterSlideObjects = [];
}
updatePlayerColor() {
// Set color based on active power-ups (priority order)
if (this.isInvincible) {
this.player.setColor(COLORS.PLAYER.INVINCIBLE);
} else if (this.isFlying) {
this.player.setColor(COLORS.PLAYER.FLYING);
} else if (this.hasSolarBoost) {
this.player.setColor(COLORS.PLAYER.SOLAR_BOOST);
} else if (this.hasWindPower) {
this.player.setColor(COLORS.PLAYER.WIND_POWER);
} else if (this.hasWaterSlide) {
this.player.setColor(COLORS.PLAYER.WATER_SLIDE);
} else {
this.player.resetToNormalColor();
}
}
updateTimers(deltaTime) {
// Update invincibility
if (this.isInvincible) {
this.invincibilityTimer -= deltaTime;
if (this.invincibilityTimer <= 0) {
this.deactivateInvincibility();
}
}
// Update helicopter
if (this.isFlying) {
this.flyingTimer -= deltaTime;
if (this.flyingTimer <= 0) {
this.deactivateHelicopter();
}
}
// Update solar boost
if (this.hasSolarBoost) {
this.solarBoostTimer -= deltaTime;
if (this.solarBoostTimer <= 0) {
this.deactivateSolarPower();
}
}
// Update wind power
if (this.hasWindPower) {
this.windPowerTimer -= deltaTime;
if (this.windPowerTimer <= 0) {
this.deactivateWindPower();
}
}
// Update water slide
if (this.hasWaterSlide) {
this.waterSlideTimer -= deltaTime;
if (this.waterSlideTimer <= 0) {
this.deactivateWaterSlide();
}
}
}
updateWaterSlidePosition(gameSpeed) {
if (this.hasWaterSlide) {
// Keep water streams positioned relative to player, not moving with game speed
const playerPos = this.player.getPosition();
// Update water stream positions to stay ahead of player
let streamIndex = 0;
for (let lane = 0; lane < LANES.COUNT; lane++) {
for (let i = 0; i < 50; i++) { // 50 segments per lane
if (streamIndex < this.waterSlideObjects.length) {
const streamSegment = this.waterSlideObjects[streamIndex];
// Keep streams positioned ahead of player
streamSegment.position.z = playerPos.z - 10 - (i * 2);
streamIndex++;
}
}
}
// Continuously check for and clear obstacles
this.clearObstaclesInWaterPath();
}
}
clearObstaclesInWaterPath() {
if (!this.obstacleManager) return;
const obstacles = this.obstacleManager.getObstacles();
const playerPos = this.player.getPosition();
// Check all obstacles within the water stream range
for (let i = obstacles.length - 1; i >= 0; i--) {
const obstacle = obstacles[i];
const obstaclePos = obstacle.mesh.position;
// Check if obstacle is within the water stream area (ahead of player)
const isInRange = obstaclePos.z < playerPos.z + 5 && obstaclePos.z > playerPos.z - 150;
if (isInRange && !obstacle.beingPushed) {
// Mark obstacle as being pushed and start animation
obstacle.beingPushed = true;
obstacle.originalX = obstaclePos.x;
obstacle.pushStartTime = Date.now();
obstacle.pushDirection = Math.random() > 0.5 ? 1 : -1; // Randomly push left or right
// Create water splash effect when flood hits obstacle
this.createFloodHitEffect(obstaclePos);
// Add to pushed obstacles list for animation
this.pushedObstacles.push(obstacle);
// Obstacle being swept away by flood
}
}
// Update pushed obstacles animation
this.updatePushedObstacles();
}
updatePushedObstacles() {
const obstacles = this.obstacleManager.getObstacles();
for (let i = this.pushedObstacles.length - 1; i >= 0; i--) {
const obstacle = this.pushedObstacles[i];
const currentTime = Date.now();
const pushDuration = currentTime - obstacle.pushStartTime;
const maxPushDuration = 2000; // 2 seconds to push obstacle off screen
if (pushDuration < maxPushDuration) {
// Calculate push progress (0 to 1)
const progress = pushDuration / maxPushDuration;
const easeProgress = 1 - Math.pow(1 - progress, 3); // Ease-out cubic for realistic physics
// Push obstacle horizontally off the track
const pushDistance = 15; // Total distance to push
const newX = obstacle.originalX + (obstacle.pushDirection * pushDistance * easeProgress);
obstacle.mesh.position.x = newX;
// Add slight rotation for realism
obstacle.mesh.rotation.y = obstacle.pushDirection * easeProgress * Math.PI * 0.3;
obstacle.mesh.rotation.z = obstacle.pushDirection * easeProgress * Math.PI * 0.1;
// Scale down slightly as it gets pushed away
const scale = 1 - (easeProgress * 0.2);
obstacle.mesh.scale.setScalar(scale);
} else {
// Animation complete - remove obstacle
this.scene.remove(obstacle.mesh);
// Remove from obstacles array
const obstacleIndex = obstacles.findIndex(obs => obs === obstacle);
if (obstacleIndex !== -1) {
obstacles.splice(obstacleIndex, 1);
}
// Remove from pushed obstacles
this.pushedObstacles.splice(i, 1);
// Obstacle completely swept away by flood
}
}
}
createWaterSplashEffect(position) {
// Create multiple dramatic water splash effects
const effects = [];
// Main large splash
const mainSplashGeometry = new THREE.SphereGeometry(1.5, 16, 12);
const mainSplashMaterial = new THREE.MeshStandardMaterial({
color: 0x00ccff,
transparent: true,
opacity: 0.9,
emissive: 0x0099cc,
emissiveIntensity: 0.5
});
const mainSplash = new THREE.Mesh(mainSplashGeometry, mainSplashMaterial);
mainSplash.position.copy(position);
mainSplash.position.y += 1;
this.scene.add(mainSplash);
effects.push(mainSplash);
// Create particle-like smaller splashes around the main one
for (let i = 0; i < 8; i++) {
const particleSplashGeometry = new THREE.SphereGeometry(0.3, 8, 6);
const particleSplashMaterial = new THREE.MeshStandardMaterial({
color: 0x66ddff,
transparent: true,
opacity: 0.8,
emissive: 0x0066cc,
emissiveIntensity: 0.4
});
const particleSplash = new THREE.Mesh(particleSplashGeometry, particleSplashMaterial);
particleSplash.position.copy(position);
particleSplash.position.x += (Math.random() - 0.5) * 3;
particleSplash.position.y += Math.random() * 2 + 0.5;
particleSplash.position.z += (Math.random() - 0.5) * 3;
this.scene.add(particleSplash);
effects.push(particleSplash);
}
// Create water burst ring effect
const ringGeometry = new THREE.RingGeometry(0.5, 2, 16);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x00aaff,
transparent: true,
opacity: 0.7,
emissive: 0x0088cc,
emissiveIntensity: 0.3,
side: THREE.DoubleSide
});
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
ring.position.copy(position);
ring.position.y += 0.1;
ring.rotation.x = -Math.PI / 2;
this.scene.add(ring);
effects.push(ring);
// Animate all effects with dramatic scaling and fading
let splashTime = 0;
const animateSplash = () => {
splashTime += 0.08;
// Animate main splash - expand and fade
mainSplash.scale.setScalar(1 + splashTime * 2);
mainSplash.material.opacity = Math.max(0, 0.9 - splashTime);
// Animate particle splashes - random movement and scaling
for (let i = 1; i < effects.length - 1; i++) {
const particle = effects[i];
particle.scale.setScalar(1 + splashTime * 1.5);
particle.material.opacity = Math.max(0, 0.8 - splashTime);
particle.position.y += 0.1; // Rise up
}
// Animate ring - expand outward
const ring = effects[effects.length - 1];
ring.scale.setScalar(1 + splashTime * 3);
ring.material.opacity = Math.max(0, 0.7 - splashTime);
if (splashTime < 1.2) {
requestAnimationFrame(animateSplash);
} else {
// Remove all effects after animation
effects.forEach(effect => this.scene.remove(effect));
}
};
animateSplash();
}
createFloodHitEffect(position) {
// Create initial impact splash when flood hits obstacle
const impactSplashGeometry = new THREE.SphereGeometry(0.8, 12, 8);
const impactSplashMaterial = new THREE.MeshStandardMaterial({
color: 0x0099ff,
transparent: true,
opacity: 0.9,
emissive: 0x0066cc,
emissiveIntensity: 0.6
});
const impactSplash = new THREE.Mesh(impactSplashGeometry, impactSplashMaterial);
impactSplash.position.copy(position);
impactSplash.position.y += 0.5;
this.scene.add(impactSplash);
// Create water spray particles
const sprayParticles = [];
for (let i = 0; i < 12; i++) {
const sprayGeometry = new THREE.SphereGeometry(0.15, 6, 4);
const sprayMaterial = new THREE.MeshStandardMaterial({
color: 0x66ccff,
transparent: true,
opacity: 0.8,
emissive: 0x0044aa,
emissiveIntensity: 0.4
});
const spray = new THREE.Mesh(sprayGeometry, sprayMaterial);
spray.position.copy(position);
spray.position.y += 0.3;
// Random spray direction (outward from impact point)
const angle = (i / 12) * Math.PI * 2;
spray.velocity = {
x: Math.cos(angle) * (2 + Math.random()),
y: 1 + Math.random() * 2,
z: Math.sin(angle) * (2 + Math.random())
};
this.scene.add(spray);
sprayParticles.push(spray);
}
// Animate flood impact effect
let effectTime = 0;
const animateFloodEffect = () => {
effectTime += 0.06;
// Animate main impact splash
impactSplash.scale.setScalar(1 + effectTime * 2);
impactSplash.material.opacity = Math.max(0, 0.9 - effectTime);
// Animate spray particles
sprayParticles.forEach(spray => {
spray.position.x += spray.velocity.x * 0.1;
spray.position.y += spray.velocity.y * 0.1;
spray.position.z += spray.velocity.z * 0.1;
// Apply gravity
spray.velocity.y -= 0.15;
// Fade out
spray.material.opacity = Math.max(0, 0.8 - effectTime);
spray.scale.setScalar(Math.max(0.1, 1 - effectTime * 0.5));
});
if (effectTime < 1.5) {
requestAnimationFrame(animateFloodEffect);
} else {
// Clean up effects
this.scene.remove(impactSplash);
sprayParticles.forEach(spray => this.scene.remove(spray));
}
};
animateFloodEffect();
}
// Getters for game logic
getInvincibilityStatus() {
return this.isInvincible;
}
getFlyingStatus() {
return this.isFlying;
}
getSolarBoostStatus() {
const status = this.hasSolarBoost;
if (status) {
console.log('☀️ DEBUG: getSolarBoostStatus() returning true');
}
return status;
}
getWaterSlideStatus() {
return this.hasWaterSlide;
}
getWaterSlideObjects() {
return this.waterSlideObjects;
}
getActiveTimers() {
return {
invincibility: this.isInvincible ? this.invincibilityTimer : 0,
flying: this.isFlying ? this.flyingTimer : 0,
solarBoost: this.hasSolarBoost ? this.solarBoostTimer : 0,
windPower: this.hasWindPower ? this.windPowerTimer : 0,
waterSlide: this.hasWaterSlide ? this.waterSlideTimer : 0
};
}
reset() {
// Reset all power-up states
this.isInvincible = false;
this.invincibilityTimer = 0;
this.isFlying = false;
this.flyingTimer = 0;
this.hasSolarBoost = false;
this.solarBoostTimer = 0;
this.hasWindPower = false;
this.windPowerTimer = 0;
this.hasWaterSlide = false;
this.waterSlideTimer = 0;
// Clean up water slide
this.removeWaterSlidePath();
// Clean up pushed obstacles
this.pushedObstacles = [];
// Reset player abilities and color
this.player.setDoubleJumpAbility(false);
this.player.resetToNormalColor();
}
}