/* The Producer, which is created as soon as the game starts. Does very little, because Directors and Roles do most of the hard work. */ class HiggsAnomaly : AbstractProducer { static var instance : HiggsAnomaly // When all of the scenes have been completed, the victory scene increments this number. // and we go to the next chapter. // A new item will appear on the mainMenu scene. var chapter = 1 // When all of the chapters have been completed, we go on to the next instalment. // They are the same scenes, but with different gravity settings. // When the last scene of the last chapter has been completed for the last instalment, // the finalVictory scene is shown. That's the end of the game! var instalment = 1 var debugI : Input var isDebug = false val sceneTransition = SceneTransition() init { instance = this val inputs = Game.instance.resources.inputs debugI = inputs.find("debug") } override fun begin() { super.begin() loadWindowSize() Options.instance.load() // Create "framents" of costumes, for use later as explosions. val sfm = SimpleFragmentMaker(300,300) sfm.makeFragments( "ship1", 6 ) sfm.makeFragments( "ship2", 6 ) sfm.makeFragments( "gold", 6 ) sfm.makeFragments( "waterCargo", 6 ) } /** I'll tell you a secret. But you mustn't tell anybody! When you are new to the game, the first menu you see isn't the "mainMenu", it is the "chaptersMenu" for the first chapter. The mainMenu starts the chaptersMenu straight away, and we don't want to prepare a sceneTransition (as you never even SAW the mainMenu. When you complete the first chapter, you WILL THEN see the main menu, which is a list of chapters (you will only see 2 chapters, the one you've just fininshed, and a new one). When you finish the 2nd, you will see a third. */ fun skipTransition( toScene : String ) { skipTransition = true Game.instance.startScene( toScene ) } var skipTransition = false override fun sceneEnding() { // See skipMainMenu() if ( skipTransition ) { skipTransition = false } else { // Takes a screenshot of the old scene, ready to be used in sceneLoaded(). sceneTransition.prepareTransition() } } /** There are various sceneTransitions. The "options" scene slides right ON TOP of the menu, and when you return back from the "options" the menu options scene slides left i.e. the menu doesn't move in either case! When transitioning from a menu to a play scene, the menu slides UP. When transitioning from a play scene to a menu, the play scene slides DOWN. When transitioning from a play to another play, we FADE between them. */ override fun sceneLoaded() { super.sceneLoaded() val screenshot = sceneTransition.actor if (screenshot != null) { val delta = Vector2( getWindow().width, 0 ) // Slide the options scene ON TOP of the menu, and when we return to the menu // we do the opposite (the options scene is STILL ON TOP), and slides out of the way. if ( currentSceneName == "options" ) { val action = ParallelAction() for ( view in Game.instance.scene.views() ) { view.rect += delta // Jump the view off screen to the right action.add( MoveRectIntBy( view.rect, 1, -delta, Eases.easeIn ) ) } sceneTransition.beginTransition( PreventWindowResize(action), true ) } else if ( previousSceneName == "options" ) { sceneTransition.beginTransition( MoveXBy( screenshot.position, 1, window.width, Eases.easeIn ) ) } else { if ( currentSceneName.contains( "Menu" ) ) { sceneTransition.beginTransition( MoveYBy( screenshot.position, 1, -getWindow().height, Eases.easeInQuad ) ) } else if ( previousSceneName.contains("Menu") ) { sceneTransition.beginTransition( MoveYBy( screenshot.position, 1, getWindow().height, Eases.easeInQuad ) ) } else { sceneTransition.beginTransition( Fade( screenshot, 1, 0, Eases.easeIn ) ) } } } if (isDebug) { Game.instance.mergeScene("debug") } } override fun onResize(event : ResizeEvent) { super.onResize( event ) saveWindowSize() } override fun layout() { arrangeViews() } override fun onKey( event : KeyEvent ) { if (debugI.matches(event)) { isDebug = !isDebug if (isDebug == true) { Game.instance.mergeScene("debug") Game.instance.gameLoop.resetStats() } else { val glassStage = Game.instance.scene.findStage("glass") val fps = glassStage.findActorByName("fps") val memory = glassStage.findActorByName("memory") if (fps != null) fps.die() if (memory != null) memory.die() } } } // Returns how many chapters have been completed (0 when the game is new) fun chaptersCompleted() : int { val preferences = Game.instance.preferences return preferences.getInt( "chaptersCompleted", 0 ) } // Returns how many instalments have been completed (0 when the game is new) fun instalmentsCompleted() : int { val preferences = Game.instance.preferences return preferences.getInt( "instalmentsCompleted", 0 ) } /** */ fun completedChapter() { if (HiggsAnomaly.instance.chapter >= chaptersCompleted()) { val preferences = Game.instance.preferences preferences.set( "chaptersCompleted", HiggsAnomaly.instance.chapter ) } } /** * Return true if there are more instalments */ fun completedInstalment() : bool { chapter = 1 if (instalment >= instalmentsCompleted()) { val preferences = Game.instance.preferences preferences.set( "instalmentsCompleted", instalment ) } return if ( ++ instalment > 6 ) { // All instalments have been completed! instalment = 1 false } else { // Causes the Victory scene to move on to the next instalment. true } } fun highlightInstalment() { for ( button in findStage("glass").findRolesByClass( InstalmentButton ) ) { val color = if (button.instalment == instalment) { Color.create("#cccc33") } else { Color.create("#808080") } button.then( Colorize( button.actor.textAppearance.textStyle.color, 0.2, color ) ) } } }