private static void HeightSmallerThanWidth(IMario mario, IBlock item, Rectangle collisionRectangle, ISprite block)
        {
            if (block.Area(item.Location).Top > mario.Area().Top)
            {
                Mario.GroundedStatus = true;
                Mario.DisableJump    = false;
                Mario.JumpStatus     = false;
                Mario.LocationY     -= (collisionRectangle.Height);
                MarioAndEnemyCollisionHandling.SetBonusPoint(false);
                Mario.ResetVelocity();
                writeCollision(mario.Area(), block.Area(item.Location), "bottom");
            }
            else if (block.Area(item.Location).Top <= mario.Area().Top)
            {
                Mario.LocationY += collisionRectangle.Height;
                Mario.ResetVelocity();
                block.CollisionSprite();
                item.BecomeUsed();
                writeCollision(mario.Area(), block.Area(item.Location), "top");
            }

            collisionRectangle = Rectangle.Intersect(mario.Area(), block.Area(item.Location));
            if (collisionRectangle.Right == block.Area(item.Location).Right)
            {
                Mario.LocationX += collisionRectangle.Width + 1;
                writeCollision(mario.Area(), block.Area(item.Location), "left");
            }
            else if (collisionRectangle.Left == block.Area(item.Location).Left)
            {
                Mario.LocationX -= (collisionRectangle.Width + 1);
                writeCollision(mario.Area(), block.Area(item.Location), "right");
            }
        }
        public static void HandleCollision(IMario mario, IBlock item)
        {
            Rectangle collisionRectangle = new Rectangle();
            ISprite   block = item.Sprite;

            if (item is FlagPole)
            {
                item.BecomeUsed();
            }
            if (block.Area(item.Location).Equals(collisionRectangle))
            {
                return;
            }
            collisionRectangle = Rectangle.Intersect(mario.Area(), block.Area(item.Location));
            if ((collisionRectangle.Width <= collisionRectangle.Height))
            {
                WidthSmallerThanHeight(mario, item, collisionRectangle, block);
            }
            else
            {
                HeightSmallerThanWidth(mario, item, collisionRectangle, block);
            }
        }
예제 #3
0
        public static void HandleCollision(IMario mario, IEnemy item)
        {
            ISprite   enemy = item.Sprite;
            Rectangle collisionRectangle = Rectangle.Intersect(mario.Area(), enemy.Area(item.Location));

            if (collisionRectangle.Top == enemy.Area(item.Location).Top&& collisionRectangle.Width + 2 > collisionRectangle.Height)
            {
                CollideTop(mario, item);
            }
            else if (collisionRectangle.Bottom == enemy.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
            {
                CollideBottom(mario, item, collisionRectangle);
            }
            else if (collisionRectangle.Right == enemy.Area(item.Location).Right)
            {
                CollideRight(mario, item, collisionRectangle);
                item.ChangeDirection();
            }
            else if (collisionRectangle.Left == enemy.Area(item.Location).Left)
            {
                CollideLeft(mario, item, collisionRectangle);
                item.ChangeDirection();
            }
        }