Example #1
0
        public void CheckKoopaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> koopas)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();
            EnemyGravityHandler      gravityHandler  = new EnemyGravityHandler();

            for (int loop = 0; loop < koopas.Count; loop++)
            {
                Koopa koopa = (Koopa)koopas.ElementAt(loop);

                Rectangle currentKoopa = koopa.GetRectangle();

                for (int secondLoop = loop + 1; secondLoop < koopas.Count; secondLoop++)
                {
                    Koopa     secondKoopa        = (Koopa)koopas.ElementAt(secondLoop);
                    Rectangle currentSecondKoopa = secondKoopa.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentKoopa, currentSecondKoopa);
                    EnemyEnemyCollisionHandler.HandleCollision(koopa, secondKoopa, collisionType);
                }

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

                foreach (IBlock block in blocks)
                {
                    Rectangle currentBlock = block.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentKoopa, currentBlock);
                    EnemyBlockCollisionHandler.HandleCollision(koopa, block, collisionType);
                }
            }
        }
Example #2
0
        public void CheckKoopaCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();

            foreach (Koopa koopa in koopas)
            {
                Rectangle currentKoopa = koopa.GetRectangle();

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

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

                foreach (IBlock block in blocks)
                {
                    Rectangle currentBlock = block.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentKoopa, currentBlock);
                    EnemyBlockCollisionHandler.HandleCollision(koopa, block, collisionType);
                }
            }
        }
Example #3
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();
                }
            }
        }
Example #4
0
        public void CheckFireballCollisions(List <IBlock> blocks, List <IPipe> pipes, List <IEnemy> goombas, List <IEnemy> koopas, List <Fireball> projectiles)
        {
            Game1.Side collisionType = Game1.Side.None;
            GeneralCollisionDetector generalDetector = new GeneralCollisionDetector();

            foreach (Fireball fireball in projectiles)
            {
                Rectangle currentFireball = fireball.GetRectangle();


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

                    FireballBlockCollisionHandler.HandleCollision(fireball, block, collisionType);
                }

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

                    FireballEnemyCollisionHandler.HandleCollision(fireball, koopa, collisionType);
                }

                foreach (Goomba goomba in goombas)
                {
                    Rectangle currentGoomba = goomba.GetRectangle();
                    collisionType = generalDetector.DetermineCollision(currentGoomba, currentFireball);

                    FireballEnemyCollisionHandler.HandleCollision(fireball, goomba, collisionType);
                }

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

                    FireballPipeCollisionHandler.HandleCollision(fireball, pipe, collisionType);
                }
            }
        }
        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();
                    }
                }
            }
        }
Example #7
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();
                }
            }
        }
Example #8
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();
                }
            }
        }