public static void HandleCollision(IEnemy enemy, IBlock block, Game1.Side side)
        {
            EnemyGravityHandler gravity = new EnemyGravityHandler();

            if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))// || side.Equals(Game1.Side.Top))
            {
                if (block.IsHit())
                {
                    enemy.BeFlipped();
                    gravity.ApplyGravityToEnemy(enemy);
                }


                else if (block is UnbreakableBlock)
                {
                    enemy.ChangeDirection();
                }
            }

            else if (side.Equals(Game1.Side.Bottom))
            {
                if (block.IsHit())
                {
                    enemy.BeFlipped();
                    gravity.ApplyGravityToEnemy(enemy);
                    Display.UpdateKilledEnemy();
                }

                enemy.ManualMoveY(-1 * enemy.GetVerticalVelocity());
            }
        }
Exemple #2
0
        public static void EnemyHandler(IItem item, IEnemy enemy, int CollisionSide)
        {
            if (item.isVisible && !(enemy.enemySprite is GoombaStompedSprite) && !(enemy.enemySprite is KoopaStompedSprite) && item.itemSprite is FireballSprite)
            {
                switch (CollisionSide)
                {
                case 1:
                    item.isVisible = false;
                    enemy.BeFlipped();
                    MarioSoundManager.instance.playSound(MarioSoundManager.KICK);
                    break;

                case 2:
                    item.isVisible = false;
                    enemy.BeFlipped();
                    MarioSoundManager.instance.playSound(MarioSoundManager.KICK);
                    break;

                case 3:
                    item.isVisible = false;
                    enemy.BeFlipped();
                    MarioSoundManager.instance.playSound(MarioSoundManager.KICK);
                    break;

                case 4:
                    item.isVisible = false;
                    enemy.BeFlipped();
                    MarioSoundManager.instance.playSound(MarioSoundManager.KICK);
                    break;
                }
            }
        }
        public static void EnemyHandler(IEnemy enemy1, IEnemy enemy2, int CollisionSide)
        {
            Vector2 newPosition;
            int     TWO = 2;

            if (!(enemy2.enemySprite is GoombaStompedSprite) && enemy2.isVisible && !(enemy1.enemySprite is GoombaStompedSprite) && enemy1.isVisible)
            {
                switch (CollisionSide)
                {
                case 1:

                    break;

                case 2:
                    newPosition.X   = enemy1.enemySprite.desRectangle.X + TWO;
                    newPosition.Y   = enemy1.enemySprite.desRectangle.Y;
                    enemy1.position = newPosition;
                    if (enemy1 is Koopa)
                    {
                        if (enemy1.shellDirection)
                        {
                            enemy2.BeFlipped();
                        }
                        else
                        {
                            enemy2.ChangeDirection();
                        }
                    }
                    enemy1.ChangeDirection();
                    break;

                case 3:

                    break;

                case 4:
                    newPosition.X   = enemy1.enemySprite.desRectangle.X - TWO;
                    newPosition.Y   = enemy1.enemySprite.desRectangle.Y;
                    enemy1.position = newPosition;
                    if (enemy1 is Koopa)
                    {
                        if (enemy1.shellDirection)
                        {
                            enemy2.BeFlipped();
                        }
                        else
                        {
                            enemy2.ChangeDirection();
                        }
                    }
                    enemy1.ChangeDirection();
                    break;
                }
            }
        }
 public void CollisionWithEnemy(IEnemy enemy, Direction direction)
 {
     EnemyBlockHandler.UpateLocation(enemy, this, direction);
     if (direction == Direction.Top)
     {
         enemy.BeFlipped();
     }
 }
        public static void HandleCollision(IItem koopaShell, IEnemy enemy, Game1.Side side)
        {
            KoopaShell shell = (KoopaShell)koopaShell;

            if (shell.isHit)
            {
                if (!side.Equals(Game1.Side.None))
                {
                    enemy.BeFlipped();
                }
            }
        }
Exemple #6
0
 public static void HandleFireballEnemyCollision(Fireball fireball, IEnemy enemy)
 {
     if (enemy.Collidable)
     {
         if (enemy is Jellyfish || enemy is Fish)
         {
             fireball.Dead = true;
             enemy.BeFlipped();
             TreeNewBee.SuperMarioBros.Instance.ScManager.Score += Constant.Constant.Instance.FireballKillEnemyReward;
         }
         else
         {
             fireball.Dead = true;
             enemy.BeStomped();
             TreeNewBee.SuperMarioBros.Instance.ScManager.Score += Constant.Constant.Instance.FireballKillEnemyReward;
         }
     }
 }
