Esempio n. 1
0
        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);
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
Esempio n. 3
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();
                }
            }
        }