コード例 #1
0
        /// <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]);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Registers a collision between two passed in Entities by adding a
        /// reference to the other Entity in its Collision Component. If the Entity
        /// does not have a Collision Component, one is added.
        /// </summary>
        /// <param name="entOne">The first Entity in the collision.</param>
        /// <param name="entTwo">The second Entity in the collision..</param>
        private void RegisterCollision(ulong entOne, ulong entTwo)
        {
            CCollision entOneCollision;
            CCollision entTwoCollision;

            //Handle collision for the first Entity
            if (!World.EntityHasComponent(entOne, typeof(CCollision)))
            {
                World.AddComponent(entOne, new CCollision(entTwo));
            }
            else
            {
                entOneCollision = World.GetComponent <CCollision>(entOne);
                entOneCollision.AddCollision(entTwo);
            }

            //Handle collision for the second Entity
            if (!World.EntityHasComponent(entTwo, typeof(CCollision)))
            {
                World.AddComponent(entTwo, new CCollision(entOne));
            }
            else
            {
                entTwoCollision = World.GetComponent <CCollision>(entTwo);
                entTwoCollision.AddCollision(entOne);
            }
        }
        public override void Process()
        {
            CCollision collision;
            CFrozen    freezeZoneFrozen;
            CFrozen    collidedFrozen;

            List <int> deadFreezeEffects = new List <int>();

            /// <summary>
            /// This loop represents each Freeze Zone.
            /// Backwards loop to allow Entities to be removed while looping.
            /// </summary>
            for (int i = Entities.Count - 1; i >= 0; i--)
            {
                freezeZoneFrozen = World.GetComponent <CFrozen>(Entities[i]);
                collision        = World.GetComponent <CCollision>(Entities[i]);

                /// <summary>
                /// This loop represents each Entity colliding with the Freeze Zone.
                /// </summary>
                for (int j = 0; j < collision.Count; j++)
                {
                    //If not already Frozen, add a Frozen Component.
                    if (!World.EntityHasComponent(collision[j], typeof(CFrozen)))
                    {
                        //Don't freeze projectiles
                        if (!World.EntityHasComponent(collision[j], typeof(CProjectile)))
                        {
                            World.AddComponent(collision[j], new CFrozen(freezeZoneFrozen.Duration, World.GameTime));
                        }

                        if (!World.EntityHasComponent(collision[j], typeof(CGotStatusEffect)))
                        {
                            World.AddComponent(collision[j], new CGotStatusEffect(typeof(CFrozen)));
                        }
                        else
                        {
                            CGotStatusEffect statusEffects = World.GetComponent <CGotStatusEffect>(collision[j]);
                            statusEffects.AddEffect(typeof(CFrozen));
                        }
                    }
                    else //If already Frozen, refresh the duration.
                    {
                        collidedFrozen             = World.GetComponent <CFrozen>(collision[i]);
                        collidedFrozen.TimeApplied = World.GameTime;
                    }
                }

                /// <summary>
                /// Freeze Zone only lasts for one frame to apply Frozen Components.
                /// Each Freeze Zone is removed from the World once its collisions are processed.
                /// </summary>
                World.RemoveEntity(Entities[i]);
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks each Entity colliding with each Poison Zone. If the Entity does not have
        /// a Poison Component, then a Poison Component and a GotStatusEffect Component are added.
        /// Otherwise, the Entity's Poison Component duration is refreshed.
        /// </summary>
        public override void Process()
        {
            CPoison    poisonEffect;
            CPoison    targetPoisonEffect;
            CCollision collision;

            /// <summary>
            /// This loop represents each Poison Zone.
            /// </summary>
            for (int i = 0; i < Entities.Count; i++)
            {
                poisonEffect = World.GetComponent <CPoison>(Entities[i]);
                collision    = World.GetComponent <CCollision>(Entities[i]);

                /// <summary>
                /// This loop represents each Entity colliding with the Poison Zone.
                /// </summary>
                for (int j = 0; j < collision.Count; j++)
                {
                    if (!World.EntityHasComponent(collision[j], typeof(CPoison)))
                    {
                        World.AddComponent(collision[j], new CPoison(poisonEffect.Strength, poisonEffect.Duration, World.GameTime));

                        if (!World.EntityHasComponent(collision[j], typeof(CGotStatusEffect)))
                        {
                            World.AddComponent(collision[j], new CGotStatusEffect(typeof(CPoison)));
                        }
                        else
                        {
                            CGotStatusEffect statusEffects = World.GetComponent <CGotStatusEffect>(collision[j]);
                            statusEffects.AddEffect(typeof(CPoison));
                        }
                    }
                    else //If entity already has a Poison Component, refresh its duration.
                    {
                        targetPoisonEffect             = World.GetComponent <CPoison>(collision[j]);
                        targetPoisonEffect.TimeApplied = World.GameTime;
                    }
                }
            }
        }