class Countdown : ActionRole { var requiredSeconds = 60 var seconds = requiredSeconds var score = 0 var started = false override fun begin() { actor.name = "countdown" actor.textAppearance.text = "" requiredSeconds = Play.instance.seconds seconds = requiredSeconds super.begin() } // Called ever second before [requiredSeconds] have ellapsed. fun countdown() { seconds -- score ++ actor.textAppearance.text = "$seconds" } // Called ever second after [requiredSeconds] have ellapsed. fun countup() { seconds ++ score ++ actor.textAppearance.text = "Score : $score" if (score == requiredSeconds * 3) { actor.event( "bonus" ) } if (score == Play.instance.highScore) { actor.event( "bonus" ) } } fun completed() { DodgeEm.instance.unlockScene( Play.instance.nextScene ) actor.event("unlocked") } fun realStart() { replaceAction ( // Count down to zero (Delay( 1 ) thenOnce this:>countdown).repeat( requiredSeconds ) thenOnce this:>completed then // Count upwards ( Delay( 1 ) thenOnce this:>countup ).forever() ) } fun stop() { replaceAction( Delay( 1 ) ) } }