/// <summary> /// Evaluates the state of each Explosion Man. Two key events occur with Explosion Men: /// -When the Spawn Animation finishes, the explosion is created. /// -When the Explosion Animation finishes, the Entity is removed. /// This System checks the state and animation of each Explosion Man. /// </summary> public override void Process() { CExplosionMan explosion; CAnimation anim; CPosition pos; for (int i = Entities.Count - 1; i >= 0; i--) { anim = World.GetComponent <CAnimation>(Entities[i]); /// <summary> /// If one of the two key events are happening. /// </summary> if (SwinGame.AnimationEnded(anim.Anim)) { explosion = World.GetComponent <CExplosionMan>(Entities[i]); /// <summary> /// If not ready to explode, the Spawn animation has just finished. /// Therefore, create the explosion. /// </summary> if (!explosion.ReadyToExplode) { explosion.ReadyToExplode = true; pos = World.GetComponent <CPosition>(Entities[i]); /// <summary> /// Update size details as the Entity is now an Explosion. /// </summary> pos.Width = EntityFactory.EXPLOSION_SIZE; pos.Height = EntityFactory.EXPLOSION_SIZE; /// <summary> /// Adjust position details so explosion is in centre of the cell. /// </summary> CollisionCheckSystem collisions = World.GetSystem <CollisionCheckSystem>(); Point2D cellPos = collisions.CentreOfCell(explosion.TargetCell); pos.X = cellPos.X - (pos.Width / 2); pos.Y = cellPos.Y - (pos.Height / 2); /// <summary> /// Create explosion animation. /// </summary> anim.Img = SwinGame.BitmapNamed("Explosion"); SwinGame.AssignAnimation(anim.Anim, "Explode", anim.AnimScript); /// <summary> /// Add new components to the Entity. /// </summary> World.AddComponent(Entities[i], new CDamagesOnImpact(false)); World.AddComponent(Entities[i], new CDamage(EntityFactory.EXPLOSION_DAMAGE)); World.AddComponent(Entities[i], new CCollidable()); } else //If ready to explode, the Explode animation has just finished. Therefore, remove the Entity. { World.RemoveEntity(Entities[i]); } } } }
/// <summary> /// Creates an Entity with all Components for an Explosion Man and adds it to the World. /// This Entity represents the exploding wizard the Player can purchase. /// </summary> public static void CreateExplosionMan() { //Create Entity and add to world ulong newEntity = _world.NextEntityID; /// <summary> /// Identifies the most populated Enemy Spatial Hash Cell. The Explosion man /// will be spawned at the centre of this cell. /// </summary> CollisionCheckSystem collChkSys = World.GetSystem <CollisionCheckSystem>(); int mostPopulatedCell = collChkSys.EnemyCells.Aggregate((l, r) => l.Value.Count > r.Value.Count ? l : r).Key; Point2D pos = collChkSys.CentreOfCell(mostPopulatedCell); /// <summary> /// Adjust position for Sprite size so Explosion Man spawns at centre. /// </summary> float atX = pos.X - (EXPLOSION_MAN_SIZE / 2); float atY = pos.Y - (EXPLOSION_MAN_SIZE / 2); /// <summary> /// Animation details for Animation component. /// </summary> Bitmap bmp = SwinGame.BitmapNamed("ExplosionMan"); Animation anim = SwinGame.CreateAnimation("Spawn", SwinGame.AnimationScriptNamed("ExplosionAnim")); AnimationScript animScript = SwinGame.AnimationScriptNamed("ExplosionAnim"); //Create components and pass to world to send to Systems List <Component> components = new List <Component>(); components.Add(new CPlayerTeam()); components.Add(new CPosition(atX, atY, EXPLOSION_MAN_SIZE)); components.Add(new CAnimation(bmp, anim, animScript)); components.Add(new CExplosionMan(mostPopulatedCell)); _world.AddEntity(newEntity, components); }