1
1
import GameEnv from './GameEnv.js' ;
2
2
import GameControl from './GameControl.js' ;
3
- import PlayerBaseOneD from './PlayerBaseOneD.js' ; ///With this you can change the direction of the sprite sheet with just the sprite rows.
3
+ import PlayerBaseOneD from './PlayerBaseOneD.js' ;
4
+ import SkibidiTitan from './SkibidiTitan.js' ; // Import SkibidiTitan
4
5
5
- /**
6
- * @class PlayerSkibidi class
7
- * @description PlayerSkibidi.js key objective is to eent the user-controlled character in the game.
8
- *
9
- * The Player class extends the Character class, which in turn extends the GameObject class.
10
- * Animations and events are activated by key presses, collisions, and gravity.
11
- * WASD keys are used by user to control The Player object.
12
- *
13
- * @extends PlayerBase
14
- */
15
- export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD added the sprite mirror but deleted the sprite not showing the animations
16
-
17
- /** GameObject instantiation: constructor for PlayerSkibidi object
18
- * @extends Character
19
- * @param {HTMLCanvasElement } canvas - The canvas element to draw the player on.
20
- * @param {HTMLImageElement } image - The image to draw the player with.
21
- * @param {Object } data - The data object containing the player's properties.
22
- */
6
+ export class PlayerSkibidi extends PlayerBaseOneD {
23
7
constructor ( canvas , image , data ) {
24
8
super ( canvas , image , data ) ;
25
9
this . invincible = true ;
26
10
this . timer = false ;
27
11
GameEnv . invincible = false ; // Player is NOT invincible
28
12
29
-
30
13
this . animationSpeed = data ?. animationSpeed ;
31
14
this . counter = this . animationSpeed ;
32
15
// Goomba variables, deprecate?
@@ -62,7 +45,6 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
62
45
63
46
console . log ( "New Y Position:" , this . y ) ;
64
47
}
65
-
66
48
67
49
updateFrameX ( ) {
68
50
if ( this . frameX < this . maxFrame ) {
@@ -90,9 +72,20 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
90
72
this . handleCollisionEvent ( "SkibidiToilet" ) ;
91
73
this . handleCollisionEvent ( "laser" ) ;
92
74
this . handleCollisionEvent ( "powerup" ) ; // created a new case where it detects for collision between player and power-up
75
+ }
76
+
77
+ handleDeath ( ) {
78
+ if ( this . state . isDying ) {
79
+ this . canvas . style . transition = "transform 0.5s" ;
80
+ this . canvas . style . transform = "rotate(-90deg) translate(-26px, 0%)" ;
81
+ GameEnv . playSound ( "PlayerDeath" ) ;
82
+ setTimeout ( async ( ) => {
83
+ await GameControl . transitionToLevel ( GameEnv . levels [ GameEnv . levels . indexOf ( GameEnv . currentLevel ) ] ) ;
84
+ } , 900 ) ;
85
+ }
93
86
}
94
87
95
- handleKeyUp ( event ) {
88
+ handleKeyUp ( event ) {
96
89
const key = event . key ;
97
90
if ( key in this . pressedKeys ) {
98
91
delete this . pressedKeys [ key ] ;
@@ -153,6 +146,15 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
153
146
// handles additional player reactions
154
147
switch ( this . state . collision ) {
155
148
case "finishline" :
149
+ const skibidiTitan = GameEnv . gameObjects . find ( obj => obj . name === 'skibidiTitan' ) ;
150
+ if ( skibidiTitan . currentHp > 0 ) {
151
+ alert ( "Kill the titan with B buddy, why do you think theres a health bar" ) ;
152
+ this . setX ( 0 )
153
+ this . setY ( 700 )
154
+ this . state . animation = 'idle' ;
155
+ break ;
156
+ }
157
+
156
158
// 1. Caught in finishline
157
159
if ( this . collisionData . touchPoints . this . onTopofOther || this . state . isFinishing ) {
158
160
// Position player in the center of the finishline
@@ -175,6 +177,8 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
175
177
this . state . movement . right = true ;
176
178
}
177
179
break ;
180
+
181
+
178
182
case "SkibidiToilet" : // Note: Goomba.js and Player.js could be refactored
179
183
// 1. Player jumps on goomba, interaction with Goomba.js
180
184
if ( this . collisionData . touchPoints . this . top && this . collisionData . touchPoints . other . bottom && this . state . isDying == false ) {
@@ -227,6 +231,7 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
227
231
228
232
}
229
233
break ;
234
+ /*
230
235
case "powerup":
231
236
if (GameEnv.powerUpCollected) {
232
237
console.log("Power-up collision detected! Changing difficulty...");
@@ -246,6 +251,7 @@ export class PlayerSkibidi extends PlayerBaseOneD { /// Using PlayerBaseOneD add
246
251
GameEnv.update();
247
252
console.log("Power Up",GameEnv.gameObjects[GameEnv.gameObjects.length - 1]);
248
253
break;
254
+ */
249
255
}
250
256
251
257
}
0 commit comments