Beispiel #1
0
        public static void handleProjectileCollision(IProjectile projectile, LevelStorage storage)
        {
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side;
            Rectangle         floorCheck;

            floorCheck = projectile.returnCollisionRectangle();
            floorCheck.Y++;
            projectile.RigidBody().Floored = false;
            foreach (IBlock block in storage.blocksList)
            {
                if (block.checkForCollisionTestFlag())
                {
                    side = collisionDetector.getCollision(projectile.returnCollisionRectangle(), block.returnCollisionRectangle());
                    ProjectileBlockCollisionHandler.handleCollision(projectile, block, side);
                }
                if (collisionDetector.getCollision(floorCheck, block.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                {
                    projectile.RigidBody().Floored = true;
                }
            }
            foreach (IEnviromental enviromental in storage.enviromentalObjectsList)
            {
                side = collisionDetector.getCollision(projectile.returnCollisionRectangle(), enviromental.returnCollisionRectangle());
                ProjectileEnviromentalCollisionHandler.handleCollision(projectile, enviromental, side);
                if (collisionDetector.getCollision(floorCheck, enviromental.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                {
                    projectile.RigidBody().Floored = true;
                }
            }
        }
Beispiel #2
0
        public static void handleItemCollision(IItemObjects item, LevelStorage storage)
        {
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side;
            Rectangle         floorCheck;

            floorCheck = item.returnCollisionRectangle();
            floorCheck.Y++;
            item.RigidBody().Floored = false;
            foreach (IBlock block in storage.blocksList)
            {
                if (block.checkForCollisionTestFlag())
                {
                    side = collisionDetector.getCollision(item.returnCollisionRectangle(), block.returnCollisionRectangle());
                    ItemBlockCollisionHandler.handleCollision(item, block, side);
                }
                if (collisionDetector.getCollision(floorCheck, block.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                {
                    item.RigidBody().Floored = true;
                }
            }
            foreach (IEnviromental enviromental in storage.enviromentalObjectsList)
            {
                side = collisionDetector.getCollision(item.returnCollisionRectangle(), enviromental.returnCollisionRectangle());
                ItemEnvriomentalCollisionHandler.handleCollision(item, enviromental, side);
            }
        }
Beispiel #3
0
        public static void handleMarioCollision(IPlayer mario, Game1 game, LevelStorage storage)
        {
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side;
            Rectangle         floorCheck;

            floorCheck = mario.returnCollisionRectangle();
            floorCheck.Y++;
            ((Mario)mario).rigidbody.Floored = false;
            foreach (IBlock block in storage.blocksList)
            {
                if (block.checkForCollisionTestFlag())
                {
                    side = collisionDetector.getCollision(mario.returnCollisionRectangle(), block.returnCollisionRectangle());
                    MarioBlockCollisionHandler.handleCollision((Mario)mario, block, side, game);
                    if (collisionDetector.getCollision(floorCheck, block.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                    {
                        ((Mario)mario).rigidbody.Floored = true;
                    }
                }
            }
            foreach (IEnemyObject enemy in storage.enemiesList)
            {
                side = collisionDetector.getCollision(mario.returnCollisionRectangle(), enemy.returnCollisionRectangle());
                MarioEnemyCollisionHandler.handleCollision((Mario)mario, enemy, side, storage);
            }
            foreach (IItemObjects item in storage.itemList)
            {
                if (item.checkForCollisionTestFlag())
                {
                    side = collisionDetector.getCollision(mario.returnCollisionRectangle(), item.returnCollisionRectangle());
                    MarioItemCollisionHandler.handleCollision((Mario)mario, item, side);
                }
            }
            foreach (IEnviromental enviromental in storage.enviromentalObjectsList)
            {
                side = collisionDetector.getCollision(mario.returnCollisionRectangle(), enviromental.returnCollisionRectangle());
                MarioPipeCollisionHandler.handleCollision((Mario)mario, enviromental, side);
                if (collisionDetector.getCollision(floorCheck, enviromental.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                {
                    ((Mario)mario).rigidbody.Floored = true;
                }
            }
        }
Beispiel #4
0
        public static void handleEnemyCollision(IEnemyObject enemy, LevelStorage storage)
        {
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side;
            Rectangle         floorCheck;

            floorCheck = enemy.returnCollisionRectangle();
            floorCheck.Y++;
            enemy.GetRigidBody().Floored = false;
            foreach (IBlock block in storage.blocksList)
            {
                if (block.checkForCollisionTestFlag())
                {
                    side = collisionDetector.getCollision(enemy.returnCollisionRectangle(), block.returnCollisionRectangle());
                    EnemyBlockCollisionHandler.handleCollision(enemy, block, side);
                }
                if (collisionDetector.getCollision(floorCheck, block.returnCollisionRectangle()).returnCollisionSide().Equals(CollisionSide.Top))
                {
                    enemy.GetRigidBody().Floored = true;
                }
            }
            foreach (IEnviromental enviromental in storage.enviromentalObjectsList)
            {
                side = collisionDetector.getCollision(enemy.returnCollisionRectangle(), enviromental.returnCollisionRectangle());
                EnemyEnviromentalCollisionHandler.handleCollision(enemy, enviromental, side);
            }
            foreach (IEnemyObject secondEnemy in storage.enemiesList)
            {
                if (!enemy.Equals(secondEnemy))
                {
                    side = collisionDetector.getCollision(enemy.returnCollisionRectangle(), secondEnemy.returnCollisionRectangle());
                    EnemyEnemyCollisionHandler.handleCollision(enemy, secondEnemy, side);
                }
            }
            foreach (IProjectile projectile in storage.projectileList)
            {
                if (projectile.Active())
                {
                    side = collisionDetector.getCollision(enemy.returnCollisionRectangle(), projectile.returnCollisionRectangle());
                    EnemyProjectileCollisionHandler.handleCollision(enemy, projectile, side);
                }
            }
        }
        public void questionBlockTestLeft()
        {
            bool passed = true;

            BlockSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(390, 400);
            IBlock            question          = new Blocks(400, 400, BlockType.Question);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side = collisionDetector.getCollision(mario.returnCollisionRectangle(), question.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                Console.WriteLine("QuestionBlockTestLeft Passed");
            }
            else
            {
                Console.WriteLine("QuestionBlockTestLeft failed");
            }
        }
        public void PipeTestRight()
        {
            bool passed = true;

            MiscGameObjectTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(410, 400);
            IEnviromental     pipe              = new Pipe(400, 400);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side              = collisionDetector.getCollision(mario.returnCollisionRectangle(), pipe.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                Console.WriteLine("PipeRight Test Passed");
            }
            else
            {
                Console.WriteLine("PipeRight failed");
            }
        }
        public void HiddenBlockTestTop()
        {
            bool passed = true;

            BlockSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(400, 400);
            IBlock            hidden            = new Blocks(400, 415, BlockType.Hidden);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side = collisionDetector.getCollision(mario.returnCollisionRectangle(), hidden.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Top))
            {
                Console.WriteLine("HiddenBlockTop Test Passed");
            }
            else
            {
                Console.WriteLine("HiddenBlockTop failed");
            }
        }
        public void GroundBlockTestRight()
        {
            bool passed = true;

            BlockSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(410, 400);
            IBlock            ground            = new Blocks(400, 400, BlockType.Ground);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side = collisionDetector.getCollision(mario.returnCollisionRectangle(), ground.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                Console.WriteLine("GroundBlockRight Test Passed");
            }
            else
            {
                Console.WriteLine("GroundBlockRight failed");
            }
        }
        public void PlatformingBlockTestBottom()
        {
            bool passed = true;

            BlockSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(400, 400);
            IBlock            platform          = new Blocks(400, 385, BlockType.Platforming);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side = collisionDetector.getCollision(mario.returnCollisionRectangle(), platform.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Bottom))
            {
                Console.WriteLine("PlatformBlockBottom Test Passed");
            }
            else
            {
                Console.WriteLine("PlatformBlockBottom failed");
            }
        }