public void SmallMarioKoopaLeftSideCollisionTest() { MarioInstance testMario = new MarioInstance(game); MarioInstance expectedMario = new MarioInstance(game); expectedMario.VectorCoordinates = new Vector2(-1, 0); expectedMario.Damage(); GreenKoopa testGreenKoopa = new GreenKoopa(game); testGreenKoopa.VectorCoordinates = new Vector2(11, 0); ICollisionSide side = new LeftSideCollision(); 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 FireMarioStarLeftSideCollisionTest() { WorldManager.LoadListFromFile("World1-1", game); MarioInstance testMario = new MarioInstance(game); MarioInstance expectedMario = new MarioInstance(game); testMario.Flower(); expectedMario.Flower(); expectedMario.Star(); Star testStar = new Star(game); Star expectedStar = new Star(game); expectedStar.Disappear(); ICollisionSide side = new LeftSideCollision(); CollisionData collision = new CollisionData(testMario, testStar, 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 BigMarioRedMushroomLeftSideCollisionTest() { MarioInstance testMario = new MarioInstance(game); MarioInstance expectedMario = new MarioInstance(game); expectedMario.Mushroom(); testMario.Mushroom(); RedMushroom testRedMushroom = new RedMushroom(game); RedMushroom expectedRedMushroom = new RedMushroom(game); expectedRedMushroom.Disappear(); ICollisionSide side = new LeftSideCollision(); CollisionData collision = new CollisionData(testMario, testRedMushroom, 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 StarSmallMarioKoopaCollisionLeftTest() { WorldManager.LoadListFromFile("World1-1", game); IMario testMario = WorldManager.GetMario(); testMario.Star(); testMario = WorldManager.GetMario(); testMario.VectorCoordinates = new Vector2(0, 0); GreenKoopa testGreenKoopa = new GreenKoopa(game); testGreenKoopa.VectorCoordinates = new Vector2(11, 0); GreenKoopa expectedGreenKoopa = new GreenKoopa(game); expectedGreenKoopa.Flipped(); ICollisionSide side = new LeftSideCollision(); 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(-1, 0); Assert.AreEqual(testState, expectedState); Assert.AreEqual(testLocation, expectedLocation); }
public void FireMarioCoinLeftSideCollisionTest() { MarioInstance testMario = new MarioInstance(game); MarioInstance expectedMario = new MarioInstance(game); testMario.Flower(); expectedMario.Flower(); Coin testCoin = new Coin(game); Coin expectedCoin = new Coin(game); expectedCoin.Disappear(); ICollisionSide side = new LeftSideCollision(); CollisionData collision = new CollisionData(testMario, testCoin, 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 FireMarioGoombaLeftSideCollisionTest() { MarioInstance testMario = new MarioInstance(game); MarioInstance expectedMario = new MarioInstance(game); expectedMario.VectorCoordinates = new Vector2(-1, 0); testMario.MarioState = new FireRightIdleState(testMario); expectedMario.MarioState = new FireRightIdleState(expectedMario); expectedMario.Damage(); Goomba testGoomba = new Goomba(game); testGoomba.VectorCoordinates = new Vector2(14, 0); ICollisionSide side = new LeftSideCollision(); 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 StarFireMarioGoombaLeftCollisionTest() { WorldManager.LoadListFromFile("World1-1", game); IMario testMario = WorldManager.GetMario(); testMario.Flower(); testMario.Star(); testMario = WorldManager.GetMario(); testMario.VectorCoordinates = new Vector2(0, 0); Goomba testGoomba = new Goomba(game); testGoomba.VectorCoordinates = new Vector2(14, 0); Goomba expectedGoomba = new Goomba(game); expectedGoomba.Flipped(); ICollisionSide side = new LeftSideCollision(); 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(-1, 0); Assert.AreEqual(testState, expectedState); Assert.AreEqual(testLocation, expectedLocation); }
public void BigMarioHiddenBlockLeftSideCollisionTest() { 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 LeftSideCollision(); CollisionData collision = new CollisionData(testMario, testBlock, side); MarioBlockCollisionHandler collisionHandler = new MarioBlockCollisionHandler(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 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); }