Beispiel #1
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);
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #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();
                }
            }
        }