Bullet.cs 647 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. namespace Tutorial006.Sprites
  9. {
  10. public class Bullet : Sprite
  11. {
  12. private float _timer;
  13. public Bullet(Texture2D texture)
  14. : base(texture)
  15. {
  16. }
  17. public override void Update(GameTime gameTime, List<Sprite> sprites)
  18. {
  19. _timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
  20. if (_timer >= LifeSpan)
  21. IsRemoved = true;
  22. Position += Direction * LinearVelocity;
  23. }
  24. }
  25. }