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());
            }
        }
Beispiel #2
0
 public static void HandleCollision(IEnemy enemy1, IEnemy enemy2, Game1.Side side)
 {
     if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))
     {
         enemy1.ChangeDirection();
         enemy2.ChangeDirection();
     }
 }
 public static void HandleCollision(KoopaShell shell, IBlock block, Game1.Side side)
 {
     if (shell.isHit)
     {
         if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))
         {
             shell.ChangeDirection();
         }
     }
 }
        public static void HandleCollision(IPlayer player, IBlock block, Game1.Side side)
        {
            int collisionFix = 4;

            if (!player.IsInSpecialAnimationState())
            {
                if (side.Equals(Game1.Side.Left))
                {
                    player.ManualMoveX(collisionFix);

                    player.SetVelo(0);
                }
                else if (side.Equals(Game1.Side.Right))
                {
                    player.ManualMoveX(-1 * collisionFix);

                    player.SetVelo(0);
                }
                else if (side.Equals(Game1.Side.Top))
                {
                    player.ManualMoveY(player.GetVerticalVelocity() * (-2));

                    player.SetVerticalVelocity(0);
                }


                else if (side.Equals(Game1.Side.Bottom))
                {
                    int downDirection = 1;
                    int upDirection   = -1;
                    if (player.GetVerticalVelocity() > 0)
                    {
                        // player.ManualMoveY(upDirection * player.GetVerticalVelocity());         //player.GetVerticalVelocity() * (-1.0));

                        double displacement = player.GetRectangle().Bottom - block.GetRectangle().Top;

                        if ((displacement) >= downDirection)
                        {
                            player.ManualMoveY(upDirection * displacement + upDirection);
                        }
                        else
                        {
                            player.ManualMoveY(0);
                        }
                    }
                    player.SetTouchedGround(true);
                    player.SetVerticalVelocity(0);
                    player.ResetEnemyMultiplier(1);

                    /*
                     * player.ManualMoveY(player.GetVerticalVelocity() * (-2));
                     * plyer.SetVerticalVelocity(0);*/
                }
            }
        }
Beispiel #5
0
        public static void HandleCollision(IEnemy enemy, IPipe pipe, Game1.Side side)
        {
            if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right) || side.Equals(Game1.Side.Top))
            {
                enemy.ChangeDirection();
            }

            else
            {
                //just keep walking
            }
        }
        public static void HandleCollision(IItem koopaShell, Game1.Side side)
        {
            KoopaShell shell = (KoopaShell)koopaShell;

            if (shell.isHit)
            {
                if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))
                {
                    shell.ChangeDirection();
                }
            }
        }
Beispiel #7
0
        public void CheckGoombaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();

            foreach (Goomba goomba in goombas)
            {
                EnemyGravityHandler gravityHandler = new EnemyGravityHandler(goomba);

                Rectangle currentGoomba     = goomba.GetRectangle();
                bool      goombaIsSupported = false;

                foreach (Koopa koopa in koopas)
                {
                    Rectangle currentKoopa = koopa.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentGoomba, currentKoopa);
                    EnemyEnemyCollisionHandler.HandleCollision(goomba, koopa, collisionType);
                }

                foreach (IPipe pipe in pipes)
                {
                    Rectangle currentPipe = pipe.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentGoomba, currentPipe);
                    EnemyPipeCollisionHandler.HandleCollision(goomba, pipe, collisionType);

                    if (collisionType.Equals(Game1.Side.Bottom) || (currentPipe.Top - currentGoomba.Bottom <= 3 && generalDetector.IsAlongSameYAxis(currentGoomba, currentPipe)))
                    {
                        goombaIsSupported = true;
                    }
                }

                foreach (IBlock block in blocks)
                {
                    Rectangle currentBlock = block.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentGoomba, currentBlock);
                    EnemyBlockCollisionHandler.HandleCollision(goomba, block, collisionType);

                    if (collisionType.Equals(Game1.Side.Bottom) || (currentBlock.Top - currentGoomba.Bottom <= 3 && generalDetector.IsAlongSameYAxis(currentGoomba, currentBlock)))
                    {
                        goombaIsSupported = true;
                    }
                }

                if (!goombaIsSupported)
                {
                    gravityHandler.ApplyGravityToEnemy();
                }
                else
                {
                    goomba.SetGrounded();
                }
            }
        }