Exemple #7
0
        public static void HandleCollision(IPlayer marioPlayer, IEnemy enemy, Game1.Side side)
        {
            Mario mario = (Mario)marioPlayer;

            if (!mario.IsInSpecialAnimationState())
            {
                if (mario.IsStarMario() && !side.Equals(Game1.Side.None))
                {
                    enemy.BeFlipped();
                }
                else if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right) || side.Equals(Game1.Side.Top))
                {
                    mario.TakeDamage();
                }
                //case mario on enemy
                else if (side.Equals(Game1.Side.Bottom))
                {
                    int bounceVelocity = -4;
                    // case enemy is goomba
                    if (enemy is Goomba)
                    {
                        Goomba localGoomba = (Goomba)enemy;
                        localGoomba.KillEnemy();

                        mario.SetVerticalVelocity(bounceVelocity);
                    }
                    if (enemy is Koopa)
                    {
                        Koopa localKoopa = (Koopa)enemy;

                        localKoopa.KillEnemy();
                        mario.SetVerticalVelocity(bounceVelocity);
                    }

                    if (!WorldManager.spriteSet.players[0].GetTouchedGround())
                    {
                        WorldManager.spriteSet.players[0].IncrementEnemyMultiplier();
                    }
                }
            }
        }
 private static void MarioGoombaCollision(IMario mario, IEnemy enemy, CollisionSide side)
 {
     if (mario.MarioPowerUpState is MarioSmallInvincibleState || mario.MarioPowerUpState is MarioSuperInvincibleState)
     {
         enemy.BeFlipped();
     }
     else
     {
         if (side == CollisionSide.Top && enemy.Collidable)
         {
             enemy.BeStomped();
             SoundFactory.Instance.CreateStompSound();
             TreeNewBee.SuperMarioBros.Instance.ScManager.Score += Constant.Instance.HitGoombaReward;
         }
         else
         {
             if (!(enemy.State is GoombaFlippedState || enemy.State is GoombaStompedState))
             {
                 mario.TakeDamage();
             }
         }
     }
 }
 public void EnemyBlockCollision(Mario mario, IEnemy enemy, List <IBlock> envElements)
 {
     enemy.gravity = 3;
     foreach (IBlock block in envElements)
     {
         if (block.isVisible)
         {
             if (enemy.enemySprite.desRectangle.Bottom > block.position.Y - 5 && enemy.enemySprite.desRectangle.Bottom <= block.position.Y)
             {
                 if (enemy.enemySprite.desRectangle.Right > block.position.X + 3 && enemy.enemySprite.desRectangle.Left < block.blockSprite.desRectangle.Right - 3)
                 {
                     if (!enemy.flip)
                     {
                         if (mario.state.marioSprite.desRectangle.Intersects(block.blockSprite.desRectangle) && mario.marioState != Mario.MARIO_SMALL && block.blockSprite is BrickBlockSprite)
                         {
                             enemy.BeFlipped();
                             //score part
                             mario.isScored    = true;
                             mario.score       = GameConstants.Score1;
                             mario.totalScore += mario.score;
                             Vector2 newP;
                             newP.X             = block.blockSprite.desRectangle.X + GameConstants.Twelve;
                             newP.Y             = block.blockSprite.desRectangle.Y - GameConstants.Three;
                             mario.textPosition = newP;
                         }
                         enemy.gravity = 0;
                     }
                 }
             }
         }
         if (enemy.enemySprite.desRectangle.Intersects(block.blockSprite.desRectangle))
         {
             firstRectangle   = enemy.enemySprite.desRectangle;
             secondRectangle  = block.blockSprite.desRectangle;
             collideRectangle = Rectangle.Intersect(firstRectangle, secondRectangle);
             if (collideRectangle.Width > collideRectangle.Height)
             {
                 if (firstRectangle.Top > secondRectangle.Top)
                 {
                     SIDE = GameConstants.Bottom;
                 }
                 else
                 {
                     SIDE = GameConstants.Top;
                 }
             }
             else if (collideRectangle.Width <= collideRectangle.Height)
             {
                 if (firstRectangle.Left > secondRectangle.Left)
                 {
                     SIDE = GameConstants.Right;
                 }
                 else
                 {
                     SIDE = GameConstants.Left;
                 }
             }
             if (collideRectangle.Width * collideRectangle.Height > GameConstants.Eleven + GameConstants.Two)
             {
                 EnemyBlockHandler.BlockHandler(enemy, block, SIDE);
             }
         }
     }
 }
        public static void EnemyHandler(Mario mario, IEnemy enemy, int CollisionSide)
        {
            int     THREE = 3;
            int     SIX   = 6;
            Vector2 newPosition;

            if (!(enemy.enemySprite is GoombaFlippedSprite) && !(enemy.enemySprite is GoombaStompedSprite) && !(enemy.enemySprite is KoopaFlippedSprite))
            {
                switch (CollisionSide)
                {
                case 1:
                    if (mario.HasStarPower)
                    {
                        enemy.BeFlipped();
                        //score
                        mario.isScored    = true;
                        mario.score       = GameConstants.Score1;
                        mario.totalScore += mario.score;
                        Vector2 newP;
                        newP.X             = mario.position.X;
                        newP.Y             = mario.position.Y - THREE;
                        mario.textPosition = newP;
                    }
                    else
                    {
                        if (mario.state.marioSprite.desRectangle.Bottom > enemy.enemySprite.desRectangle.Top)
                        {
                            mario.bounce = true;
                            MarioSoundManager.instance.playSound(MarioSoundManager.STOMP);
                            enemy.BeStomped();
                            if (!(enemy.shellDirection))
                            {
                                mario.isScored    = true;
                                mario.score       = GameConstants.Score1;
                                mario.totalScore += mario.score;
                                Vector2 newP;
                                newP.X             = mario.position.X;
                                newP.Y             = mario.position.Y - THREE;
                                mario.textPosition = newP;
                            }
                        }
                        else if (enemy.enemySprite is KoopaStompedSprite)
                        {
                            if (enemy.shellDirection)
                            {
                                mario.MarioGetHit();
                            }
                            else
                            {
                                if (mario.marioDirection)
                                {
                                    enemy.shellDirection = true;
                                    enemy.shellMoving    = GameConstants.Left;
                                }
                                else
                                {
                                    enemy.shellDirection = true;
                                    enemy.shellMoving    = GameConstants.Right;
                                }
                            }
                        }
                    }
                    break;

                case 2:
                    if (mario.HasStarPower)
                    {
                        enemy.BeFlipped();
                        //score
                        mario.isScored = true;
                        mario.score    = GameConstants.Score1;
                        Vector2 newP;
                        newP.X             = mario.position.X;
                        newP.Y             = mario.position.Y - THREE;
                        mario.textPosition = newP;
                    }
                    else
                    {
                        if (enemy.enemySprite is KoopaStompedSprite)
                        {
                            if (enemy.shellDirection)
                            {
                                mario.MarioGetHit();
                            }
                            else
                            {
                                if (mario.position.X < enemy.position.X)
                                {
                                    newPosition.X  = mario.position.X - SIX;
                                    newPosition.Y  = mario.position.Y;
                                    mario.position = newPosition;
                                }
                                else
                                {
                                    newPosition.X  = mario.position.X + SIX;
                                    newPosition.Y  = mario.position.Y;
                                    mario.position = newPosition;
                                }

                                enemy.shellDirection = true;
                                enemy.shellMoving    = GameConstants.Right;
                            }
                        }
                        else
                        {
                            mario.MarioGetHit();
                        }
                    }
                    break;

                case 3:
                    if (mario.HasStarPower)
                    {
                        enemy.BeFlipped();
                        //score
                        mario.isScored = true;
                        mario.score    = GameConstants.Score1;
                        Vector2 newP;
                        newP.X             = mario.position.X;
                        newP.Y             = mario.position.Y - THREE;
                        mario.textPosition = newP;
                    }
                    else
                    {
                        mario.MarioGetHit();
                    }

                    break;

                case 4:
                    if (mario.HasStarPower)
                    {
                        enemy.BeFlipped();
                        //score
                        mario.isScored = true;
                        mario.score    = GameConstants.Score1;
                        Vector2 newP;
                        newP.X             = mario.position.X;
                        newP.Y             = mario.position.Y - THREE;
                        mario.textPosition = newP;
                    }
                    else
                    {
                        if (enemy.enemySprite is KoopaStompedSprite)
                        {
                            if (enemy.shellDirection)
                            {
                                mario.MarioGetHit();
                            }
                            else
                            {
                                MarioSoundManager.instance.playSound(MarioSoundManager.KICK);
                                if (mario.position.X < enemy.position.X)
                                {
                                    newPosition.X  = mario.position.X - SIX;
                                    newPosition.Y  = mario.position.Y;
                                    mario.position = newPosition;
                                }
                                else
                                {
                                    newPosition.X  = mario.position.X + SIX;
                                    newPosition.Y  = mario.position.Y;
                                    mario.position = newPosition;
                                }
                                enemy.shellDirection = true;
                                enemy.shellMoving    = GameConstants.Left;
                            }
                        }
                        else
                        {
                            mario.MarioGetHit();
                        }
                    }
                    break;
                }
            }
        }
