class Play : AbstractDirector { @Attribute var horizontalClan = Clan.MO @Attribute var verticalClan = Clan.MO @Attribute var seconds = 15 @Attribute var nextScene = "menu" @Attribute var acceleration = 0.1 var highScore = 0 var action : Action var started = false var ended = false var restartI : Input var startI : Input static var instance : Play fun play() = this init { instance = this } override fun begin() { super.begin() highScore = DodgeEm.instance.sceneScore( Game.instance.sceneName ) } override fun activated() { restartI = Game.instance.resources.inputs.find( "restart" ) startI = Game.instance.resources.inputs.find( "start" ) action = ( Delay( 1 ) thenOnce this:>increaseSpeed ).forever() action.begin() Game.instance.resources.sounds.find("readyset").play() } override fun tick() { action.act() } override fun onKey( event : KeyEvent ) { if (restartI.matches(event) ) { Game.instance.startScene( Game.instance.sceneName ) } if (!started && startI.matches(event) ) { realStart() } } override fun onMouseButton( event : MouseEvent ) { if (!started && startI.matches(event) ) { realStart() } } fun realStart() { if ( ! started ) { Game.instance.resources.sounds.find("readyset").stop() started = true (Game.instance.scene.findActorByName( "startInfo" ).role as StartInfo).realStart() (Game.instance.scene.findActorByName( "player" ).role as Player).realStart() (Game.instance.scene.findActorByName( "countdown" ).role as Countdown).realStart() } } fun playerDied() { ended = true } fun increaseSpeed() { if (started && !ended) { val rocks = Game.instance.scene.findStage( "main" ).findRolesByClass( Rock ) for ( rock in rocks ) { rock.velocity.x = Math.signum(rock.velocity.x) * (Math.abs(rock.velocity.x) + acceleration) rock.velocity.y = Math.signum(rock.velocity.y) * (Math.abs(rock.velocity.y) + acceleration) } } } }