public override void Update() { switch (Globals.gamestate) { case Gamestate.Active: case Gamestate.Paused: case Gamestate.Mainmenu: case Gamestate.Optionsmenu: case Gamestate.Challengesmenu: case Gamestate.Statsmenu: case Gamestate.Win: break; case Gamestate.Dead: Globals.save.DeleteFile("xml\\level.xml"); Globals.save.DeleteFile("xml\\stats.xml"); restartButton.Update(); if (restartButton.buttonState == Button.ButtonState.Activated) { ResetWorld(null); } if (Globals.GetKeyUp(Keys.Escape)) { Globals.CurrentScene = new Mainmenu(); Globals.gamestate = Gamestate.Mainmenu; } break; default: break; } }
public override void Update() { Savebutton.Update(); // Update the buttons and check which button is supposed to be selected. for (int i = 0; i < buttons.Count; i++) { buttons[i].Update(); if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.W) || Globals.GetKeyUp(Keys.Up)) && i > 0) { buttons[i - 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.S) || Globals.GetKeyUp(Keys.Down)) && i < buttons.Count - 1) { buttons[i + 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } } // Switch back to the mainmenu by hitting the escape key. if (Globals.GetKeyDown(Keys.Escape)) { //SaveOptions(null); //Globals.gamestate = Gamestate.Mainmenu; Globals.CurrentScene = new Mainmenu(); } }
public override void Update() { for (int i = 0; i < buttons.Count; i++) { buttons[i].Update(); if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.A) || Globals.GetKeyUp(Keys.Left)) && i > 0) { buttons[i - 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.D) || Globals.GetKeyUp(Keys.Right)) && i < buttons.Count - 1) { buttons[i + 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } } // Switch back to the mainmenu by hitting the escape key. if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape)) { //Globals.gamestate = Gamestate.Mainmenu; Globals.CurrentScene = new Mainmenu(); } }
public override void Update() { // Update the buttons and check which button is supposed to be selected. for (int i = 0; i < buttons.Count; i++) { buttons[i].Update(); if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.W) || Globals.GetKeyUp(Keys.Up)) && i > 0) { buttons[i - 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } if (buttons[i].buttonState == Button.ButtonState.Selected && (Globals.GetKeyUp(Keys.S) || Globals.GetKeyUp(Keys.Down)) && i < buttons.Count - 1) { buttons[i + 1].buttonState = Button.ButtonState.Selected; buttons[i].buttonState = Button.ButtonState.Unselected; // Break because the player can move the arrow only once per frame. break; } } // Close the game by hitting the escape key. if (Globals.GetKeyDown(Keys.Escape)) { System.Environment.Exit(0); } }
public virtual void Update() { switch (buttonState) { case ButtonState.Unselected: break; case ButtonState.Selected: // press enter to activate the button if (Globals.GetKeyUp(Keys.Enter)) { buttonState = ButtonState.Activated; } break; case ButtonState.Activated: // run the buttons effect and get back to being only selected ButtonUse(); buttonState = ButtonState.Selected; break; default: break; } }
public override void Update() { switch (buttonState) { case ButtonState.Unselected: break; case ButtonState.Selected: // press enter to activate the button if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.Enter)) { buttonState = ButtonState.Activated; } ChangeValue(); break; case ButtonState.Activated: // run the buttons effect and get back to being only selected buttonState = ButtonState.Selected; break; default: break; } }
public override void Update() { // Switch back to the mainmenu by hitting the escape key. if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape)) { //Globals.gamestate = Gamestate.Mainmenu; Globals.CurrentScene = new Mainmenu(); } }
/// <summary> /// The Update method of a Player. Handles input and "stuff". /// </summary> public override void Update() { // if the players HP is 0, thus is dead, change the gamestate to dead if (Health <= 0) { Globals.gamestate = Gamestate.Dead; } // pressing the P key will pause the game and thus stop updating the game (unpausing in Game1.Update()) if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.P)) { Globals.gamestate = Gamestate.Paused; } //activating itemeffects on buttonpress for testing if (Globals.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.K)) { poopsicle = true; } //just boomer things if (Globals.GetKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) && Level.Player.Bombs > 0) { //Level.CurrentRoom.Add(new Explosion(Position)); Level.CurrentRoom.Add(new Bomb(Position)); Level.Player.Bombs--; Globals.sounds.PlaySoundEffect("Sound8"); } //testing items and such if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.J)) { //Level.CurrentRoom.Add(new Itemstone(new Syringe(Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale), // Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale)); Level.CurrentRoom.Add(new Pot(Level.CurrentRoom.Position + (Room.Dimensions / 5) * Tile.Size * Globals.Scale)); //Level.Player.Keys += 1; } //testing environment and enemies if (Globals.GetKeyUp(Microsoft.Xna.Framework.Input.Keys.L)) { Level.CurrentRoom.Add(new Flyboss(Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale)); //Level.CurrentRoom.Add(new Itemstone(new Heart(Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale), // Level.CurrentRoom.Position + (Room.Dimensions / 3) * Tile.Size * Globals.Scale)); } // effect used, when the player picks up the Poopsicle item. Spawn 3 flies, that are orbiting around you. if (poopsicle) { Companions.Add(new Flybuddy(new Vector2(Position.X, Position.Y + 55), 0)); Companions.Add(new Flybuddy(new Vector2(Position.X + 40, Position.Y - 40))); Companions.Add(new Flybuddy(new Vector2(Position.X - 40, Position.Y - 40))); poopsicle = false; } // Handle movement input. // The movement speed. //ushort speed = 350; // The velocity. _velocity = Vector2.Zero; // Up. if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.W)) { // Play the movement sound. //Globals.sounds.PlaySoundEffectOnce("Sound3"); // Move it up. _velocity += -Vector2.UnitY * speed; // If there's a top door. if (Level.CurrentRoom.Doors[(byte)Directions.Up] != null) { // If it touches the top door, it's hidden and the player has more than 0 keys. if (!(Level.CurrentRoom.Doors[(byte)Directions.Up].Kind == DoorKind.Hidden) && (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Up]) && Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Up].Position.X - Position.X) <= Door.Width * Scale.X) && Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Locked && Keys > 0) { // The player uses a key. Keys--; // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Up].Unlock(true); } } } // Right. if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.D)) { // Play the movement sound. //Globals.sounds.PlaySoundEffectOnce("Sound2"); // Move it right. _velocity += Vector2.UnitX * speed; // If there's a right door. if (Level.CurrentRoom.Doors[(byte)Directions.Right] != null) { // If it touches the right door, it's hidden and the player has more than 0 keys. if (!(Level.CurrentRoom.Doors[(byte)Directions.Right].Kind == DoorKind.Hidden) && (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Right]) && Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Right].Position.Y - Position.Y) <= Door.Width * Scale.Y) && Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Locked && Keys > 0) { // The player uses a key. Keys--; // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Right].Unlock(true); } } } // Down. if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.S)) { // Play the movement sound. //Globals.sounds.PlaySoundEffectOnce("Sound4"); // Move it down. _velocity += Vector2.UnitY * speed; // If there's a bottom door. if (Level.CurrentRoom.Doors[(byte)Directions.Down] != null) { // If it touches the bottom door, it's hidden and the player has more than 0 keys. if (!(Level.CurrentRoom.Doors[(byte)Directions.Down].Kind == DoorKind.Hidden) && (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Down]) && Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Down].Position.X - Position.X) <= Door.Width * Scale.X) && Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Locked && Keys > 0) { // The player uses a key. Keys--; // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Down].Unlock(true); } } } // Left. if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.A)) { // Play the movement sound. //Globals.sounds.PlaySoundEffectOnce("Sound1"); // Move it left. _velocity += -Vector2.UnitX * speed; // If there's a left door. if (Level.CurrentRoom.Doors[(byte)Directions.Left] != null) { // If it touches the left door, it's hidden and the player has more than 0 keys. if (!(Level.CurrentRoom.Doors[(byte)Directions.Left].Kind == DoorKind.Hidden) && (BumpsInto(Level.CurrentRoom.Doors[(byte)Directions.Left]) && Math.Abs(Level.CurrentRoom.Doors[(byte)Directions.Left].Position.Y - Position.Y) <= Door.Width * Scale.Y) && Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Locked && Keys > 0) { // The player uses a key. Keys--; // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Left].Unlock(true); } } } // Choose the proper animation. if (Math.Abs(_velocity.X) > Math.Abs(_velocity.Y)) { // If it moves left. if (_velocity.X < 0) { CurrentAnimation = _walkingAnimations[3]; } // Else it moves right. else { CurrentAnimation = _walkingAnimations[1]; } } // Else it moves up, down or diagonally. else { // If it moves up. if (_velocity.Y < 0) { CurrentAnimation = _walkingAnimations[0]; } // Else it moves down. else if (_velocity.Y > 0) { CurrentAnimation = _walkingAnimations[2]; } } // Move it. if (_velocity != Vector2.Zero) { //Globals.sounds.PlaySoundEffectOnce("Sound4"); // Play the walking sound effect. if (_walkingSound.State != SoundState.Playing) { _walkingSound.Play(); } CurrentAnimation.Resume(); _velocity = Globals.DegreesToVector2(Globals.Vector2ToDegrees(_velocity)) * speed; Move(_velocity); } else { CurrentAnimation.Pause(); CurrentAnimation.SelectFrame(0); } // handle combat inputs damageImunity.UpdateTimer(); timer.UpdateTimer(); // up if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Up) && timer.Test()) { Globals.sounds.PlaySoundEffect("Attack1"); Level.CurrentRoom.Add(new BasicAttack(0 - 90, Position)); timer.ResetToZero(); } // right if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Right) && timer.Test()) { Globals.sounds.PlaySoundEffect("Attack1"); Level.CurrentRoom.Add(new BasicAttack(90 - 90, Position)); timer.ResetToZero(); } // down if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Down) && timer.Test()) { Globals.sounds.PlaySoundEffect("Attack1"); Level.CurrentRoom.Add(new BasicAttack(180 - 90, Position)); timer.ResetToZero(); } // left if (Globals.GetKey(Microsoft.Xna.Framework.Input.Keys.Left) && timer.Test()) { Globals.sounds.PlaySoundEffect("Attack1"); Level.CurrentRoom.Add(new BasicAttack(270 - 90, Position)); timer.ResetToZero(); } // Draw the list of companions for (int i = 0; i < Companions.Count; i++) { Companions[i].Update(); if (Companions[i].isDestroyed) { Companions.RemoveAt(i); } } // Update the Player's layer and stuff. base.Update(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Save the current GameTime and states. Globals.GameTime = gameTime; Globals.CurrentKeyboardState = Keyboard.GetState(); Globals.CurrentMouseState = Mouse.GetState(); Globals.CurrentGamePadState = GamePad.GetState(PlayerIndex.One); switch (Globals.gamestate) { case Gamestate.Active: Globals.CurrentScene.Update(); if (Globals.GetKeyDown(Keys.Escape)) { Level.SaveData(); Level.Player.SaveData(); // [PLACEHOLDER] Save the data of the previous, the current and the next rooms of the level and all its objects excluding the player Globals.sounds.StopSong(); Globals.CurrentScene = new Mainmenu(); Globals.gamestate = Gamestate.Mainmenu; } break; case Gamestate.Paused: Globals.UI.Update(); if (Globals.GetKeyUp(Keys.P)) { Globals.gamestate = Gamestate.Active; } break; case Gamestate.Mainmenu: case Gamestate.Optionsmenu: case Gamestate.Challengesmenu: case Gamestate.Statsmenu: case Gamestate.Win: // Call the current Scene's Update method. Globals.CurrentScene.Update(); // Call the UI's Update method. Globals.UI.Update(); break; case Gamestate.Dead: // Call the UI's Update method. Globals.UI.Update(); break; default: break; } // Save the current states as the previous states (so they will be accessable as previous states in the next Update()). Globals.PreviousKeyboardState = Globals.CurrentKeyboardState; Globals.PreviousMouseState = Globals.CurrentMouseState; Globals.PreviousGamePadState = Globals.CurrentGamePadState; base.Update(gameTime); }