public void Update(MyGame game, GameTime gameTime) { background.Update(game, gameTime, PlayerAction.None); timer++; var kbState = Keyboard.GetState(); var gpState = GamePad.GetState(PlayerIndex.One); if (timer > 0) { if (gpState.Buttons.Back == ButtonState.Pressed || kbState.IsKeyDown(Keys.Escape)) { game.Exit(); return; } if ((kbState.IsKeyDown(Keys.Right) || kbState.IsKeyDown(Keys.D) || gpState.IsButtonDown(Buttons.DPadRight) || gpState.IsButtonDown(Buttons.LeftThumbstickRight))) { timer = -10; selectedButton[selectedIndex] = false; selectedButton[(selectedIndex + 1) % 4] = true; selectedIndex = (selectedIndex + 1) % 4; Draw(game, gameTime); } if (kbState.IsKeyDown(Keys.Left) || kbState.IsKeyDown(Keys.A) || gpState.IsButtonDown(Buttons.DPadLeft) || gpState.IsButtonDown(Buttons.LeftThumbstickLeft)) { timer = -10; selectedButton[selectedIndex] = false; selectedButton[(selectedIndex + 3) % 4] = true; selectedIndex = (selectedIndex + 3) % 4; Draw(game, gameTime); } if (kbState.IsKeyDown(Keys.Space)) { if (selectedIndex == 0) { var scene = new GameLevel(@"Content\Maps\level_fire.txt"); game.setScene(scene); } else if (selectedIndex == 1) { var scene = new GameLevel(@"Content\Maps\level_earth.txt"); game.setScene(scene); } else if (selectedIndex == 2) { var scene = new GameLevel(@"Content\Maps\level_air.txt"); game.setScene(scene); } else if (selectedIndex == 3) { var scene = new GameLevel(@"Content\Maps\level_water.txt"); game.setScene(scene); } } } }
public void Update(MyGame game, GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { game.setScene(new MainMenu()); return; } var action = ReadPlayerControls(); if (!jumping) { if ((action & PlayerAction.Jump) == PlayerAction.Jump) { jumping = true; jumpingHeight = jumpingHeightStart; player.PlayJumpSoundEffect(); } } var limitY = map.GetFloorY(game, player.PlayerSize); var rightX = map.GetRightX(game, player.PlayerSize); var leftX = map.GetLeftX(game, player.PlayerSize); System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}", leftX, rightX)); if ((action & PlayerAction.MoveLeft) == PlayerAction.MoveLeft && player.PlayerLocation.X < leftX) { action &= ~PlayerAction.MoveLeft; } if ((action & PlayerAction.MoveRight) == PlayerAction.MoveRight && player.PlayerLocation.X + player.PlayerSize.Width > rightX) { action &= ~PlayerAction.MoveRight; } if (jumping) { player.PlayerLocation.Y += jumpingHeight; jumpingHeight += .5f; if (jumpingHeight > -jumpingHeightStart) { jumping = false; } if (player.PlayerLocation.Y + player.PlayerSize.Height > limitY) { var newY = limitY - player.PlayerSize.Height; //if (newY > player.PlayerLocation.Y) { player.PlayerLocation.Y = newY; jumping = false; } } } else { if (player.PlayerLocation.Y + player.PlayerSize.Height + 15 < limitY) { player.PlayerLocation.Y += 15; } else { var newY = limitY - player.PlayerSize.Height; if (newY >= player.PlayerLocation.Y) { player.PlayerLocation.Y = newY; jumping = false; } } } player.Update(game, gameTime, action); background.Update(game, gameTime, action); map.Update(game, gameTime, action); }