Ship.cs 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Tutorial020.Sprites
  9. {
  10. public class Ship : Sprite, ICollidable
  11. {
  12. public int Health { get; set; }
  13. public Bullet Bullet { get; set; }
  14. public float Speed;
  15. public Ship(Texture2D texture) : base(texture)
  16. {
  17. }
  18. protected void Shoot(float speed)
  19. {
  20. var bullet = Bullet.Clone() as Bullet;
  21. bullet.Position = this.Position;
  22. bullet.Colour = this.Colour;
  23. bullet.Layer = 0.1f;
  24. bullet.LifeSpan = 5f;
  25. bullet.Velocity = new Vector2(speed, 0f);
  26. bullet.Parent = this;
  27. Children.Add(bullet);
  28. }
  29. public virtual void OnCollide(Sprite sprite)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. }
  34. }