public void InputsPlayer(GameTime gameTime, bool move, bool jump, Player player) { // Save previous keyboard/gamepad states previousKeyboardState = currentKeyboardState; previousGamepadState = currentGamepadState; // Read current keyboard/gamepad currentKeyboardState = Keyboard.GetState(); currentGamepadState = GamePad.GetState(PlayerIndex.One); if (move && player.CanMove) { if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamepadState.ThumbSticks.Left.X < 0) player.Move(-1f); else if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamepadState.ThumbSticks.Left.X > 0) player.Move(1f); else player.Move(0f); } if (player.CanJump && jump) { if (currentGamepadState.IsButtonDown(Buttons.A) && previousGamepadState.IsButtonUp(Buttons.A)) player.Jump(); else if (currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z)) player.Jump(); } if (player.IsOverDoor) { if (currentGamepadState.ThumbSticks.Left.Y < 0 && previousGamepadState.ThumbSticks.Left.Y < 0 && player.Velocity.X == 0 ) player.EnterDoor(); else if (currentKeyboardState.IsKeyDown(Keys.Up) && previousKeyboardState.IsKeyUp(Keys.Up) && player.Velocity.X == 0 ) player.EnterDoor(); } if (currentGamepadState.IsButtonDown(Buttons.B) && previousGamepadState.IsButtonUp(Buttons.B)) player.Attack(gameTime); else if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) player.Attack(gameTime); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); PlayerTexture = Content.Load<Texture2D>("Textures/player"); MapTexture = Content.Load<Texture2D>("Textures/tiles"); EnemyTexture = Content.Load<Texture2D>("Textures/enemySheet"); DoorTexture = Content.Load<Texture2D>("Textures/door"); TextureSword = Content.Load<Texture2D>("Textures/sword"); BossTexture = Content.Load<Texture2D>("Textures/bossSheet"); Background = Content.Load<Texture2D>("Textures/background"); Song walkingSong = Content.Load<Song>("Audio/walking_flat"); SoundEffect jumpSfx = Content.Load<SoundEffect>("Audio/jump"); SoundEffect swordSfx = Content.Load<SoundEffect>("Audio/sword"); MediaPlayer.IsRepeating = true; MediaPlayer.Play(walkingSong); Animation playerAnimation = new Animation(PlayerTexture, Vector2.Zero, 90, 99, 3, 100, Color.White, 1f, true, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); player = new Player(playerAnimation, new Vector2(96 * 4, 96 * 3), jumpSfx, swordSfx, TextureSword); // Load Level Data levelData = new LevelData(); LevelChunkObjects = levelData.getLevel(MapTexture, EnemyTexture, BossTexture, DoorTexture, CurrentLevel); // Create a Blank white image WhiteRectangle = new Texture2D(GraphicsDevice, 1, 1); WhiteRectangle.SetData(new[] { Color.White }); }