Beispiel #8
0
 public void ChangeStateWhenSmall(Game1.Side side)
 {
     if (side.Equals(Game1.Side.Top))
     {
         isHit = true;
     }
 }
        public static void HandleCollision(IItem star, IPipe pipe, Game1.Side side)
        {
            Star localStar        = (Star)star;
            int  starDisplacement = 3;

            if (side.Equals(Game1.Side.Left))
            {
                localStar.location.X += starDisplacement;
                localStar.movingRight = !localStar.movingRight;
            }
            else if (side.Equals(Game1.Side.Right))
            {
                localStar.location.X -= starDisplacement;
                localStar.movingRight = !localStar.movingRight;
            }
        }
        public void CheckStarCollisions(List <IItem> items, List <IBlock> blocks, List <IPipe> pipes)
        {
            Game1.Side             collisionType   = Game1.Side.None;
            BlockCollisionDetector generalDetector = new BlockCollisionDetector();
            ItemGravityHandler     gravityHandler  = new ItemGravityHandler();
            bool shouldBounce = false;

            foreach (IItem star in items)
            {
                if (star is Star)
                {
                    Rectangle currentStar = star.GetRectangle();
                    foreach (IBlock block in blocks)
                    {
                        Rectangle currentBlock = block.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentStar, currentBlock);

                        StarBlockCollisionHanlder.HandleCollision(star, block, collisionType);
                        if (collisionType.Equals(Game1.Side.Bottom))
                        {
                            shouldBounce = true;
                        }
                    }

                    foreach (IPipe pipe in pipes)
                    {
                        Rectangle currentPipe = pipe.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentStar, currentPipe);

                        StarPipeCollisionHandler.HandleCollision(star, pipe, collisionType);
                        if (collisionType.Equals(Game1.Side.Bottom))
                        {
                            shouldBounce = true;
                        }
                    }

                    if (shouldBounce)
                    {
                        star.SetGrounded();
                    }
                    else
                    {
                        gravityHandler.ApplyGravityToItem(star);
                    }
                }
            }
        }
Beispiel #11
0
 public void ChangeState(Game1.Side side)
 {
     if (side.Equals(Game1.Side.Top))
     {
         sourceRectangle = new Rectangle(BlockUtility.blockSize * 3, 0, BlockUtility.blockSize, BlockUtility.blockSize);
         isHidden        = false;
         hasItem         = false;
     }
 }
Beispiel #12
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();
                    }
                }
            }
        }
        public static void HandleCollision(IItem star, IBlock block, Game1.Side side)
        {
            Star localStar      = (Star)star;
            int  bounceDistance = 3;

            if (side.Equals(Game1.Side.Left) || side.Equals(Game1.Side.Right))
            {
                if (block is UnbreakableBlock)
                {
                    if (localStar.movingRight)
                    {
                        localStar.location.X -= bounceDistance;
                    }
                    else
                    {
                        localStar.location.X += bounceDistance;
                    }
                    localStar.movingRight = !localStar.movingRight;
                }
            }
        }
        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();
                }
            }
        }
Beispiel #15
0
 public void ChangeState(Game1.Side side)
 {
     if (side.Equals(Game1.Side.Top))
     {
         if (isHit == true)
         {
             SoundManager.PlaySound(Game1.breakBlockSound);
             Rectangle destinationRectangle = new Rectangle(BlockUtility.offScreen, BlockUtility.offScreen, BlockUtility.blockSize, BlockUtility.blockSize);
         }
         else
         {
             isHit       = true;
             shouldBreak = true;
             BreakBlock();
         }
     }
 }
Beispiel #16
0
 public void ChangeState(Game1.Side side)
 {
     if (side.Equals(Game1.Side.Top))
     {
         if (item.GetType() != typeof(MultiCoin))
         {
             sourceRectangle = new Rectangle(BlockUtility.blockSize * numberOfFrames, 0, BlockUtility.blockSize, BlockUtility.blockSize);
             hasItem         = false;
             isHit           = true;
         }
         else if (hitCount > maxHitCount || timer > maxTimer)
         {
             sourceRectangle = new Rectangle(BlockUtility.blockSize * numberOfFrames, 0, BlockUtility.blockSize, BlockUtility.blockSize);
             hasItem         = false;
             isHit           = true;
         }
     }
 }
