@@ -10,23 +10,31 @@ import {
1010} from "../model/character.ts"
1111import * as signal from "../util/signal.ts"
1212import { bindToggleFullscreenOnce } from "../util/fullscreen.ts"
13+ import { seed } from "../util/random.ts"
1314
1415export class MainCharacter extends Character {
1516 #lastMoveTypes: MoveType [ ] = [ ]
16- #nextActionQueue: ( NextAction | "speed-up" | "speed-reset" ) [ ] = [ ]
17+ #nextActionQueue: ( NextAction | "speed-2x" | "speed-4x" | "speed-reset" ) [ ] =
18+ [ ]
1719 #speedUpTimer: number | undefined = undefined
1820 override getNextAction (
1921 fieldTester : IFieldTester ,
2022 collisionChecker : CollisionChecker ,
2123 ) : NextAction {
2224 if ( this . #nextActionQueue. length > 0 ) {
2325 const nextAction = this . #nextActionQueue. shift ( ) !
24- if ( nextAction === "speed-up " ) {
26+ if ( nextAction === "speed-2x " ) {
2527 this . speed = 2
2628 this . #speedUpTimer = setTimeout ( ( ) => {
2729 this . #nextActionQueue. push ( "speed-reset" , "jump" )
2830 } , 15000 )
2931 return this . getNextAction ( fieldTester , collisionChecker )
32+ } else if ( nextAction === "speed-4x" ) {
33+ this . speed = 4
34+ this . #speedUpTimer = setTimeout ( ( ) => {
35+ this . #nextActionQueue. push ( "speed-reset" , "jump" )
36+ } , 15000 )
37+ return this . getNextAction ( fieldTester , collisionChecker )
3038 } else if ( nextAction === "speed-reset" ) {
3139 if ( this . #speedUpTimer) {
3240 clearTimeout ( this . #speedUpTimer)
@@ -84,7 +92,19 @@ export class MainCharacter extends Character {
8492 }
8593 case "mushroom" : {
8694 itemContainer . collect ( this . i , this . j )
87- this . #nextActionQueue. push ( "speed-reset" , "jump" , "jump" , "speed-up" )
95+ this . #nextActionQueue = [ ]
96+ this . #nextActionQueue. push ( "speed-reset" , "jump" , "speed-2x" )
97+ break
98+ }
99+ case "purple-mushroom" : {
100+ itemContainer . collect ( this . i , this . j )
101+ const { choice } = seed ( `${ this . i } ,${ this . j } ` )
102+ this . #nextActionQueue = [ ]
103+ this . #nextActionQueue. push ( "speed-reset" , "jump" , "jump" , "speed-4x" )
104+ for ( const _ of Array ( 30 ) ) {
105+ this . #nextActionQueue. push ( choice ( [ UP , DOWN , LEFT , RIGHT ] ) )
106+ }
107+ this . #nextActionQueue. push ( "speed-reset" , "jump" )
88108 break
89109 }
90110 }
0 commit comments