Exemple #11
0
 public static void FireballCollideWithEnemy(FireballObject fireball, IEnemy enemy)
 {
     fireball.Explode();
     enemy.BeFlipped();
 }
Exemple #12
0
 public void Execute()
 {
     Enemy.BeFlipped(Mario);
 }
        public static void EnemyCollideWithEnvironment(IEnemy enemy, IGameObject environment)
        {
            Rectangle  enemyRectangle       = enemy.GetHitBox();
            Rectangle  environmentRectangle = environment.GetHitBox();
            ICollision collisionSide        = CollisionSideDetector.DetectCollisionSide(enemyRectangle, environmentRectangle);

            if (collisionSide is RightCollision)
            {
                //let koopa shells kill
                if (environment is Koopa koopa)
                {
                    if (koopa.State is LeftSlidingShellState || koopa.State is RightSlidingShellState)
                    {
                        enemy.BeFlipped();
                        SoundFactory.Instance.Play(SoundFactory.Effects.Kick);
                    }
                    else if (!(enemy is LeftSlidingShellState || enemy is RightSlidingShellState))
                    {
                        environment.SideCollisionResponse();
                    }
                }
                else if (environment is IEnemy collidedEnemy)
                {
                    if (enemy.State is LeftSlidingShellState || enemy.State is RightSlidingShellState)
                    {
                        collidedEnemy.BeFlipped();
                        SoundFactory.Instance.Play(SoundFactory.Effects.Kick);
                    }
                    else if (!(enemy is LeftSlidingShellState || enemy is RightSlidingShellState))
                    {
                        environment.SideCollisionResponse();
                    }
                }
                else
                {
                    enemy.SideCollisionResponse();
                }

                enemy.Position = new Vector2(enemy.Position.X - collisionSide.CollisionIntersection.Width, enemy.Position.Y);
            }
            else if (collisionSide is LeftCollision)
            {
                //let koopa shells kill
                if (environment is Koopa koopa)
                {
                    if (koopa.State is LeftSlidingShellState || koopa.State is RightSlidingShellState)
                    {
                        enemy.BeFlipped();
                        SoundFactory.Instance.Play(SoundFactory.Effects.Kick);
                    }
                    else if (!(enemy is LeftSlidingShellState || enemy is RightSlidingShellState))
                    {
                        environment.SideCollisionResponse();
                    }
                }
                else if (environment is IEnemy collidedEnemy)
                {
                    if (enemy.State is LeftSlidingShellState || enemy.State is RightSlidingShellState)
                    {
                        collidedEnemy.BeFlipped();
                    }
                    else if (!(enemy is LeftSlidingShellState || enemy is RightSlidingShellState))
                    {
                        environment.SideCollisionResponse();
                    }
                }
                else
                {
                    enemy.SideCollisionResponse();
                }
                enemy.Position = new Vector2(enemy.Position.X + collisionSide.CollisionIntersection.Width, enemy.Position.Y);
            }
            else if (collisionSide is TopCollision && (environment is IBlock || environment is IPipe))
            {
                if (environment is IBlock block)
                {
                    if (block.WasHit)
                    {
                        enemy.BeFlipped();
                        SoundFactory.Instance.Play(SoundFactory.Effects.Kick);
                    }
                    if (!(block.State is HiddenItemBlockState))
                    {
                        enemy.Position  = new Vector2(enemy.Position.X, enemy.Position.Y - collisionSide.CollisionIntersection.Height);
                        enemy.IsFalling = false;
                    }
                }
                else
                {
                    enemy.Position  = new Vector2(enemy.Position.X, enemy.Position.Y - collisionSide.CollisionIntersection.Height);
                    enemy.IsFalling = false;
                }
            }
            else if (collisionSide is TopCollision && environment is IEnemy)
            {
                IEnemy collidedEnemy = (IEnemy)environment;
                collidedEnemy.BeFlipped();
            }
        }
 public void Attack(IEnemy enemy)
 {
     enemy.BeFlipped();
     enemy.Movement = new DeadMovement(game);
     Boom();
 }