/// <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 keyboardKey = game.KeyboardManager.AnyTriggered; // If no key was 'just pressed' if (keyboardKey == null) { // Does nothing return; } // Increases the amount of days that have passed GameGlobals.Days++; // Then goes back to the game scene game.SceneManager.NextScene = new SceneGame(); }
/// <summary> /// Creates a keyboard manager /// </summary> /// <param name="game">Game manager</param> public KeyboardManager(Game game) { // Gets all the keys from the enumeration and how many there are of them Key[] keys = (Key[])Enum.GetValues(typeof(Key)); int keysLength = keys.Length; // Creates a collection of keyboard key managers to manage every key // NOTE: it's keyLength - 1 because it doesn't allow you to manage the NULL key, so we can skip it _Keys = new KeyboardKey[keysLength - 1]; Key key; // Iterates through all the keys for (int i = 1; i < keysLength; i++) { // And sets up every keyboard key manager key = keys[i]; _Keys[i - 1] = new KeyboardKey(game, key, Keyboard.IsKeyDown(key)); } }
/// <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; } }
/// <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 keyboardKey = game.KeyboardManager.AnyTriggered; // If not key was 'just pressed' if (keyboardKey == null) { // Does nothing return; } // If Esc was pressed if (keyboardKey.Key == Key.Escape) { // Goes to the title screen game.SceneManager.NextScene = new SceneTitle(); } // If Enter was pressed else if (keyboardKey.Key == Key.Enter) { // Checks if the name length is over than 0 int nameLength = _Name.Length; // If it's over than 0 it means the pet was named something if (nameLength > 0) { // So it moves to the actual game scene game.SceneManager.NextScene = new SceneGame(); } } // If Backspace was pressed else if (keyboardKey.Key == Key.Back) { // Checks for the length again int nameLength = _Name.Length; // And if it's over than 0, it means that the pet was named something if (nameLength > 0) { // So removes the last character from it _Name = _Name.Substring(0, nameLength - 1); } } // If any other key was pressed other than those three else { // Gets the key name string keyString = keyboardKey.Key.ToString(); // If the key name is only one character if (keyString.Length == 1) { // Gets this character char keyChar = keyString[0]; // And if it's a letter if (char.IsLetter(keyChar)) { // Checks for the length once again int nameLength = _Name.Length; // And if the name length is not larger than 8 if (nameLength < 8) { // Add this letter _Name += keyChar; } } } } }