Repository navigation
Expand file tree
/
Copy pathpowerups.js
More file actions
282 lines (246 loc) · 8.53 KB
/
Copy pathpowerups.js
File metadata and controls
282 lines (246 loc) · 8.53 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
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
// 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
}
setGameSpeedReference(gameSpeedRef) {
this.gameSpeed = gameSpeedRef;
}
setCollectableManager(collectableManager) {
this.collectableManager = collectableManager;
}
activateInvincibility(duration = POWER_UP_DURATIONS.INVINCIBILITY) {
this.isInvincible = true;
this.invincibilityTimer = duration;
this.player.setColor(COLORS.PLAYER.INVINCIBLE);
console.log("Hard Hat Shield ACTIVE!");
}
deactivateInvincibility() {
this.isInvincible = false;
this.updatePlayerColor();
console.log("Hard Hat Shield DEACTIVATED!");
}
activateHelicopter(duration = POWER_UP_DURATIONS.HELICOPTER) {
console.log("Activating Helicopter Ride with duration:", 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);
console.log("Helicopter Ride ACTIVE!");
}
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();
console.log("Helicopter Ride 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);
console.log("Solar Power Boost ACTIVE!");
}
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();
console.log("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);
console.log("Wind Power ACTIVE!");
}
deactivateWindPower() {
this.hasWindPower = false;
this.player.setDoubleJumpAbility(false);
this.updatePlayerColor();
console.log("Wind Power DEACTIVATED!");
}
activateWaterSlide(duration = POWER_UP_DURATIONS.WATER_SLIDE) {
console.log("Activating Water Pipeline with duration:", duration);
this.hasWaterSlide = true;
this.waterSlideTimer = duration;
this.createWaterSlidePath();
this.player.setColor(COLORS.PLAYER.WATER_SLIDE);
console.log("Water Pipeline ACTIVE!");
}
deactivateWaterSlide() {
this.hasWaterSlide = false;
this.removeWaterSlidePath();
this.updatePlayerColor();
console.log("Water Pipeline DEACTIVATED!");
}
createWaterSlidePath() {
this.removeWaterSlidePath();
const slideLength = 50;
const slideGeometry = new THREE.BoxGeometry(1, 0.1, 1);
const slideMaterial = new THREE.MeshStandardMaterial({
color: 0x00aaff,
transparent: true,
opacity: 0.7
});
const slideLane = Math.floor(Math.random() * LANES.COUNT);
const playerZ = this.player.getPosition().z;
for (let i = 0; i < slideLength; i++) {
const slideSegment = new THREE.Mesh(slideGeometry, slideMaterial);
slideSegment.position.set(
LANES.POSITIONS[slideLane],
0.05,
playerZ - 10 - i
);
this.scene.add(slideSegment);
this.waterSlideObjects.push(slideSegment);
}
}
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) {
for (const obj of this.waterSlideObjects) {
obj.position.z += gameSpeed;
}
}
}
// 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();
// Reset player abilities and color
this.player.setDoubleJumpAbility(false);
this.player.resetToNormalColor();
}
}