EntityFactory.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using StarWarrior.Components;
  3. using Artemis;
  4. using Microsoft.Xna.Framework;
  5. namespace StarWarrior
  6. {
  7. public class EntityFactory {
  8. public static Entity CreateMissile(EntityWorld world)
  9. {
  10. Entity missile = world.CreateEntity();
  11. GamePool pool = (GamePool)world.GetPool();
  12. missile.SetGroup("BULLETS");
  13. missile.AddComponent(pool.TakeComponent<Transform>());
  14. missile.AddComponent(pool.TakeComponent<SpatialForm>());
  15. missile.AddComponent(pool.TakeComponent<Velocity>());
  16. missile.AddComponent(pool.TakeComponent<Expires>());
  17. missile.GetComponent<SpatialForm>().SetSpatialFormFile("Missile");
  18. missile.GetComponent<Expires>().SetLifeTime(2000);
  19. return missile;
  20. }
  21. public static Entity CreateEnemyShip(EntityWorld world) {
  22. Entity e = world.CreateEntity();
  23. e.SetGroup("SHIPS");
  24. GamePool pool = (GamePool)world.GetPool();
  25. e.AddComponent(pool.TakeComponent<Transform>());
  26. e.AddComponent(pool.TakeComponent<SpatialForm>());
  27. e.AddComponent(pool.TakeComponent<Health>());
  28. e.AddComponent(pool.TakeComponent<Weapon>());
  29. e.AddComponent(pool.TakeComponent<Enemy>());
  30. e.AddComponent(pool.TakeComponent<Velocity>());
  31. e.GetComponent<SpatialForm>().SetSpatialFormFile("EnemyShip");
  32. e.GetComponent<Health>().SetHealth(10);
  33. return e;
  34. }
  35. public static Entity CreateBulletExplosion(EntityWorld world, float x, float y)
  36. {
  37. Entity e = world.CreateEntity();
  38. GamePool pool = (GamePool)world.GetPool();
  39. e.SetGroup("EFFECTS");
  40. e.AddComponent(pool.TakeComponent<Transform>());
  41. e.AddComponent(pool.TakeComponent<SpatialForm>());
  42. e.AddComponent(pool.TakeComponent<Expires>());
  43. e.GetComponent<SpatialForm>().SetSpatialFormFile("BulletExplosion");
  44. e.GetComponent<Expires>().SetLifeTime(1000);
  45. e.GetComponent<Transform>().SetCoords(new Vector3(x, y, 0));
  46. return e;
  47. }
  48. public static Entity CreateShipExplosion(EntityWorld world, float x, float y)
  49. {
  50. Entity e = world.CreateEntity();
  51. GamePool pool = (GamePool)world.GetPool();
  52. e.SetGroup("EFFECTS");
  53. e.AddComponent(pool.TakeComponent<Transform>());
  54. e.AddComponent(pool.TakeComponent<SpatialForm>());
  55. e.AddComponent(pool.TakeComponent<Expires>());
  56. e.GetComponent<SpatialForm>().SetSpatialFormFile("ShipExplosion");
  57. e.GetComponent<Transform>().SetCoords(new Vector3(x, y, 0));
  58. e.GetComponent<Expires>().SetLifeTime(1000);
  59. return e;
  60. }
  61. }
  62. }