Exemple #1
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     BlockSpriteFactory.Instance.LoadAllTextures(Content);
     ItemSpriteFactory.Instance.LoadAllTextures(Content);
     PipeSpriteFactory.Instance.LoadAllTextures(Content);
     EnemySpriteFactory.Instance.LoadAllTextures(Content);
     MarioSpriteFactory.Instance.LoadAllTextures(Content);
     GameUtilities.Game = this;
     currentTest        = 1;
     isInitializing     = true;
     testHandler        = new AllCollisionHandler();
 }
Exemple #2
0
        public bool TestMarioBlockCollisions()
        {
            IGameObject marioLeftBlock   = new Mario(new Vector2(40, 52));
            IGameObject leftBlock        = new BrickBlock(new Vector2(50, 50));
            IGameObject marioTopBlock    = new Mario(new Vector2(101, 90));
            IGameObject topBlock         = new BrickBlock(new Vector2(100, 100));
            IGameObject marioRightBlock  = new Mario(new Vector2(160, 153));
            IGameObject rightBlock       = new BrickBlock(new Vector2(150, 150));
            IGameObject marioBottomBlock = new Mario(new Vector2(200, 210));
            IGameObject bottomBlock      = new BrickBlock(new Vector2(200, 200));
            IGameObject marioNoBlock     = new Mario(new Vector2(0, 100));
            IGameObject noCollisionBlock = new BrickBlock(new Vector2(0, 0));

            Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand> testDictionary = new Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand>
            {
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Block, Object2Side.Top), new MarioBlockCollisionTopCommand() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Block, Object2Side.Right), new MarioBlockCollisionRightCommand() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Block, Object2Side.Bottom), new MarioBlockCollisionBottomCommand() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Block, Object2Side.Left), new MarioBlockCollisionLeftCommand() }
            };
            AllCollisionHandler testHandler = new AllCollisionHandler(testDictionary);

            Console.WriteLine("Tests for collision side of Mario-Brick collisions.");
            string leftOutputDetails        = "Succesful recognition of left side of block collision: ";
            bool   leftCollision            = TestCollisionSide(leftOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioLeftBlock.Destination, leftBlock.Destination), Object2Side.Left);
            string topOutputDetails         = "Succesful recognition of top side of block collision: ";
            bool   topCollision             = TestCollisionSide(topOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioTopBlock.Destination, topBlock.Destination), Object2Side.Top);
            string rightOutputDetails       = "Succesful recognition of right side of block collision: ";
            bool   rightCollision           = TestCollisionSide(rightOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioRightBlock.Destination, rightBlock.Destination), Object2Side.Right);
            string bottomOutputDetails      = "Succesful recognition of bottom side of block collision: ";
            bool   bottomCollision          = TestCollisionSide(bottomOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioBottomBlock.Destination, bottomBlock.Destination), Object2Side.Bottom);
            string noCollisionOutputDetails = "Succesful recognition of no block collision: ";
            bool   noCollision = TestCollisionSide(noCollisionOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioNoBlock.Destination, noCollisionBlock.Destination), Object2Side.NoCollision);

            Console.WriteLine();

            bool areCollisionsSuccessful = leftCollision && topCollision && rightCollision && bottomCollision && noCollision;

            testHandler.HandleCollision(marioLeftBlock, leftBlock);
            testHandler.HandleCollision(marioRightBlock, rightBlock);
            testHandler.HandleCollision(marioBottomBlock, bottomBlock);
            testHandler.HandleCollision(marioTopBlock, topBlock);
            testHandler.HandleCollision(marioNoBlock, noCollisionBlock);

            Console.WriteLine("Tests for collision side of handled Mario-Brick collisions (No collisions).");
            string leftHandledOutputDetails = "Succesful handling of left side of block collision: ";
            bool   leftHandled             = TestCollisionSide(leftHandledOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioLeftBlock.Destination, leftBlock.Destination), Object2Side.NoCollision);
            string topHandledOutputDetails = "Succesful handling of top side of block collision: ";
            bool   topHandled = TestCollisionSide(topHandledOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioTopBlock.Destination, topBlock.Destination), Object2Side.NoCollision);
            string rightHandledOutputDetails = "Succesful handling of right side of block collision: ";
            bool   rightHandled = TestCollisionSide(rightHandledOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioRightBlock.Destination, rightBlock.Destination), Object2Side.NoCollision);
            string bottomHandledOutputDetails = "Succesful handling of bottom side of block collision: ";
            bool   bottomHandled = TestCollisionSide(bottomHandledOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioBottomBlock.Destination, bottomBlock.Destination), Object2Side.NoCollision);
            string noCollisionHandledOutputDetails = "Succesful handling of no block collision: ";
            bool   noCollisionHandled = TestCollisionSide(noCollisionHandledOutputDetails, AllCollisionHandler.DetermineCollisionSide(marioNoBlock.Destination, noCollisionBlock.Destination), Object2Side.NoCollision);

            Console.WriteLine();

            bool areHandlingsSuccessful = leftHandled && topHandled && rightHandled && bottomHandled && noCollisionHandled;

            marioLeftBlock.Draw(spriteBatch);
            leftBlock.Draw(spriteBatch);
            marioTopBlock.Draw(spriteBatch);
            topBlock.Draw(spriteBatch);
            marioRightBlock.Draw(spriteBatch);
            rightBlock.Draw(spriteBatch);
            marioBottomBlock.Draw(spriteBatch);
            bottomBlock.Draw(spriteBatch);
            marioNoBlock.Draw(spriteBatch);
            noCollisionBlock.Draw(spriteBatch);

            return(areCollisionsSuccessful && areHandlingsSuccessful);
        }
