@@ -13,7 +13,8 @@ import {
1313 PLAYER_IDLE ,
1414 TERRAIN_GRASS_BOTTOM ,
1515 TERRAIN_GRASS_TOP ,
16- UI_RECTANGLE_GRADIENT
16+ UI_RECTANGLE_GRADIENT ,
17+ UI_ROUND_FLAT
1718} from '../assets/kenney' ;
1819
1920type SpawnType = 'obstacle' | 'coin' ;
@@ -75,6 +76,13 @@ export class GameScene extends Phaser.Scene {
7576 private hudBackground ! : Phaser . GameObjects . Image ;
7677 private coinsCollected = 0 ;
7778 private gameOver = false ;
79+ private slideActive = false ;
80+ private slideEndTime = 0 ;
81+ private currentMoveSpeed = PLAYER_SPEED ;
82+ private currentJumpVelocity = JUMP_VELOCITY ;
83+ private lastLeftTapTime = 0 ;
84+ private lastRightTapTime = 0 ;
85+ private slideEmitter ! : Phaser . GameObjects . Particles . ParticleEmitter ;
7886 private baseColor ! : Phaser . GameObjects . Rectangle ;
7987 private desertBackground ! : Phaser . GameObjects . Image ;
8088 private cloudLayer ! : Phaser . GameObjects . TileSprite ;
@@ -125,6 +133,19 @@ export class GameScene extends Phaser.Scene {
125133 this . player . setGravityY ( 900 ) ;
126134 this . player . anims . play ( PLAYER_ANIM_IDLE ) ;
127135
136+ this . slideEmitter = this . add . particles ( 0 , 0 , UI_ROUND_FLAT , {
137+ emitting : false ,
138+ lifespan : 260 ,
139+ speed : { min : 10 , max : 40 } ,
140+ quantity : 2 ,
141+ scale : { start : 0.18 , end : 0.02 } ,
142+ alpha : { start : 0.8 , end : 0 } ,
143+ angle : { min : 160 , max : 200 } ,
144+ blendMode : Phaser . BlendModes . ADD
145+ } ) ;
146+ this . slideEmitter . setDepth ( 5 ) ;
147+ this . slideEmitter . startFollow ( this . player , 0 , this . player . displayHeight * 0.15 ) ;
148+
128149 for ( let i = 0 ; i < tilesAcross ; i += 1 ) {
129150 const x = i * groundTileWidth ;
130151 const bottomTile = this . add . image ( x , groundBottomY , TERRAIN_GRASS_BOTTOM ) . setOrigin ( 0 , 0 ) . setDepth ( - 5 ) ;
@@ -174,6 +195,16 @@ export class GameScene extends Phaser.Scene {
174195 this . moveDirection = 0 ;
175196 } ) ;
176197
198+ this . input . keyboard ?. on ( 'keydown' , ( event : KeyboardEvent ) => {
199+ if ( event . repeat ) {
200+ return ;
201+ }
202+ if ( this . gameOver ) {
203+ return ;
204+ }
205+ this . handleDoubleTap ( event ) ;
206+ } ) ;
207+
177208 this . createHud ( width ) ;
178209
179210 this . statusText = this . add . text ( GAME_WIDTH / 2 , GAME_HEIGHT / 2 , '' , {
@@ -189,6 +220,14 @@ export class GameScene extends Phaser.Scene {
189220 this . lastFishSpawnTime = this . time . now ;
190221 this . gameOver = false ;
191222 this . coinsCollected = 0 ;
223+ this . slideActive = false ;
224+ this . slideEndTime = 0 ;
225+ this . currentMoveSpeed = PLAYER_SPEED ;
226+ this . currentJumpVelocity = JUMP_VELOCITY ;
227+ this . lastLeftTapTime = 0 ;
228+ this . lastRightTapTime = 0 ;
229+ this . slideEmitter . stop ( ) ;
230+ this . player . clearTint ( ) ;
192231 this . setFishPowerCount ( 0 ) ;
193232 }
194233
@@ -202,6 +241,7 @@ export class GameScene extends Phaser.Scene {
202241 return ;
203242 }
204243
244+ this . updateSlideMax ( time ) ;
205245 this . handleMovement ( ) ;
206246 this . handleSpawning ( time ) ;
207247 this . handleFishSpawning ( time ) ;
@@ -223,10 +263,10 @@ export class GameScene extends Phaser.Scene {
223263 }
224264
225265 if ( isGrounded && Phaser . Input . Keyboard . JustDown ( this . keys . SPACE ) ) {
226- this . player . setVelocityY ( JUMP_VELOCITY ) ;
266+ this . player . setVelocityY ( this . currentJumpVelocity ) ;
227267 }
228268
229- this . player . setVelocityX ( direction * PLAYER_SPEED ) ;
269+ this . player . setVelocityX ( direction * this . currentMoveSpeed ) ;
230270
231271 if ( ! isGrounded ) {
232272 this . player . anims . play ( PLAYER_ANIM_JUMP , true ) ;
@@ -277,6 +317,9 @@ export class GameScene extends Phaser.Scene {
277317 }
278318
279319 private handleFishSpawning ( time : number ) {
320+ if ( this . slideActive ) {
321+ return ;
322+ }
280323 const spawnInterval = FISH_SPAWN_INTERVAL + Phaser . Math . Between ( - FISH_SPAWN_VARIANCE , FISH_SPAWN_VARIANCE ) ;
281324 if ( time - this . lastFishSpawnTime < spawnInterval ) {
282325 return ;
@@ -346,6 +389,7 @@ export class GameScene extends Phaser.Scene {
346389 }
347390
348391 this . gameOver = true ;
392+ this . deactivateSlideMax ( ) ;
349393 this . player . setVelocity ( 0 , 0 ) ;
350394 this . obstacles . setVelocityY ( 0 ) ;
351395 this . coins . setVelocityY ( 0 ) ;
@@ -458,6 +502,75 @@ export class GameScene extends Phaser.Scene {
458502 this . layoutHud ( this . scale . width ) ;
459503 }
460504
505+ private handleDoubleTap ( event : KeyboardEvent ) {
506+ const now = this . time . now ;
507+ const isLeft = event . code === 'ArrowLeft' || event . code === 'KeyA' ;
508+ const isRight = event . code === 'ArrowRight' || event . code === 'KeyD' ;
509+
510+ if ( ! isLeft && ! isRight ) {
511+ return ;
512+ }
513+
514+ if ( isLeft ) {
515+ if ( now - this . lastLeftTapTime <= 220 ) {
516+ this . tryActivateSlideMax ( ) ;
517+ this . lastLeftTapTime = 0 ;
518+ return ;
519+ }
520+ this . lastLeftTapTime = now ;
521+ }
522+
523+ if ( isRight ) {
524+ if ( now - this . lastRightTapTime <= 220 ) {
525+ this . tryActivateSlideMax ( ) ;
526+ this . lastRightTapTime = 0 ;
527+ return ;
528+ }
529+ this . lastRightTapTime = now ;
530+ }
531+ }
532+
533+ private tryActivateSlideMax ( ) {
534+ if ( this . slideActive ) {
535+ return ;
536+ }
537+ if ( this . fishPowerCount < FISH_MAX_POWER ) {
538+ return ;
539+ }
540+ this . activateSlideMax ( ) ;
541+ }
542+
543+ private activateSlideMax ( ) {
544+ this . slideActive = true ;
545+ this . slideEndTime = this . time . now + 3000 ;
546+ this . currentMoveSpeed = PLAYER_SPEED * 2.4 ;
547+ this . currentJumpVelocity = JUMP_VELOCITY * 1.3 ;
548+ this . setFishPowerCount ( 0 ) ;
549+ this . player . setTint ( 0x7ffcff ) ;
550+ this . slideEmitter . start ( ) ;
551+ }
552+
553+ private updateSlideMax ( time : number ) {
554+ if ( ! this . slideActive ) {
555+ return ;
556+ }
557+ if ( time < this . slideEndTime ) {
558+ return ;
559+ }
560+ this . deactivateSlideMax ( ) ;
561+ }
562+
563+ private deactivateSlideMax ( ) {
564+ if ( ! this . slideActive ) {
565+ return ;
566+ }
567+ this . slideActive = false ;
568+ this . currentMoveSpeed = PLAYER_SPEED ;
569+ this . currentJumpVelocity = JUMP_VELOCITY ;
570+ this . slideEmitter . stop ( ) ;
571+ this . player . clearTint ( ) ;
572+ }
573+
461574 private applyFishPulse ( fish : Phaser . Physics . Arcade . Sprite ) {
462575 const baseSpeed = fish . getData ( 'baseSpeed' ) as number ;
463576 if ( ! Number . isFinite ( baseSpeed ) ) {
0 commit comments