Player.cs 687 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 Tutorial023.Sprites
  10. {
  11. public class Player : Sprite
  12. {
  13. public Vector2 Velocity;
  14. public Player(Texture2D texture)
  15. : base(texture)
  16. {
  17. }
  18. public override void Update(GameTime gameTime)
  19. {
  20. if (Keyboard.GetState().IsKeyDown(Keys.D))
  21. Velocity.X = 3f;
  22. else if (Keyboard.GetState().IsKeyDown(Keys.A))
  23. Velocity.X = -3f;
  24. else
  25. Velocity.X = 0f;
  26. }
  27. }
  28. }