Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        protected override bool Collide(MobileObject other)
        {
            // Players can walk through each other
            if (other is Player)
            {
                return(false);
            }


            else if (other is Bomb)
            {
                // TODO: kicking/punching
                return(true);
            }

            else if (other is Explosion)
            {
                // Players shouldn't die on the tiniest touch of the explosion.
                // Leave them half a field of room in each direction
                // -> this is respected here. The explosion itself is only in the
                //    center of the field, so a collision is only raised if
                //    we actually walk through the center!

                // see also Bomb.Explode
                Die();

                return(false);
            }

            else if (other is Powerup)
            {
                Powerup pup = (Powerup)other;
                pup.Affect(this);

                return(false);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <remarks>
        /// TODO: is this sensible? Here?
        /// </remarks>
        public void AddPlayer(Player player)
        {
            float x = player.X;
            float y = player.Y;
            float w = player.Width;
            float h = player.Height;

            for (int i = 0; i < Items.Count; ++i)
            {
                MobileObject other = Items[i];
                if (other == player)
                {
                    continue;
                }
                if (new RectangleF(x + 0.5f * w - 1.0f, y + 0.5f * h - 1.0f, 2.0f, 2.0f).IntersectsWith(new RectangleF(other.Position, other.Size)) &&
                    !(other is Stone) && !(other is Player))
                {
                    System.Console.WriteLine("Removing a " + other + " from (" + other.X + ", " + other.Y + ")");
                    Items.Remove(other);
                    --i;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 protected override bool Collide(MobileObject other)
 {
     return(true);
 }
Beispiel #4
0
        private bool IsExplosionStopper(Board board, int x, int y, List <Bomb> triggeredBombs)
        {
            bool       result = false;
            RectangleF rect   = new RectangleF(x, y, 1.0f, 1.0f);

            for (int i = 0; i < board.Items.Count; ++i)
            {
                MobileObject obj = board.Items[i];

                if (rect.IntersectsWith(new RectangleF(obj.Position, obj.Size)))
                {
                    if (obj is Wall)
                    {
                        ((Wall)obj).Explode();
                        System.Console.WriteLine("Explosion hit wall at ({0}, {1})", x, y);
                        result = true;
                    }

                    else if (obj is Stone)
                    {
                        System.Console.WriteLine("Explosion stopped by stone at ({0}, {1})", x, y);
                        return(true);
                    }

                    else if (obj is Player)
                    {
                        // TRYTRY/HACKHACK: this is necessary. And a relatively nice way
                        //                  of doing it. But can we still improve that?

                        // Players shouldn't die on the tiniest touch of the explosion.
                        // Leave them half a field of room in each direction

                        // NOTE: an analogous check has to happen in Player.Collide
                        if (rect.Contains(obj.X + 0.5f, obj.Y + 0.5f))
                        {
                            ((Player)obj).Die();
                        }
                    }
                    else if (obj is Powerup)
                    {
                        board.Items.RemoveAt(i--);
                    }

                    else if (obj is Bomb && obj != this)
                    {
                        triggeredBombs.Add(((Bomb)obj));

                        // A bomb stops an explosion.
                        // Yes, that means bombs with short range stop explosions
                        // with much larger range. That is desired behaviour!
                        // (At least that's how it works in AB) TRYTRY
                        return(true);
                    }

                    else if (obj is Explosion)
                    {
                        return(true);
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 protected override bool Collide(MobileObject other)
 {
     // powerups shouldn't move, so they really shouldn't collide with anything
     throw new System.InvalidOperationException("Powerup colliding with " + other);
 }
Beispiel #6
0
 /// <summary>
 /// When overridden in a derived class, handles collision with
 /// another object.
 /// </summary>
 /// <param name="other">
 /// the object with which a collision is occuring
 /// </param>
 /// <returns>
 /// <c>false</c> if the object can move on,
 /// <c>true</c> if the collision caused the object to stop
 /// </returns>
 protected abstract bool Collide(MobileObject other);