예제 #1
0
        public override void OnCollide(PhysicsEntity other)
        {
            other.AddForce(accelerationChange);
            if (HasParent)
            {
                parent.OnCollide(other);

                /* having problems
                 * if (other.Rect.Contains(parent.Rect))
                 * {
                 *  X = parentCentrer.X;
                 *  Y = parentCentrer.Y;
                 *  rectangle.Width = 0;
                 *  rectangle.Height = 0;
                 *  return;
                 * }
                 * if (other.X >= parentCentrer.X && other.X < rectangle.Width + X && other.X > X)
                 * {
                 *  rectangle.Width = X + (other.X - X);
                 * }
                 * else if (other.X >= parentCentrer.X && other.X + other.Rect.Width > X && other.X < X)
                 * {
                 *  rectangle.Width = 0;
                 * }
                 * else if (other.X + other.Rect.Width <= parentCentrer.X && other.X + other.Rect.Width < rectangle.Width + X && other.X + other.Rect.Width > X)
                 * {
                 *  rectangle.Width = other.X + other.Rect.Width + ((X+rectangle.Width) - (other.X + other.Rect.Width));
                 *  rectangle.X = other.X + other.Rect.Width;
                 * }
                 * else if (other.X + other.Rect.Width <= parentCentrer.X && other.X + other.Rect.Width > X + rectangle.Width && other.X > X)
                 * {
                 *  rectangle.Width = 0;
                 * }
                 *
                 * if (other.Y >= parentCentrer.Y && other.Y < rectangle.Height + Y && other.Y > Y)
                 * {
                 *  rectangle.Height = Y + (other.Y - Y);
                 * }
                 * else if (other.Y >= parentCentrer.Y && other.Y + other.Rect.Height > Y && other.Y < Y)
                 * {
                 *  rectangle.Height = 0;
                 * }
                 *
                 * else if (other.Y + other.Rect.Height <= parentCentrer.Y && other.Y + other.Rect.Height < rectangle.Height + Y && other.Y + other.Rect.Height > Y)
                 * {
                 *  rectangle.Height = other.Y + other.Rect.Height + ((Y + rectangle.Height) - (other.Y + other.Rect.Height));
                 *  rectangle.Y = other.Y + other.Rect.Height;
                 * }
                 * else if (other.Y + other.Rect.Height <= parentCentrer.Y && other.Y + other.Rect.Height > Y + rectangle.Height && other.Y > Y)
                 * {
                 *  rectangle.Height = 0;
                 * }
                 */
            }
        }
예제 #2
0
        /// <summary>
        /// when this bottle collides with some other physics entity
        /// </summary>
        /// <param name="other">the physics entity it has collided with</param>
        public override void OnCollide(PhysicsEntity other)
        {
            if (other is Player)//if the other object is the player, give the bottle to the player and no longer draw it
            {
                drawing      = false;
                isCollidable = false;
                player.bottlesOnHand++;
                player.Color = Color.DarkGreen;
                rm.Current.Colliders.Remove(this);
                rm.Current.Enemies.Remove(this);
                EntityIsRemoved();
            }
            if (thrown)//if it has been thrown determine what it has collided with and deal with it accordingly
            {
                if (!(other is EffectBox) && !(other is Button) && !(other is Player) && !(other is Fan) && !(other is Bottle) && !(other is Spikes) && (other.IsCollidable))
                {
                    drawing      = false;
                    isCollidable = false;
                    thrown       = false;
                    rm.Current.Colliders.Remove(this);
                    rm.Current.Enemies.Remove(this);
                }
                if (!(other is ForegroundTile) && !(other is Spikes) && !(other is PhaseBlock))
                {
                    if (other is PhysicsEntity && !(other is Player))
                    {
                        if (other is Enemy && !(other is Door))
                        {
                            (other as Enemy).GetHit();
                        }
                        other.acceleration = Vector2.Zero;
                        other.velocity     = new Vector2(this.velocity.X, 0);

                        other.AddForce(new Vector2((this.X < other.X) ? 5000 : -5000, 0));
                    }
                }
            }
        }