public void FireMarioRedMushroomRightSideCollisionTest()
        {
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);
            expectedMario.Flower();
            testMario.Flower();

            RedMushroom testRedMushroom = new RedMushroom(game);
            RedMushroom expectedRedMushroom = new RedMushroom(game);
            expectedRedMushroom.Disappear();

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testRedMushroom, side);
            MarioItemCollisionHandler collisionHandler = new MarioItemCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is FireRightIdleState;
            bool expectedState = expectedMario.MarioState is FireRightIdleState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void FireMarioGoombaRightSideCollisionTest()
        {
            IMario testMario = new MarioInstance(game);
            testMario.VectorCoordinates = new Vector2(14, 0);
            IMario expectedMario = new MarioInstance(game);
            expectedMario.VectorCoordinates = new Vector2(16, 0);

            testMario.MarioState = new FireRightIdleState(testMario);
            expectedMario.MarioState = new FireRightIdleState(expectedMario);

            expectedMario.Damage();

            Goomba testGoomba = new Goomba(game);

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testGoomba, side);
            MarioEnemyCollisionHandler collisionHandler = new MarioEnemyCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is NormalRightIdleState;
            bool expectedState = expectedMario.MarioState is NormalRightIdleState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void SmallMarioStarRightSideCollisionTest()
        {
            WorldManager.LoadListFromFile("World1-1", game);
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);
            expectedMario.Star();

            Star testStar = new Star(game);
            Star expectedStar = new Star(game);
            expectedStar.Disappear();

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testStar, side);
            MarioItemCollisionHandler collisionHandler = new MarioItemCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is SmallRightIdleState;
            bool expectedState = expectedMario.MarioState is SmallRightIdleState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void BigMarioCoinRightSideCollisionTest()
        {
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);
            testMario.Mushroom();
            expectedMario.Mushroom();

            Coin testCoin = new Coin(game);
            Coin expectedCoin = new Coin(game);
            expectedCoin.Disappear();

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testCoin, side);
            MarioItemCollisionHandler collisionHandler = new MarioItemCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is NormalRightIdleState;
            bool expectedState = expectedMario.MarioState is NormalRightIdleState;

            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void FireMarioHiddenBlockRightSideCollisionTest()
        {
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);

            Block testBlock = new Block(Block.Type.HiddenBlock, game);
            Block expectedBlock = new Block(Block.Type.HiddenBlock, game);

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testBlock, side);
            MarioBlockCollisionHandler collisionHandler = new MarioBlockCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is FireRightIdleState;
            bool expectedState = expectedMario.MarioState is FireRightIdleState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void SmallMarioKoopaRightSideCollisionTest()
        {
            IMario testMario = new MarioInstance(game);
            testMario.VectorCoordinates = new Vector2(14, 0);
            IMario expectedMario = new MarioInstance(game);
            expectedMario.VectorCoordinates = new Vector2(16, 0);
            expectedMario.Damage();

            GreenKoopa testGreenKoopa = new GreenKoopa(game);

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testGreenKoopa, side);
            MarioEnemyCollisionHandler collisionHandler = new MarioEnemyCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testMario.MarioState is DeadMarioState;
            bool expectedState = expectedMario.MarioState is DeadMarioState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = expectedMario.VectorCoordinates;

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public void StarSmallMarioGoombaRightCollisionTest()
        {
            WorldManager.LoadListFromFile("World1-1", game);
            IMario testMario = WorldManager.GetMario();
            testMario.Star();
            testMario = WorldManager.GetMario();
            testMario.VectorCoordinates = new Vector2(14, 0);

            Goomba testGoomba = new Goomba(game);
            testGoomba.VectorCoordinates = new Vector2(0, 0);
            Goomba expectedGoomba = new Goomba(game);
            expectedGoomba.Flipped();

            ICollisionSide side = new RightSideCollision();
            CollisionData collision = new CollisionData(testMario, testGoomba, side);
            MarioEnemyCollisionHandler collisionHandler = new MarioEnemyCollisionHandler(collision);

            collisionHandler.HandleCollision();

            bool testState = testGoomba.state is GoombaFlippedState;
            bool expectedState = expectedGoomba.state is GoombaFlippedState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = new Vector2(16, 0);

            Assert.AreEqual(testState, expectedState);
            Assert.AreEqual(testLocation, expectedLocation);
        }
        public static ICollisionSide DetectCollision(IGameObject objectA, IGameObject objectB)
        {
            ICollisionSide collisionSide;
            Rectangle hitBoxA;
            Rectangle previousHitBoxA;
            Rectangle previousHitBoxB;
            Rectangle hitBoxB;
            Rectangle collisionRectangle;

            Vector2 objectAOldCoordinates;
            Vector2 objectBOldCoordinates;

            if (objectA.Physics != null)
            {
                objectAOldCoordinates = objectA.Physics.OldCoordinates;

                if (objectA.Physics.Velocity.Y > 0)
                    objectAOldCoordinates.Y--;
                
            }
            else
                objectAOldCoordinates = objectA.VectorCoordinates;

            if (objectB.Physics != null)
            {
                objectBOldCoordinates = objectB.Physics.OldCoordinates;

                if (objectB.Physics.Velocity.Y > 0)
                {
                    objectBOldCoordinates.Y--;
                }
            }
            else
                objectBOldCoordinates = objectB.VectorCoordinates;

            previousHitBoxA = new Rectangle((int)objectAOldCoordinates.X, (int)objectAOldCoordinates.Y, (int)objectA.Sprite.SpriteDimensions.X, (int)objectA.Sprite.SpriteDimensions.Y);
            previousHitBoxB = new Rectangle((int)objectBOldCoordinates.X, (int)objectBOldCoordinates.Y, (int)objectB.Sprite.SpriteDimensions.X, (int)objectB.Sprite.SpriteDimensions.Y);

            hitBoxA = new Rectangle((int)objectA.VectorCoordinates.X, (int)objectA.VectorCoordinates.Y, (int)objectA.Sprite.SpriteDimensions.X, (int)objectA.Sprite.SpriteDimensions.Y);
            hitBoxB = new Rectangle((int)objectB.VectorCoordinates.X, (int)objectB.VectorCoordinates.Y, (int)objectB.Sprite.SpriteDimensions.X, (int)objectB.Sprite.SpriteDimensions.Y);

            collisionRectangle = Rectangle.Intersect(hitBoxA, hitBoxB);
            

            if (collisionRectangle.IsEmpty || objectA is IScenery || objectB is IScenery)
            {
                collisionSide = null;
            }       
            else if (isTopLeftCorner(hitBoxA, hitBoxB))
            {
                if ((previousHitBoxA.Right <= previousHitBoxB.Left) && (previousHitBoxA.Bottom > previousHitBoxB.Top))
                {
                   
                    collisionSide = new LeftSideCollision();
                }
                else
                    collisionSide = new TopSideCollision();
            }
            else if (isTopRightCorner(hitBoxA, hitBoxB))
            {
                if ((previousHitBoxA.Left >= previousHitBoxB.Right) && (previousHitBoxA.Bottom > previousHitBoxB.Top))
                {
                    
                    collisionSide = new RightSideCollision();
                    
                }
                else
                    collisionSide = new TopSideCollision();
            }
            else if (isBottomLeftCorner(hitBoxA, hitBoxB))
            {
                if ((previousHitBoxA.Right <= previousHitBoxB.Left) && (previousHitBoxA.Top < previousHitBoxB.Bottom))
                    collisionSide = new LeftSideCollision();
                else             
                    collisionSide = new BottomSideCollision();
            }
            else if (isBottomRightCorner(hitBoxA, hitBoxB))
            {
                if ((previousHitBoxA.Left >= previousHitBoxB.Right) && (previousHitBoxA.Top < previousHitBoxB.Bottom))
                {
                    collisionSide = new RightSideCollision();
                }
                else
                    collisionSide = new BottomSideCollision();
            }
            else
            {
                collisionSide = new TopSideCollision();
            }

            return collisionSide;
        }