Esempio n. 1
0
        private static void WidthGreaterThanHeight(IEnemy enemy, IBlock item, Rectangle collisionRectangle, ISprite block)
        {
            if (collisionRectangle.Right == block.Area(item.Location).Right)
            {
                enemy.MovingLeft = false;
                enemy.ChangeDirection();
                enemy.Location = new Vector2(enemy.Location.X + collisionRectangle.Width, enemy.Location.Y);
            }
            else if (collisionRectangle.Left == block.Area(item.Location).Left)
            {
                enemy.MovingLeft = true;
                enemy.ChangeDirection();
                enemy.Location = new Vector2(enemy.Location.X - (collisionRectangle.Width), enemy.Location.Y);
            }
            collisionRectangle = Rectangle.Intersect(enemy.Sprite.Area(enemy.Location), block.Area(item.Location));

            if (collisionRectangle.Bottom == block.Area(item.Location).Bottom)
            {
                enemy.Location = new Vector2(enemy.Location.X, enemy.Location.Y + collisionRectangle.Height + 3);
            }
            else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
            {
                enemy.Location  = new Vector2(enemy.Location.X, enemy.Location.Y - (collisionRectangle.Height + 3));
                enemy.IsFalling = false;
            }
        }
        public static void HandleCollision(IEnemy enemy, IEnemy item)
        {
            if (!(enemy is Missle) && !(enemy is Octopus) && !(enemy is Nami) && !(item is Missle) && !(item is Octopus) && !(item is Nami))
            {
                ISprite   block = item.Sprite;
                Rectangle collisionRectangle = Rectangle.Intersect(enemy.Sprite.Area(enemy.Location), block.Area(item.Location));
                if (collisionRectangle.Bottom == block.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    enemy.Location = new Vector2(enemy.Location.X, enemy.Location.Y + collisionRectangle.Height + 1);
                }
                else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    enemy.Location  = new Vector2(enemy.Location.X, enemy.Location.Y - (collisionRectangle.Height + 1));
                    enemy.IsFalling = false;
                }

                else if (collisionRectangle.Right == enemy.Sprite.Area(enemy.Location).Right)
                {
                    enemy.MovingLeft = true;
                    item.MovingLeft  = false;
                    enemy.ChangeDirection();
                    item.ChangeDirection();
                    enemy.Location = new Vector2(enemy.Location.X - (collisionRectangle.Width), enemy.Location.Y);
                }
                else if (collisionRectangle.Left == enemy.Sprite.Area(enemy.Location).Left)
                {
                    enemy.MovingLeft = false;
                    item.MovingLeft  = true;
                    enemy.ChangeDirection();
                    item.ChangeDirection();
                    enemy.Location = new Vector2(enemy.Location.X + (collisionRectangle.Width), enemy.Location.Y);
                }
            }
        }
        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);
            }
        }
Esempio n. 5
0
        public static void HandleCollision(IItem powerup, IBlock item)
        {
            ISprite block = item.Sprite;

            if (!(item is Sun))
            {
                Rectangle collisionRectangle = Rectangle.Intersect(powerup.Sprite.Area(powerup.Location), block.Area(item.Location));
                if (collisionRectangle.Bottom == block.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    powerup.Location = new Vector2(powerup.Location.X, powerup.Location.Y + collisionRectangle.Height + 2);
                }
                else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
                {
                    if (powerup is Star)
                    {
                        powerup.Location = new Vector2(powerup.Location.X, powerup.Location.Y - (collisionRectangle.Height + 50));
                    }
                    else
                    {
                        powerup.Location = new Vector2(powerup.Location.X, powerup.Location.Y - (collisionRectangle.Height + 2));
                    }
                    powerup.IsFalling = false;
                }

                collisionRectangle = Rectangle.Intersect(powerup.Sprite.Area(powerup.Location), block.Area(item.Location));
                if (collisionRectangle.Right == block.Area(item.Location).Right)
                {
                    powerup.Location   = new Vector2(powerup.Location.X + collisionRectangle.Width + 1, powerup.Location.Y);
                    powerup.MovingLeft = false;
                }
                else if (collisionRectangle.Left == block.Area(item.Location).Left)
                {
                    powerup.Location   = new Vector2(powerup.Location.X - (collisionRectangle.Width + 1), powerup.Location.Y);
                    powerup.MovingLeft = true;
                }
            }
        }
Esempio n. 6
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();
            }
        }
        public static void HandleCollision(IProjectile projectile, IBlock item)
        {
            ISprite   block = item.Sprite;
            Rectangle collisionRectangle = Rectangle.Intersect(projectile.Area(), block.Area(item.Location));

            if (collisionRectangle.Bottom == block.Area(item.Location).Bottom&& collisionRectangle.Width > collisionRectangle.Height)
            {
                projectile.KillFireball();
            }
            else if (collisionRectangle.Top == block.Area(item.Location).Top&& collisionRectangle.Width > collisionRectangle.Height)
            {
                projectile.LocationY = projectile.LocationY - (collisionRectangle.Height + 45);
            }

            collisionRectangle = Rectangle.Intersect(projectile.Area(), block.Area(item.Location));
            if (collisionRectangle.Right == block.Area(item.Location).Right)
            {
                projectile.KillFireball();
            }
            else if (collisionRectangle.Left == block.Area(item.Location).Left)
            {
                projectile.KillFireball();
            }
        }
Esempio n. 8
0
        public static void HandleCollision(IEnemy enemy, IBlock item)
        {
            ISprite   block = item.Sprite;
            Rectangle collisionRectangle = Rectangle.Intersect(enemy.Sprite.Area(enemy.Location), block.Area(item.Location));

            if (!(enemy is Missle) && !(enemy is Octopus) && !(enemy is Nami))
            {
                if (collisionRectangle.Width > collisionRectangle.Height)
                {
                    HeightGreaterThanWidth(enemy, item, collisionRectangle, block);
                }
                else
                {
                    WidthGreaterThanHeight(enemy, item, collisionRectangle, block);
                }
            }
        }