public void SmallMarioGoombaBottomSideCollisionTest()
        {
            IMario testMario = new MarioInstance(game);
            testMario.VectorCoordinates = new Vector2(0, 14);
            IMario expectedMario = new MarioInstance(game);
            expectedMario.VectorCoordinates = new Vector2(0, 16);
            expectedMario.Damage();

            Goomba testGoomba = new Goomba(game);

            ICollisionSide side = new BottomSideCollision();
            CollisionData collision = new CollisionData(testMario, testGoomba, 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 FireMarioQuestionBlockBottomSideCollisionTest()
        {
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);
            expectedMario.VectorCoordinates = new Vector2(0, 15);

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

            ICollisionSide side = new BottomSideCollision();
            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 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);
        }
        public void NormalMarioKoopaBottomSideCollisionTest()
        {
            IMario testMario = new MarioInstance(game);
            testMario.VectorCoordinates = new Vector2(0, 19);
            IMario expectedMario = new MarioInstance(game);
            expectedMario.VectorCoordinates = new Vector2(0, 21);

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

            expectedMario.Damage();

            GreenKoopa testGreenKoopa = new GreenKoopa(game);

            ICollisionSide side = new BottomSideCollision();
            CollisionData collision = new CollisionData(testMario, testGreenKoopa, side);
            MarioEnemyCollisionHandler collisionHandler = new MarioEnemyCollisionHandler(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 StarSmallMarioGoombaBottomCollisionTest()
        {
            WorldManager.LoadListFromFile("World1-1", game);
            IMario testMario = WorldManager.GetMario();
            testMario.Star();
            testMario = WorldManager.GetMario();
            testMario.VectorCoordinates = new Vector2(0, 14);

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

            ICollisionSide side = new BottomSideCollision();
            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(0, 16);

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

            GreenKoopa testGreenKoopa = new GreenKoopa(game);
            testGreenKoopa.VectorCoordinates = new Vector2(0, 0);
            GreenKoopa expectedGreenKoopa = new GreenKoopa(game);
            expectedGreenKoopa.Flipped();

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

            collisionHandler.HandleCollision();

            bool testState = testGreenKoopa.state is GreenKoopaFlippedInShellState;
            bool expectedState = expectedGreenKoopa.state is GreenKoopaFlippedInShellState;
            Vector2 testLocation = testMario.VectorCoordinates;
            Vector2 expectedLocation = new Vector2(0, 21);

            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;
        }
        public void FireMarioRedMushroomBottomSideCollisionTest()
        {
            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 BottomSideCollision();
            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 SmallMarioStarBottomSideCollisionTest()
        {
            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 BottomSideCollision();
            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 SmallMarioCoinBottomSideCollisionTest()
        {
            MarioInstance testMario = new MarioInstance(game);
            MarioInstance expectedMario = new MarioInstance(game);

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

            ICollisionSide side = new BottomSideCollision();
            CollisionData collision = new CollisionData(testMario, testCoin, 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);
        }