public void OneUpMushroomTest()
        {
            bool passed = true;

            ItemSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(390, 400);
            IItemObjects      item              = new OneUpMushroom(400, 400);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side              = collisionDetector.getCollision(mario.returnCollisionRectangle(), item.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                passed = true;
            }
            else
            {
                passed = false;
            }
            MarioItemCollisionHandler.handleCollision((Mario)mario, item, side);
            if (passed)
            {
                Console.WriteLine("OneUpMushroom Test Passed");
            }
            else
            {
                Console.WriteLine("OneUpMushroom failed");
            }
        }
        public void StarTest()
        {
            bool passed = true;

            ItemSpriteTextureStorage.Load(game.Content);
            MarioSpriteFactory.Load(game.Content);
            IPlayer           mario             = new Mario(390, 400);
            IItemObjects      star              = new SuperStar(400, 400);
            CollisionDetector collisionDetector = new CollisionDetector();
            ICollision        side              = collisionDetector.getCollision(mario.returnCollisionRectangle(), star.returnCollisionRectangle());

            if (passed && side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                passed = true;
            }
            else
            {
                passed = false;
            }
            MarioItemCollisionHandler.handleCollision((Mario)mario, star, side);
            if (((Mario)mario).Star && passed)
            {
                Console.WriteLine("Star Test Passed");
            }
            else
            {
                Console.WriteLine("Star failed");
            }
        }
Esempio n. 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;
                }
            }
        }