import { Helicopter } from "./helicopter" ; import { PowerUp } from "./power_up" ; import { ShockAbsorber } from "./shock_absorber" ; import { SuperBounce } from "./super_bounce" ; import { SuperJump } from "./super_jump" ; import { SuperSpeed } from "./super_speed" ; import { TimeTravel } from "./time_travel" ; interface Type < T > extends Function { new ( ... args ) : T ; } export const POSSIBLE_POWERUPS = [ SuperJump , SuperSpeed , Helicopter , SuperBounce , ShockAbsorber , TimeTravel ] ; /** A random power-up decides which power-up it acts like once it is picked up. */ export class RandomPowerUp extends PowerUp { dtsPath = "shapes/items/random.dts" ; sounds = POSSIBLE_POWERUPS . map ( x => new x ( this . element ) . sounds ) . flat ( ) ; lastInstance : PowerUp ; pickedUpCount = 0 ; pickUpName = '' ; pickUp ( ) { while ( true ) { let Random ; if ( this . level . replay . mode === 'record' ) Random = POSSIBLE_POWERUPS [ Math . floor ( Math . random ( ) * 6 ) ] ; else Random = POSSIBLE_POWERUPS [ this . level . replay . randomPowerUpChoices . get ( this . id ) [ this . pickedUpCount ] ] ; let instance = new Random ( this . element ) ; instance . level = this . level ; instance . id = this . id ; if ( instance . pickUp ( ) ) { this . pickUpName = instance . pickUpName ; this . customPickUpAlert = instance . customPickUpAlert ; this . an = instance . an ; this . autoUse = instance . autoUse ; this . cooldownDuration = instance . cooldownDuration ; this . lastInstance = instance ; this . pickedUpCount ++ ; if ( this . level . replay . mode === 'record' ) { let arr = this . level . replay . randomPowerUpChoices . get ( this . id ) ; if ( ! arr ) arr = [ ] , this . level . replay . randomPowerUpChoices . set ( this . id , arr ) ; arr . push ( POSSIBLE_POWERUPS . indexOf ( Random ) ) ; } return true ; } } } use ( t ) { this . lastInstance . use ( t ) ; } getAllDtsPaths ( ) { return POSSIBLE_POWERUPS . map ( x => new x ( this . element ) . dtsPath ) ; } reset ( ) { super . reset ( ) ; this . pickedUpCount = 0 ; } }