// A Director used by most of the scenes in the game. // Note, the menu scene also uses this. class Level : AbstractDirector { static var instance : Level = null // If the scene is won, the next scene to play. @Attribute var nextScene = "menu" // Initially zero, then incremented as aliens are created. // Incremented from method newAlien, and decrmented from alienDead. var aliensRemaining = 0 var ended = false var endCountdown = 100 var escape : Input init { instance = this } override fun activated() { escape = Game.instance.resources.inputs.find("escape") } override fun tick() { if (ended) { endCountdown -- if (endCountdown <= 0) { Game.instance.startScene( nextScene ) } } } fun newAlien() { aliensRemaining ++ } fun alienDied() { aliensRemaining -- if (aliensRemaining <= 0) { DrunkInvaders.instance.unlockScene( nextScene ) ended = true } } override fun onKey( event : KeyEvent ) { if ( escape.isPressed() ) { if ( Game.instance.sceneName == "menu" ) { Game.instance.quit() } else { Game.instance.startScene( "menu" ) } } } }