Beispiel #17
0
        public static void HandleCollision(IPlayer player, IPipe pipe, Game1.Side side)
        {
            int collisionFix = 3;

            if (side.Equals(Game1.Side.Left))
            {
                hasCollided = true;

                player.ManualMoveX(collisionFix);
                player.SetVelo(0);
            }
            else if (side.Equals(Game1.Side.Right))
            {
                hasCollided = true;
                player.SetVelo(0);

                if (pipe.GetType() == typeof(UndergroundSidePipe) && pipe.IsWarp() && player.GetDirection() == MarioDirection.RIGHT)
                {
                    if (!player.IsInSpecialAnimationState())
                    {
                        collisionFix = 0;
                        player.PipeRightAnimation();
                    }
                    else if (!player.HasFinishedSpecialAnimationState())
                    {
                        player.PipeRightAnimation();
                    }

                    if (player.HasFinishedSpecialAnimationState())
                    {
                        //Signal for mario to move down and then load new level
                        WorldManager.switchLevel        = true;
                        WorldManager.currentFilename    = pipe.GetFileName();
                        LevelManager.marioStartLocation = pipe.GetSpawnCoords();
                        WorldManager.marioStartLocation = pipe.GetSpawnCoords();
                    }
                }
                else
                {
                    player.ManualMoveX(-1 * collisionFix);
                }
            }

            else if (side.Equals(Game1.Side.Bottom))
            {
                if (player.GetVerticalVelocity() > 0)
                {
                    //player.ManualMoveY(-1 * player.GetVerticalVelocity());         //player.GetVerticalVelocity() * (-1.0));

                    int displacement = player.GetRectangle().Bottom - pipe.GetRectangle().Top;

                    if ((displacement) > 1)
                    {
                        player.ManualMoveY(-1 * displacement);
                    }
                }

                player.SetVerticalVelocity(0);

                if (pipe.GetType() == typeof(LargePipe) && pipe.IsWarp() && player.GetDirection() == MarioDirection.DOWN)
                {
                    if (!player.IsInSpecialAnimationState())
                    {
                        player.PipeDownAnimation();
                    }
                    else if (!player.HasFinishedSpecialAnimationState())
                    {
                        player.PipeDownAnimation();
                    }

                    if (player.HasFinishedSpecialAnimationState())
                    {
                        //Signal for mario to move down and then load new level
                        WorldManager.switchLevel        = true;
                        WorldManager.currentFilename    = pipe.GetFileName();
                        WorldManager.marioStartLocation = pipe.GetSpawnCoords();
                    }
                }
            }

            if (hasCollided)
            {
                player.LockMov();
            }
            else
            {
                player.UnlockMov();
            }
            hasCollided = false;
        }
        public FreeBowser.Game1.Side DetermineCollision(Rectangle referenceRectangle, Rectangle otherRectangle)
        {
            Rectangle area = Rectangle.Intersect(referenceRectangle, otherRectangle);

            Game1.Side collisionSide = Game1.Side.None;
            if (area.Height == 0 && area.Width == 0)
            {
                collisionSide = Game1.Side.None;
            }

            else if (area.Right > referenceRectangle.Left && area.Left <= referenceRectangle.Left && area.Bottom <= referenceRectangle.Bottom && area.Top >= referenceRectangle.Top)
            {
                collisionSide = Game1.Side.Left;

                if (otherRectangle.Right < ((referenceRectangle.Center.X + referenceRectangle.Left) / 2.0))
                {
                    //if (!(area.Bottom >= referenceRectangle.Top && area.Top <= referenceRectangle.Top))

                    return(collisionSide);
                }
            }
            else if (area.Left < referenceRectangle.Right && area.Right >= referenceRectangle.Right && (area.Bottom <= referenceRectangle.Bottom || area.Top >= referenceRectangle.Top))
            {
                collisionSide = Game1.Side.Right;

                if (otherRectangle.Left > ((referenceRectangle.Center.X + referenceRectangle.Right) / 2.0))
                {
                    //if (!(area.Bottom >= referenceRectangle.Top && area.Top <= referenceRectangle.Top))
                    return(collisionSide);
                }
            }


            if (area.Bottom >= referenceRectangle.Top && area.Top == referenceRectangle.Top)//&& (area.Left >= ((referenceRectangle.Center.X + referenceRectangle.Right) / 2.0 )|| (area.Right <= ((referenceRectangle.Center.X + referenceRectangle.Left) / 2.0))))
            {
                if (collisionSide.Equals(Game1.Side.Left))
                {
                    if (!(referenceRectangle.Top <= otherRectangle.Top))//|| referenceRectangle.Bottom >= otherRectangle.Bottom))
                    {
                        collisionSide = Game1.Side.Top;
                    }
                }
                else if (collisionSide.Equals(Game1.Side.Right))
                {
                    if (!(referenceRectangle.Top <= otherRectangle.Top))//|| referenceRectangle.Bottom >= otherRectangle.Bottom))
                    {
                        collisionSide = Game1.Side.Top;
                    }
                }
                else
                {
                    collisionSide = Game1.Side.Top;
                }
            }

            else if (area.Top <= referenceRectangle.Bottom && area.Bottom == referenceRectangle.Bottom)
            {
                if (collisionSide.Equals(Game1.Side.Left))
                {
                    if (!(referenceRectangle.Bottom >= otherRectangle.Bottom))
                    {
                        collisionSide = Game1.Side.Bottom;
                    }
                }
                else if (collisionSide.Equals(Game1.Side.Right))
                {
                    if (!(referenceRectangle.Bottom >= otherRectangle.Bottom))
                    {
                        collisionSide = Game1.Side.Bottom;
                    }
                }
                else
                {
                    collisionSide = Game1.Side.Bottom;
                }
            }
            return(collisionSide);
        }
        public static void HandleCollision(IPlayer player, IItem item, Game1.Side side)
        {
            if (!side.Equals(Game1.Side.None))
            {
                MarioState playerState = player.GetState();

                if (item is FireFlower)
                {
                    if (playerState.Equals(MarioState.SMALL) || playerState.Equals(MarioState.LARGE))
                    {
                        player.SwitchToFireMario(true);
                    }
                    item.ChangeState();
                }

                if (item is RedMushroom)
                {
                    if (playerState.Equals(MarioState.SMALL))
                    {
                        player.SwitchToBigMario(true);
                    }
                    item.ChangeState();
                }

                if (item is Star)
                {
                    //go to star state
                    item.ChangeState();

                    if (StarUtility.isFirstShown == false)
                    {
                        StarUtility.starTime    = 8;
                        StarUtility.isStarMario = true;
                        player.SetStarMario(true);
                        StarUtility.StarMarioLock = true;
                        Console.Out.WriteLine("collide with star");
                        StarUtility.isFirstShown = true;
                    }
                }

                if (item is VisibleCoin)
                {
                    item.ChangeState();
                }

                if (item is GreenMushroom)
                {
                    int lives = player.GetLives();
                    player.SetLives(lives + 1);
                    item.ChangeState();
                }
            }

            if (item is KoopaShell)
            {
                KoopaShell shell        = (KoopaShell)item;
                int        collisionFix = 2;
                if (side.Equals(Game1.Side.Top))
                {
                    int bounceVelocity = -5;
                    //Console.WriteLine("here");
                    player.SetVerticalVelocity(bounceVelocity);
                    item.ChangeState();
                }

                if (side.Equals(Game1.Side.Left))
                {
                    if (shell.isHit)
                    {
                        player.TakeDamage();
                    }
                    else
                    {
                        player.MoveX(-1 * collisionFix);
                        player.SetHorizontalVelocity(0);
                    }
                }
                else if (side.Equals(Game1.Side.Right))
                {
                    if (shell.isHit)
                    {
                        player.TakeDamage();
                    }
                    else
                    {
                        player.MoveX(collisionFix);
                        player.SetHorizontalVelocity(0);
                    }
                }
            }

            if (item is Flag)
            {
                if (side.Equals(Game1.Side.Left))
                {
                    MarioFlagCollisionHandler.HandleCollision(player, item);
                }
            }
        }
