EnemySpawnSystem.cs 898 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using Artemis;
  3. using StarWarrior.Components;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using System.Collections.Generic;
  6. namespace StarWarrior.Systems
  7. {
  8. public class EnemySpawnSystem : IntervalEntitySystem {
  9. private SpriteBatch spriteBatch;
  10. private Random r;
  11. public EnemySpawnSystem(int interval, SpriteBatch spriteBatch) : base(interval){
  12. this.spriteBatch = spriteBatch;
  13. }
  14. public override void Initialize() {
  15. r = new Random();
  16. }
  17. protected override void ProcessEntities(Dictionary<int, Entity> entities)
  18. {
  19. Entity e = EntityFactory.CreateEnemyShip(world);
  20. e.GetComponent<Transform>().SetLocation(r.Next(spriteBatch.GraphicsDevice.Viewport.Width), r.Next(400)+50);
  21. e.GetComponent<Velocity>().SetVelocity(0.05f);
  22. e.GetComponent<Velocity>().SetAngle(r.Next() % 2 == 0 ? 0 : 180);
  23. e.Refresh();
  24. }
  25. }
  26. }