protected override void Update(GameTime gameTime) { KeyboardState keyboardState = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here var gamePadState = GamePad.GetState(PlayerIndex.One); //var leftStick = gamePadState.ThumbSticks.Left; var dt = gameTime.ElapsedGameTime.TotalMilliseconds; player.Update(gamePadState, keyboardState, dt); var collisions = map.Collide(player.getPos()); player.Collide(collisions); //if (leftStick.X < 0) { // pos.X -= (float)dt; //} else if (leftStick.X > 0) { // pos.X += (float)dt; //} base.Update(gameTime); }
/// <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) { var state = Keyboard.GetState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Player1.Collide(Snoek)) { MessageBox.Show("score:" + Snoek.score); Exit(); } // TODO: Add your update logic here if (Snoek.direction == Player.direction.left) { Snoek.Position.X += Snoek.speed; } if (Snoek.direction == Player.direction.right) { Snoek.Position.X -= Snoek.speed; } // Move our sprite based on arrow keys being pressed: if (state.IsKeyDown(Keys.Right)) { Player1.Move(Player.direction.right); } if (state.IsKeyDown(Keys.Left)) { Player1.Move(Player.direction.left); } if (state.IsKeyDown(Keys.Up)) { Player1.Move(Player.direction.up); } if (state.IsKeyDown(Keys.Down)) { Player1.Move(Player.direction.down); } base.Update(gameTime); }