Beispiel #20
0
        public void CheckMushroomCollisions(List <IItem> items, List <IBlock> blocks, List <IPipe> pipes)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();
            ItemGravityHandler       gravityHandler  = new ItemGravityHandler();

            foreach (IItem rm in items)
            {
                bool itemIsSupported = false;
                if (rm is RedMushroom)
                {
                    Rectangle currentRM = rm.GetRectangle();

                    foreach (IBlock block in blocks)
                    {
                        Rectangle currentBlock = block.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentBlock, currentRM);

                        MushroomBlockCollisionHandler.HandleCollision(rm, block, collisionType);
                        if (collisionType.Equals(Game1.Side.Top) || (currentBlock.Top - currentRM.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentRM, currentBlock)))
                        {
                            itemIsSupported = true;
                        }
                    }

                    foreach (IPipe pipe in pipes)
                    {
                        Rectangle currentPipe = pipe.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentPipe, currentRM);

                        MushroomPipeCollisionHandler.HandleCollision(rm, pipe, collisionType);

                        if (collisionType.Equals(Game1.Side.Top) || (currentPipe.Top - currentRM.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentRM, currentPipe)))
                        {
                            itemIsSupported = true;
                        }
                    }
                    if (!(itemIsSupported))
                    {
                        gravityHandler.ApplyGravityToItem(rm);
                    }
                    else
                    {
                        rm.SetGrounded();
                    }
                }
            }

            foreach (IItem gm in items)
            {
                bool itemIsSupported = false;

                if (gm is GreenMushroom)
                {
                    Rectangle currentGM = gm.GetRectangle();

                    foreach (IBlock block in blocks)
                    {
                        Rectangle currentBlock = block.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentBlock, currentGM);

                        MushroomBlockCollisionHandler.HandleCollision(gm, block, collisionType);
                        if (collisionType.Equals(Game1.Side.Top) || (currentBlock.Top - currentGM.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentGM, currentBlock)))
                        {
                            itemIsSupported = true;
                        }
                    }

                    foreach (IPipe pipe in pipes)
                    {
                        Rectangle currentPipe = pipe.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentPipe, currentGM);

                        MushroomPipeCollisionHandler.HandleCollision(gm, pipe, collisionType);

                        if (collisionType.Equals(Game1.Side.Top) || (currentPipe.Top - currentGM.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentGM, currentPipe)))
                        {
                            itemIsSupported = true;
                        }
                    }
                }

                if (!(itemIsSupported))
                {
                    gravityHandler.ApplyGravityToItem(gm);
                }
                else
                {
                    gm.SetGrounded();
                }
            }
        }
 public void ChangeState(Game1.Side side)
 {
     if (side.Equals(Game1.Side.Bottom))
     {
     }
 }
        public void CheckKoopaShellCollisions(List <IItem> items, List <IEnemy> goombas, List <IEnemy> koopas, List <IBlock> blocks, List <IPipe> pipes)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();
            ItemGravityHandler       gravityHandler  = new ItemGravityHandler();

            foreach (IItem item in items)
            {
                if (item is KoopaShell)
                {
                    KoopaShell shell           = (KoopaShell)item;
                    Rectangle  currentShell    = shell.GetRectangle();
                    bool       itemIsSupported = false;


                    foreach (IBlock block in blocks)
                    {
                        Rectangle currentBlock = block.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentBlock, currentShell);

                        ShellBlockCollisionHandler.HandleCollision(shell, block, collisionType);
                        if (collisionType.Equals(Game1.Side.Top) || (currentBlock.Top - currentShell.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentShell, currentBlock)))
                        {
                            itemIsSupported = true;
                        }
                    }

                    foreach (IPipe pipe in pipes)
                    {
                        Rectangle currentPipe = pipe.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentPipe, currentShell);

                        ShellPipeCollisionHandler.HandleCollision(shell, collisionType);

                        if (collisionType.Equals(Game1.Side.Top) || (currentPipe.Top - currentShell.Bottom <= 5 && generalDetector.IsAlongSameYAxis(currentShell, currentPipe)))
                        {
                            itemIsSupported = true;
                        }
                    }
                    foreach (Goomba goomba in goombas)
                    {
                        Rectangle currentGoomba = goomba.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentShell, currentGoomba);

                        ShellEnemyCollisionHandler.HandleCollision(shell, goomba, collisionType);
                    }

                    foreach (Koopa koopa in koopas)
                    {
                        Rectangle currentKoopa = koopa.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentShell, currentKoopa);

                        ShellEnemyCollisionHandler.HandleCollision(shell, koopa, collisionType);
                    }

                    if (!(itemIsSupported))
                    {
                        gravityHandler.ApplyGravityToItem(shell);
                    }
                    else
                    {
                        shell.SetGrounded();
                    }
                }
            }
        }
        public void CheckMariosCollisions(List <IPlayer> players, List <IItem> items, List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();
            BlockCollisionDetector   blockDetector   = new BlockCollisionDetector();
            MarioGravityHandler2     gravityHandler  = new MarioGravityHandler2();

            double initialDistance = 1000;

            foreach (Mario mario in players)
            {
                if (!mario.isDying)
                {
                    Rectangle currentMario           = mario.GetRectangle();
                    bool      marioIsSupported       = false;
                    bool      marioIsBlocked         = false;
                    bool      wasTopCollision        = false;
                    bool      marioBounceOffEnemy    = false;
                    IBlock    closestBlock           = (IBlock)blocks.ElementAt(0);
                    double    distanceToClosestBlock = initialDistance;

                    for (int loop = 0; loop < blocks.Count; loop++)
                    {
                        IBlock    block        = (IBlock)blocks.ElementAt(loop);
                        Rectangle currentBlock = block.GetRectangle();

                        collisionType = blockDetector.DetermineCollision(currentMario, currentBlock);

                        if (collisionType.Equals(Game1.Side.Bottom) || (currentBlock.Top - currentMario.Bottom <= 2 && blockDetector.IsAlongSameYAxis(currentMario, currentBlock)))
                        {
                            marioIsSupported = true;
                        }
                        else if (collisionType.Equals(Game1.Side.Top))
                        {
                            marioIsBlocked = true;
                            SoundManager.PlaySound(Game1.bumpSound);
                        }

                        if (collisionType.Equals(Game1.Side.Top))
                        {
                            wasTopCollision = true;
                            if (blockDetector.DistanceToCenterOfPlayer(currentMario, currentBlock) < distanceToClosestBlock)
                            {
                                closestBlock = block;
                            }
                        }
                        else
                        {
                            BlockMarioCollisionHandler.HandleCollision(mario, block, collisionType);
                        }
                        MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType);
                    }

                    if (wasTopCollision)
                    {
                        if (closestBlock.HasItem())
                        {
                            //Console.WriteLine(mario.GetState());
                            IItem createdItem = closestBlock.ReleaseItem(mario.GetState());
                            if (items != null)
                            {
                                createdItem.SetCreatedFromBlock(true);
                                items.Add(createdItem);
                            }
                        }
                        BlockMarioCollisionHandler.HandleCollision(mario, closestBlock, Game1.Side.Top);
                    }

                    foreach (Goomba goomba in goombas)
                    {
                        Rectangle currentGoomba = goomba.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentMario, currentGoomba);
                        if (collisionType.Equals(Game1.Side.Bottom))
                        {
                            marioBounceOffEnemy = true;
                        }
                        MarioEnemyCollisionHandler.HandleCollision(mario, goomba, collisionType);
                    }

                    foreach (Koopa koopa in koopas)
                    {
                        Rectangle currentKoopa = koopa.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentMario, currentKoopa);
                        //Console.WriteLine(collisionType);
                        MarioEnemyCollisionHandler.HandleCollision(mario, koopa, collisionType);
                        if (collisionType.Equals(Game1.Side.Bottom))
                        {
                            marioBounceOffEnemy = true;
                            if (!Game1.nightmare)
                            {
                                IItem shell = koopa.CreateShell();
                                items.Add(shell);
                            }
                        }
                    }

                    foreach (IPipe pipe in pipes)
                    {
                        Rectangle currentPipe = pipe.GetRectangle();
                        collisionType = generalDetector.DetermineCollision(currentMario, currentPipe);


                        if (collisionType.Equals(Game1.Side.Bottom)) //|| (currentPipe.Top - currentMario.Bottom <= 3 && generalDetector.IsAlongSameYAxis(currentMario, currentPipe)))
                        {
                            collisionType    = Game1.Side.Bottom;
                            marioIsSupported = true;
                        }
                        else if (collisionType.Equals(Game1.Side.Top))
                        {
                            marioIsBlocked = true;
                        }

                        MarioPipeCollisionHandler.HandleCollision(mario, pipe, collisionType);
                    }

                    foreach (IItem item in items)
                    {
                        Rectangle currentItem = item.GetRectangle();

                        collisionType = generalDetector.DetermineCollision(currentItem, currentMario);
                        if (!collisionType.Equals(Game1.Side.None))
                        {
                            //Console.WriteLine("touching item: " + item);
                        }
                        MarioItemCollisionHandler.HandleCollision(mario, item, collisionType);
                    }


                    if (!marioIsSupported)
                    {
                        if (!mario.IsInSpecialAnimationState())
                        {
                            gravityHandler.ApplyGravityToMario(mario);
                        }
                    }
                    else if (marioIsBlocked)
                    {
                        mario.ManualMoveY(4);
                        mario.SetFalling();
                    }
                    else if (!marioBounceOffEnemy)
                    {
                        mario.SetGrounded();
                    }
                }
            }
        }
