Bullet.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //---------------------------------------------------------------------------------
  2. // Written by Michael Hoffman
  3. // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
  4. //----------------------------------------------------------------------------------
  5. using System;
  6. using System.Linq;
  7. using AtomicEngine;
  8. namespace AtomicBlaster
  9. {
  10. class Bullet : Entity
  11. {
  12. private static Random rand = new Random();
  13. public Bullet(Vector2 position, Vector2 velocity)
  14. {
  15. image = Art.Bullet;
  16. Position = position;
  17. Velocity = velocity;
  18. Orientation = Velocity.ToAngle();
  19. Radius = 8;
  20. }
  21. public override void Update()
  22. {
  23. if (Velocity.LengthSquared > 0)
  24. Orientation = Velocity.ToAngle();
  25. Position += Velocity;
  26. GameRoot.Grid.ApplyExplosiveForce(0.5f * Velocity.Length, Position, 80);
  27. // delete bullets that go off-screen
  28. if (!GameRoot.ScreenBounds.Contains(Position))
  29. {
  30. IsExpired = true;
  31. for (int i = 0; i < 30; i++)
  32. GameRoot.ParticleManager.CreateParticle(Art.LineParticle, Position, Color.LightBlue, 50, 1,
  33. new ParticleState() { Velocity = rand.NextVector2(0, 9), Type = ParticleType.Bullet, LengthMultiplier = 1 });
  34. }
  35. }
  36. }
  37. }