Example #1
0
        protected bool EnemyWithinRange(float radiusWidth, float radiusHeight)
        {
            bool withinRange = false;

            Field.ForEachActor <IActor>
            (
                actor =>
            {
                //Non-killable actors don't trigger the explosion
                IAffectedByBombExplosion killable = actor as IAffectedByBombExplosion;
                if (killable == null)
                {
                    return(false);
                }

                //The friendly fire is not wanted and thus by itself doesn't trigger the explosion
                if (actor is IEnemy)
                {
                    return(false);
                }

                //If there is a killable actor within range, we set the flag to true and stop searching for more
                if (actor.IntersectsWithin(X, radiusWidth, Y, radiusHeight))
                {
                    withinRange = true;
                    return(true);
                }
                return(false);
            }
            );
            return(withinRange);
        }
Example #2
0
        /// <summary>
        /// Overridable actions performed when the bomb has to explode.
        /// </summary>
        protected virtual void Explode()
        {
            Log.i(this, "Bomb exploding");

            //The explosion starts; if the bomb is already exploding, this function call is meaningless and duplicate.
            if (Exploding)
            {
                return;
            }
            Exploding = true;

            int affectedActors = 0;

            Field.ForEachActor <IActor>
            (
                actor =>
            {
                IAffectedByBombExplosion killable = actor as IAffectedByBombExplosion;
                if (killable == null)
                {
                    return(false);
                }

                //If there is a killable actor within the range of radius, he gets affected by the explosion
                if (actor.IntersectsWithin(X, RadiusWidth, Y, RadiusHeight))
                {
                    killable.OnBombExplosion(this);
                    affectedActors++;
                }
                return(false);
            }
            );

            AfterExplosion();
            Log.i(this, "Bomb has finished the explosion, affecting " + affectedActors + " actors");
        }