Player.cs 780 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. namespace Tutorial018.Sprites
  10. {
  11. public class Player : Sprite
  12. {
  13. public Player(GraphicsDevice graphicsDevice, Texture2D texture)
  14. : base(graphicsDevice, texture)
  15. {
  16. }
  17. public override void Update(GameTime gameTime)
  18. {
  19. if (Keyboard.GetState().IsKeyDown(Keys.W))
  20. Position.Y -= 3;
  21. if (Keyboard.GetState().IsKeyDown(Keys.S))
  22. Position.Y += 3;
  23. if (Keyboard.GetState().IsKeyDown(Keys.A))
  24. Position.X -= 3;
  25. if (Keyboard.GetState().IsKeyDown(Keys.D))
  26. Position.X += 3;
  27. }
  28. }
  29. }