@@ -21,9 +21,13 @@ export class GameScene extends Phaser.Scene {
21
21
this . load . image ( 'ground' , 'assets/images/ground.png' ) ;
22
22
this . load . image ( 'wall' , 'assets/images/wall.png' ) ;
23
23
this . load . image ( 'platform' , 'assets/images/platform.png' ) ;
24
- this . load . spritesheet ( 'zeta' ,
25
- 'assets/images/zeta_spritesheet_' + this . character . name + '.png' ,
26
- { frameWidth : 40 , frameHeight : this . character . height }
24
+ this . load . spritesheet ( 'zeta_alpha' ,
25
+ 'assets/images/zeta_spritesheet_alpha.png' ,
26
+ { frameWidth : 40 , frameHeight : 66 }
27
+ ) ;
28
+ this . load . spritesheet ( 'zeta_beta' ,
29
+ 'assets/images/zeta_spritesheet_beta.png' ,
30
+ { frameWidth : 40 , frameHeight : 60 }
27
31
) ;
28
32
this . load . spritesheet ( 'door' ,
29
33
'assets/images/door.png' ,
@@ -37,10 +41,20 @@ export class GameScene extends Phaser.Scene {
37
41
'assets/images/protector_spritesheet.png' ,
38
42
{ frameWidth : 50 , frameHeight : 50 }
39
43
) ;
44
+
45
+ this . load . audio ( 'aud_end_game' , 'assets/audio/end_game.wav' ) ;
46
+ this . load . audio ( 'aud_jump' , 'assets/audio/jump.wav' ) ;
47
+ this . load . audio ( 'aud_walk' , 'assets/audio/walk.wav' ) ;
48
+ this . load . audio ( 'aud_power_down' , 'assets/audio/power_down.wav' ) ;
49
+ this . load . audio ( 'aud_power_up' , 'assets/audio/power_up.wav' ) ;
50
+ this . load . audio ( 'aud_success' , 'assets/audio/success.mp3' ) ;
51
+ this . load . audio ( 'aud_bot_kill' , 'assets/audio/bot_kill.mp3' ) ;
40
52
}
41
53
42
54
create ( ) {
43
55
56
+ this . charactername = 'zeta_' + localStorage . getItem ( "character" ) ;
57
+
44
58
this . botKillCount = 0 ;
45
59
46
60
// Add the background image
@@ -49,6 +63,9 @@ export class GameScene extends Phaser.Scene {
49
63
// Set up sprite animations
50
64
this . initAnimation ( ) ;
51
65
66
+ // Set up the sound fx
67
+ this . createAudio ( ) ;
68
+
52
69
// Add a game controller with devault arrow keys
53
70
this . cursors = this . input . keyboard . createCursorKeys ( ) ;
54
71
@@ -87,29 +104,44 @@ export class GameScene extends Phaser.Scene {
87
104
update ( scenetime ) {
88
105
89
106
if ( this . cursors . left . isDown ) {
107
+ if ( ! this . audWalk . isPlaying && this . player . body . touching . down ) this . audWalk . play ( ) ;
90
108
this . player . setVelocityX ( - 200 ) ;
91
109
this . player . anims . play ( 'left' , true ) ;
92
110
} else if ( this . cursors . right . isDown ) {
111
+ if ( ! this . audWalk . isPlaying && this . player . body . touching . down ) this . audWalk . play ( ) ;
93
112
this . player . setVelocityX ( 200 ) ;
94
113
this . player . anims . play ( 'right' , true ) ;
95
114
} else {
115
+ this . audWalk . stop ( ) ;
96
116
this . player . setVelocityX ( 0 ) ;
97
117
this . player . anims . play ( 'turn' ) ;
98
118
}
99
119
100
120
if ( this . cursors . up . isDown && this . player . body . touching . down ) {
121
+ this . audJump . play ( ) ;
101
122
this . player . setVelocityY ( - 750 ) ;
102
123
}
103
124
104
125
if ( this . botKillCount >= this . botSpawnCount ) {
105
126
// All bots destroyed
127
+ this . audSuccess . play ( ) ;
106
128
this . botKillCount = 0 ;
107
129
this . door . setActive ( true ) ;
108
130
this . door . anims . play ( 'doorOpen' ) ;
109
131
}
110
132
111
133
}
112
134
135
+ createAudio ( ) {
136
+ this . audEndGame = this . sound . add ( 'aud_end_game' ) ;
137
+ this . audJump = this . sound . add ( 'aud_jump' ) ;
138
+ this . audWalk = this . sound . add ( 'aud_walk' ) ;
139
+ this . audPowerDown = this . sound . add ( 'aud_power_down' ) ;
140
+ this . audPowerUp = this . sound . add ( 'aud_power_up' ) ;
141
+ this . audSuccess = this . sound . add ( 'aud_success' ) ;
142
+ this . audBotKill = this . sound . add ( 'aud_bot_kill' ) ;
143
+ }
144
+
113
145
createSwitches ( ) {
114
146
let switches = this . physics . add . staticGroup ( ) ;
115
147
@@ -148,7 +180,7 @@ export class GameScene extends Phaser.Scene {
148
180
}
149
181
150
182
createPlayer ( ) {
151
- let player = this . physics . add . sprite ( 400 , 450 , 'zeta' ) ;
183
+ let player = this . physics . add . sprite ( 400 , 450 , this . charactername ) ;
152
184
153
185
player . setBounce ( 0.2 ) ;
154
186
player . setCollideWorldBounds ( true ) ;
@@ -179,8 +211,10 @@ export class GameScene extends Phaser.Scene {
179
211
180
212
handleCollisionEnemy ( player , bot ) {
181
213
if ( bot . active ) {
214
+ this . audEndGame . play ( ) ;
182
215
this . scene . start ( 'EndScene' ) ;
183
216
} else {
217
+ this . audBotKill . play ( ) ;
184
218
let tmpbot = this . physics . add . staticSprite ( bot . x , bot . y , 'bot' ) ;
185
219
tmpbot . anims . play ( 'botAsplode' ) ;
186
220
bot . destroy ( ) ;
@@ -220,6 +254,7 @@ export class GameScene extends Phaser.Scene {
220
254
}
221
255
222
256
disableBots ( ) {
257
+ this . audPowerDown . play ( ) ;
223
258
for ( let bot of this . bots . getChildren ( ) ) {
224
259
bot . setVelocity ( 0 , 0 ) . setActive ( false ) ;
225
260
}
@@ -231,6 +266,7 @@ export class GameScene extends Phaser.Scene {
231
266
}
232
267
233
268
enableBots ( ) {
269
+ this . audPowerUp . play ( ) ;
234
270
for ( let botSwitch of this . switches . getChildren ( ) ) {
235
271
botSwitch . anims . play ( 'switchOn' ) ;
236
272
botSwitch . setActive ( true ) ;
@@ -242,22 +278,28 @@ export class GameScene extends Phaser.Scene {
242
278
}
243
279
244
280
initAnimation ( ) {
281
+
282
+ // Clear out the zeta anims to allow for character change
283
+ this . anims . remove ( 'left' ) ;
284
+ this . anims . remove ( 'turn' ) ;
285
+ this . anims . remove ( 'right' ) ;
286
+
245
287
this . anims . create ( {
246
288
key : 'left' ,
247
- frames : this . anims . generateFrameNumbers ( 'zeta' , { start : 0 , end : 3 } ) ,
289
+ frames : this . anims . generateFrameNumbers ( this . charactername , { start : 0 , end : 3 } ) ,
248
290
frameRate : 20 ,
249
291
repeat : - 1
250
292
} ) ;
251
293
252
294
this . anims . create ( {
253
295
key : 'turn' ,
254
- frames : [ { key : 'zeta' , frame : 4 } ] ,
296
+ frames : [ { key : this . charactername , frame : 4 } ] ,
255
297
frameRate : 20
256
298
} ) ;
257
299
258
300
this . anims . create ( {
259
301
key : 'right' ,
260
- frames : this . anims . generateFrameNumbers ( 'zeta' , { start : 5 , end : 8 } ) ,
302
+ frames : this . anims . generateFrameNumbers ( this . charactername , { start : 5 , end : 8 } ) ,
261
303
frameRate : 20 ,
262
304
repeat : - 1
263
305
} ) ;
0 commit comments