/// <summary> /// Subscribe the EventManager to all Sprite * Events /// </summary> /// <param name="e"></param> public void SubscribeAll(Sprite e) { // Every Sprite has Dispose e.Dispose += this.eventManager.Dispose; // Entitiy Specific Events if (e is Entity) { Entity v = (Entity)e; v.Collided += this.eventManager.Collided; } // BulletSpawner Specific Events if (e is BulletSpawner) { BulletSpawner b = (BulletSpawner)e; b.Fire += this.eventManager.Fire; } if (e is Boss2) { Boss2 b = (Boss2)e; b.NewSpawner += this.eventManager.ReadyEnqueue; } if (e is Boss1) { Boss1 b = (Boss1)e; b.NewSpawner += this.eventManager.ReadyEnqueue; } }
/// <summary> /// Directly add a spawner to this wave /// </summary> /// <param name="e"></param> /// <param name="wavetime_seconds"></param> public void AddSpawner(BulletSpawner e, int wavetime_seconds = -1) { if (lockwave == true) { throw new Exception("SpriteWave: wave already started. You cannot add more sprites"); } if (wavetime_seconds > -1) { e.WaveTimeSeconds = wavetime_seconds; } this.spawners.Add(e); }
//public void test_Add() //{ // Entity e = ef.CreateEnemy(EntityFactory.EntitiyType.Boss1); // e.Movement = mf.CreateMovement(MovementFactory.MovementType.Bounce, e); // e.Position = new Vector2(300, 300); // this.SubscribeAll(e); // this.entities.Add(e); //} /// <summary> /// Add a player to this game through the queue /// </summary> /// <param name="spawner"> Add a spawner as well? </param> public void AddPlayerOne(SpawnerFactory.SpawnerType spawner = SpawnerFactory.SpawnerType.None) { Entity player = ef.CreateEnemy(EntityFactory.EntitiyType.Player); player.MakeInvincible(3); player.Position = new Vector2(600, 600); GUIComponent plComponent = new PlayerLives(); eventManager.ReadyEnqueue(plComponent, new AddGUIEventArgs(plComponent, player)); eventManager.ReadyEnqueue(player, new AddPlayerEventArgs((Player)player)); if (spawner != SpawnerFactory.SpawnerType.None) { BulletSpawner s = this.sf.CreateSpawner(spawner, player); MirrorMovement m = (MirrorMovement)mf.CreateMovement(MovementFactory.MovementType.Mirror, player); m.ThisSprite = s; s.Movement = m; eventManager.ReadyEnqueue(s, new AddSpawnerEventArgs(player, s)); } }
public AddSpawnerEventArgs(Entity parent, BulletSpawner spawner) { this.parent = parent; this.spawner = spawner; }
/// <summary> /// Parse the spawners attribute of a wave /// </summary> /// <param name="spawners"></param> /// <param name="e"></param> /// <returns></returns> private static List <BulletSpawner> ParseSpawners(XmlNode spawners, Entity e) { List <BulletSpawner> new_spawners = new List <BulletSpawner>(); StandardSpawnerFactory sf = new StandardSpawnerFactory(); StandardMovementFactory mf = new StandardMovementFactory(); SpawnerFactory.SpawnerType stype = SpawnerFactory.SpawnerType.None; MovementFactory.MovementType spawner_mtype = MovementFactory.MovementType.Mirror; SpawnerFactory.BulletType btype = SpawnerFactory.BulletType.Green; Movement spawnermovement = null; double firerate = 1.0d; double bulletspeed = 7.0f; double bulletlifespan = 10.0f; int timesec = e.WaveTimeSeconds; BulletSpawner s = null; foreach (XmlNode att in spawners.ChildNodes) { LogConsole.Log(Environment.NewLine); foreach (XmlNode snode in att.ChildNodes) { switch (snode.Name) { case "timeseconds": timesec = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Wave time seconds: " + timesec.ToString()); break; case "spawnertype": stype = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Spawner type: " + stype.ToString()); break; case "firerate": firerate = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Firerate: " + firerate.ToString()); break; case "bullettype": btype = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Bullet type: " + btype.ToString()); break; case "spawnermovement": spawner_mtype = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Spawner movement type: " + spawner_mtype.ToString()); break; case "bulletspeed": bulletspeed = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Spawner bullet speed: " + bulletspeed.ToString()); break; case "bulletlifespan": bulletlifespan = TypeTable.Get(snode.Name, snode.InnerText); LogConsole.Log(" Parse:Spawner: Spawner bullet lifespan: " + bulletlifespan.ToString()); break; } } if (stype != SpawnerFactory.SpawnerType.None) { s = sf.CreateSpawner(stype, e, btype); s.BulletLifeSpan = (float)bulletlifespan; s.FireRateSeconds = firerate; s.BulletSpeed = (float)bulletspeed; s.WaveTimeSeconds = timesec; spawnermovement = mf.CreateMovement(spawner_mtype, e); spawnermovement.ThisSprite = s; s.Movement = spawnermovement; new_spawners.Add(s); } } return(new_spawners); }