/// <summary> /// Handles the logical part of the scene /// </summary> /// <param name="game">Game manager</param> public void Update(Game game) { // Gets if any key was 'just pressed' KeyboardKey key = game.KeyboardManager.AnyTriggered; // If no key was 'just pressed' if (key == null) { // Just updates the animation flow _Animation.Update(game.DeltaMilliseconds); } // If Esc was pressed else if (key.Key == Key.Escape) { // Closes the game Environment.Exit(0); } // If it's not showing "PRESS START" and you pressed some key else if (_Step != 2) { // Skips the current animation by forcing it to progress by its duration _Animation.Update(_Animation.Time); } // If it's showing "PRESS START" and you pressed Enter else if (key.Key == Key.Enter) { // Goes to the step where it fades out the title and move on to the game ++_Step; // Changes the current animation to the title fade out animation // This animation goes from 1 (totally opaque) to 0 (totally transparent) // It takes 500 milliseconds and starts slow, goes through fast and arrives fast _Animation.Reset(1.0f, 0.0f, 500, Smoothness.Start, () => { // When it's completed, move on to the naming scene game.SceneManager.NextScene = new SceneName(); }); } }
/// <summary> /// Handles the logical part of the scene /// </summary> /// <param name="game">Game manager</param> public void Update(Game game) { // Updates the animation flow _Animation.Update(game.DeltaMilliseconds); // Gets if any keyboard key was just 'pressed' KeyboardKey keyboardKey = game.KeyboardManager.AnyTriggered; // If no key was pressed if (keyboardKey == null) { // Then does nothing return; } // If Escape was pressed if (keyboardKey.Key == Key.Escape) { // Moves back to the title scene game.SceneManager.NextScene = new SceneTitle(); } // Checks at what scene step it is switch (_Step) { // This step is when you're selecting what action you're taking case 1: bool actionChanged = false; switch (keyboardKey.Key) { // If the Left Arrow was pressed case Key.Left: // Moves to the left option --_ActionSelected; actionChanged = true; break; // If Right Arrow was pressed case Key.Right: // Moves to the right option ++_ActionSelected; actionChanged = true; break; // If Enter was pressed case Key.Enter: // Runs the action switch (_ActionSelected) { case 0: GameGlobals.Pet.Eat(); break; case 1: GameGlobals.Pet.Sleep(); break; case 2: GameGlobals.Pet.Exercise(); break; default: GameGlobals.Pet.Play(); break; } // If the pet is fine if ( (GameGlobals.Pet.Hunger < 1.0f) && (GameGlobals.Pet.Energy > -1.0f) && (GameGlobals.Pet.Fat < 1.0f) && (GameGlobals.Pet.Happiness > -1.0f) ) { // Subtracts one from the actions left --_ActionsLeft; // Moves to the feedback screen ++_Step; } // If anything about the pet is too critical else { // Fades out to the gameover scene _Animation = new SimpleAnimation(1.0f, 0.0f, 500, Smoothness.Start, () => { game.SceneManager.NextScene = new SceneGameover(); }); _Step = 4; } break; } // If you moved to a different action if (actionChanged) { _ActionSelected %= 4; while (_ActionSelected < 0) { _ActionSelected += 4; } // Do a scrolling animation to the right item _Animation.Reset( _Animation.Value, _ActionSelected, 250, Smoothness.StartArrival ); } break; // This is the feedback part case 2: // If there's still an action left if (_ActionsLeft == 1) { // Goes back to action selection part --_Step; } // Otherwise else { // Fades out to the report scene _Animation.Reset(1.0f, 0.0f, 500, Smoothness.Start, () => game.SceneManager.NextScene = new SceneReport()); ++_Step; } break; } }