/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { input = GetInput(keyboardState, gamePadState, touchState, accelState, orientation); ParseInput(input); if (IsAlive == false & isOnGround == true) { //DeadFall(); //return; } //ApplyPhysicsNew(gameTime); HandleCollisions(); float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; sprite.UpdateFrame(elapsed, ref _position, ref face, ref spriteState); }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update ( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; // TODO: Add your game logic here. sprite.UpdateFrame(elapsed, ref _position, ref face, ref spriteState); }
public override void HandleInput(GameTime gameTime, InputState input) { //// get all of our input states keyboardState = Keyboard.GetState(); touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); if (maze.player.IsAlive == false) { if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch() == true) { maze.StartRoom().StartNewLife(); } } bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); wasContinuePressed = continuePressed; }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { HandleCollision(); if (this.GetType() == typeof(Chomper)) { ((Chomper)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; if (((Chomper)this).elapsedTimeOpen > ((Chomper)this).timeOpen) { ((Chomper)this).Close(); } } if (this.GetType() == typeof(Spikes)) { ((Spikes)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; if (((Spikes)this).elapsedTimeOpen > ((Spikes)this).timeOpen) { ((Spikes)this).Close(); } } if (this.GetType() == typeof(Gate)) { if (((Gate)this).infiniteOpen == true) { return; } ((Gate)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; if (((Gate)this).elapsedTimeOpen > ((Gate)this).timeOpen) { ((Gate)this).Close(); } } //REMAIN OPEN FOREVER!!! //if (this.GetType() == typeof(Exit)) //{ // ((Exit)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; // if (((Exit)this).elapsedTimeOpen > ((Exit)this).timeOpen) // ((Exit)this).Close(); //} if (this.GetType() == typeof(PressPlate)) { if (((PressPlate)this).infinitePress == true) { return; } ((PressPlate)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; if (((PressPlate)this).elapsedTimeOpen > ((PressPlate)this).timeOpen & ((PressPlate)this).State == Enumeration.StateTile.dpressplate) { ((PressPlate)this).DePress(); } } if (this.GetType() == typeof(Loose)) { if (((Loose)this).tileState.Value().state == Enumeration.StateTile.loose) { ((Loose)this).elapsedTimeOpen += (float)gameTime.ElapsedGameTime.TotalSeconds; if (((Loose)this).elapsedTimeOpen > ((Loose)this).timeFall) { ((Loose)this).Fall(); } } } float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; tileAnimation.UpdateFrameTile(elapsed, ref _position, ref flip, ref tileState); }
private void UpdateTilesUp(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { int y = Height - 1; for (int x = 0; x < Width; ++x) { // If there is a visible Tile in that position Texture2D texture = null; texture = tiles[x, y].Texture; if (texture != null) { // Draw it in screen space. Rectangle rect = new Rectangle(x * (int)Tile.Size.X, -1 * (int)Tile.Size.Y - BOTTOM_BORDER, (int)texture.Width, (int)texture.Height); Vector2 position = new Vector2(rect.X, rect.Y); tiles[x, y].Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); } } }
private void UpdateTilesTemporaney(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { try { lock (tilesTemporaney) { foreach (Tile item in tilesTemporaney) { item.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); // Insert your code here. } } } catch (Exception ex) { } }
private void UpdateSprites(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { foreach (Sprite s in SpritesInRoom()) { ((Guard)s).Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); } }
private void UpdateItems(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { for (int y = Height - 1; y >= 0; --y) { for (int x = 0; x < Width; ++x) { if (tiles[x, y].item != null) { tiles[x, y].item.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); } } } }
public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { //THIS IS FOR NOT UPDATE THE BLOCK ROOM AND SAVE SOME CPU TIME.... if (this.roomName == "MAP_blockroom.xml") { return; } UpdateTilesTemporaney(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); UpdateTiles(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); UpdateItems(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); }
public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; itemAnimation.UpdateFrameItem(elapsed, ref position, ref flip, ref itemState); }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private Enumeration.Input GetInput ( KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation ) { if (spriteState.Value().Priority == Enumeration.PriorityState.Force) { return(Enumeration.Input.none); } //////// // CHEAT DEBUG ///////// if (PoP.CONFIG_DEBUG == true) { if (keyboardState.IsKeyDown(Keys.NumPad8)) { myRoom = myRoom.Up; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.NumPad2)) { myRoom = myRoom.Down; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.NumPad4)) { myRoom = myRoom.Left; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.NumPad6)) { myRoom = myRoom.Right; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.NumPad0)) { Maze.StartRoom().StartNewLife(); return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.OemMinus)) { AnimationSequence.frameRate = AnimationSequence.frameRate - 0.1f; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.OemPlus)) { AnimationSequence.frameRate = AnimationSequence.frameRate + 0.1f; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.NumPad5)) { //Maze.player.Resheathe(); Maze.player.Sword = true; Maze.player.LivePoints = 15; Maze.player.Energy = 15; return(Enumeration.Input.none); } if (keyboardState.IsKeyDown(Keys.Add)) { Maze.NextLevel(); } if (keyboardState.IsKeyDown(Keys.Subtract)) { Maze.PreviousLevel(); } } ////////// //TouchControl ////////// if (touchState.Count != 0) { return(GetTouchInput(touchState)); } return(GetKeyboardInput(keyboardState)); }