Beispiel #24
0
        public void CheckMarioCollisions(List <IPlayer> players, List <IItem> items, List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();
            BlockCollisionDetector   blockDetector   = new BlockCollisionDetector();

            foreach (Mario mario in players)
            {
                Rectangle            currentMario   = mario.GetRectangle();
                MarioGravityHandler2 gravityHandler = new MarioGravityHandler2(mario);
                bool marioIsSupported = false;
                bool marioIsBlocked   = false;
                foreach (IBlock block in blocks)
                {
                    Rectangle currentBlock = block.GetRectangle();
                    collisionType = blockDetector.DetermineCollision(currentMario, currentBlock);

                    if (collisionType.Equals(Game1.Side.Bottom) || (currentBlock.Top - currentMario.Bottom <= 4 && blockDetector.IsAlongSameYAxis(currentMario, currentBlock)))
                    {
                        marioIsSupported = true;
                    }
                    else if (collisionType.Equals(Game1.Side.Top))
                    {
                        marioIsBlocked = true;
                    }

                    if (block.HasItem() && collisionType.Equals(Game1.Side.Top))
                    {
                        IItem createdItem = block.ReleaseItem(mario.marioState);
                        if (items != null)
                        {
                            createdItem.SetCreatedFromBlock(true);
                            items.Add(createdItem);
                        }
                    }

                    MarioBlockCollisionHandler.HandleCollision(mario, block, collisionType);
                    BlockMarioCollisionHandler.HandleCollision(mario, block, collisionType);
                }

                foreach (Goomba goomba in goombas)
                {
                    Rectangle currentGoomba = goomba.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentMario, currentGoomba);
                    if (collisionType.Equals(Game1.Side.Bottom))
                    {
                        marioIsSupported = true;
                    }
                    MarioEnemyCollisionHandler.HandleCollision(mario, goomba, collisionType);
                }

                foreach (Koopa koopa in koopas)
                {
                    Rectangle currentKoopa = koopa.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentMario, currentKoopa);
                    if (collisionType.Equals(Game1.Side.Bottom))
                    {
                        marioIsSupported = true;
                    }
                    MarioEnemyCollisionHandler.HandleCollision(mario, koopa, collisionType);
                    if (collisionType.Equals(Game1.Side.Bottom))
                    {
                        IItem shell = koopa.CreateShell();
                        items.Add(shell);
                    }
                }

                foreach (IPipe pipe in pipes)
                {
                    Rectangle currentPipe = pipe.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentMario, currentPipe);
                    if (collisionType.Equals(Game1.Side.Bottom) || (currentPipe.Top - currentMario.Bottom <= 4 && generalDetector.IsAlongSameYAxis(currentMario, currentPipe)))
                    {
                        collisionType    = Game1.Side.Bottom;
                        marioIsSupported = true;
                    }
                    else if (collisionType.Equals(Game1.Side.Top))
                    {
                        marioIsBlocked = true;
                    }

                    MarioPipeCollisionHandler.HandleCollision(mario, pipe, collisionType);
                }

                foreach (IItem item in items)
                {
                    Rectangle currentItem = item.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentItem, currentMario);

                    MarioItemCollisionHandler.HandleCollision(mario, item, collisionType);
                }

                if (!marioIsSupported)
                {
                    gravityHandler.ApplyGravityToMario();
                }

                else if (marioIsBlocked)
                {
                    mario.ManualMoveY(4);
                    mario.SetFalling();
                }
                else
                {
                    mario.SetGrounded();
                }
            }
        }