Exemple #3
0
        public bool TestMarioCoinCollisions()
        {
            bool isSuccess = true;

            IGameObject marioLeftCoin   = new Mario(new Vector2(40, 52));
            IGameObject leftCoin        = new Coin(new Vector2(50, 50));
            IGameObject marioTopCoin    = new Mario(new Vector2(101, 90));
            IGameObject topCoin         = new Coin(new Vector2(100, 100));
            IGameObject marioRightCoin  = new Mario(new Vector2(160, 153));
            IGameObject rightCoin       = new Coin(new Vector2(150, 150));
            IGameObject marioBottomCoin = new Mario(new Vector2(200, 210));
            IGameObject bottomCoin      = new Coin(new Vector2(200, 200));
            IGameObject marioNoCoin     = new Mario(new Vector2(0, 100));
            IItem       noCollisionCoin = new Coin(new Vector2(0, 0));

            Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand> testDictionary = new Dictionary <Tuple <ObjectType, ObjectType, Object2Side>, ICollisionCommand>
            {
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Top), new MarioCoinCollisionTop() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Right), new MarioKoopaCollisionRight() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Bottom), new MarioKoopaCollisionBottom() },
                { new Tuple <ObjectType, ObjectType, Object2Side>(ObjectType.Mario, ObjectType.Goomba, Object2Side.Left), new MarioKoopaCollisionLeft() }
            };
            AllCollisionHandler testHandler = new AllCollisionHandler(testDictionary);

            Console.WriteLine("Tests for collision side of Mario-Goomba collisions.");
            Console.Write("Succesful recognition of left side of Goomba collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioLeftCoin.Destination, leftCoin.Destination) == Object2Side.Left);
            Console.Write("Succesful recognition of top side of Goomba collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioTopCoin.Destination, topCoin.Destination) == Object2Side.Top);
            Console.Write("Succesful recognition of right side of Goomba collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioRightCoin.Destination, rightCoin.Destination) == Object2Side.Right);
            Console.Write("Succesful recognition of bottom side of Goomba collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioBottomCoin.Destination, bottomCoin.Destination) == Object2Side.Bottom);
            Console.Write("Succesful recognition of no Goomba collision: ");
            Console.WriteLine(AllCollisionHandler.DetermineCollisionSide(marioNoCoin.Destination, noCollisionCoin.Destination) == Object2Side.NoCollision);
            Console.WriteLine();

            testHandler.HandleCollision(marioLeftCoin, leftCoin);
            testHandler.HandleCollision(marioRightCoin, rightCoin);
            testHandler.HandleCollision(marioBottomCoin, bottomCoin);
            testHandler.HandleCollision(marioTopCoin, topCoin);
            testHandler.HandleCollision(marioNoCoin, noCollisionCoin);

            /*Vector2 leftCollisionResult = new Vector2(50, 52);
             * Vector2 topCollisionResult = new Vector2(101, 100);
             * Vector2 rightCollisionResult = new Vector2(150, 153);
             * Vector2 bottomCollisionResult = new Vector2(200, 200);
             * Vector2 noCollisionResult = new Vector2(0, 100);
             *
             * Console.WriteLine("Tests for Mario-Coin collisions.");
             * Console.Write("Succesful left side of Coin collision: (50, 52) = (");
             * Console.Write(marioLeftCoin.Location.X);
             * Console.Write(", ");
             * Console.Write(marioLeftCoin.Location.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioLeftCoin.Destination.X == (int)leftCollisionResult.X && marioLeftCoin.Destination.Y == (int)leftCollisionResult.Y);
             * Console.Write("Succesful top side of Coin collision: (101, 90) = (");
             * Console.Write(marioTopCoin.Location.X);
             * Console.Write(", ");
             * Console.Write(marioTopCoin.Location.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioTopGoomba.Destination.X == (int)topCollisionResult.X && marioTopGoomba.Destination.Y == (int)topCollisionResult.Y);
             * Console.Write("Succesful right side of Coin collision: (150, 153) = (");
             * Console.Write(marioRightCoin.Location.X);
             * Console.Write(", ");
             * Console.Write(marioRightCoin.Location.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioRightCoin.Destination.X == (int)rightCollisionResult.X && marioRightCOin.Destination.Y == (int)rightCollisionResult.Y);
             * Console.Write("Succesful bottom side of Coin collision: (200, 200) = (");
             * Console.Write(marioBottomCoin.Location.X);
             * Console.Write(", ");
             * Console.Write(marioBottomCoin.Location.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioBottomCoin.Destination.X == (int)bottomCollisionResult.X && marioBottomCoin.Destination.Y == (int)bottomCollisionResult.Y);
             * Console.Write("Succesful no Coin collision: (0, 100) = (");
             * Console.Write(marioNoCoin.Location.X);
             * Console.Write(", ");
             * Console.Write(marioNoCoin.Location.Y);
             * Console.WriteLine(")");
             * isSuccess = isSuccess && (marioNoCoin.Destination.X == (int)noCollisionResult.X && marioNoGoombaCoin.Destination.Y == (int)noCollisionResult.Y);
             * Console.WriteLine();
             * Console.Write("Mario-Coin collision tests are successful: ");
             * Console.WriteLine(isSuccess);
             * Console.WriteLine();
             *
             * marioLeftCoin.Draw(spriteBatch);
             * leftCoin.Draw(spriteBatch);
             * marioTopCoin.Draw(spriteBatch);
             * topCoin.Draw(spriteBatch);
             * marioRightCoin.Draw(spriteBatch);
             * rightCoin.Draw(spriteBatch);
             * marioBottomCoin.Draw(spriteBatch);
             * bottomCoin.Draw(spriteBatch);
             * marioNoCoin.Draw(spriteBatch);
             * noCollisionCoin.Draw(spriteBatch);*/

            return(isSuccess);
        }