Bullet.cs 1.5 KB

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