Ejemplo n.º 1
0
        public void SmallMarioEnemyBottomCollision()
        {
            //arrange
            game.level.mario = new Mario(game, starting);
            CollisionDetector collision = new CollisionDetector(game);
            Enemy             enemy     = new Enemy(game, Enemy.Enemies.Dino, new Vector2(250, 440));

            levelEnemies.Add(enemy);
            //act
            collision.Detect(game.level.mario, levelEnemies, levelBlocks, levelItems);
            //assert
            if ((new DeadMS(game).GetType()) == game.level.mario.state.GetType())
            {
                fileOut.WriteLine("SmallMarioEnemyBottomCollision: Passed");
            }
            else
            {
                fileOut.WriteLine("SmallMarioEnemyBottomCollision: Failed");
            }
        }
Ejemplo n.º 2
0
        public void BigMarioBrickBlockBottomCollision()
        {
            //arrange
            game.level.mario = new Mario(game, starting);
            CollisionDetector collision = new CollisionDetector(game);
            Block             block     = new Block(game, Block.BlockType.brick, new Vector2(250, 445));

            levelBlocks.Add(block);
            //act
            collision.Detect(game.level.mario, levelEnemies, levelBlocks, levelItems);
            //assert
            if (new List <Block>() == levelBlocks)
            {
                fileOut.WriteLine("BigMarioBrickBottomCollision: Passed");
            }
            else
            {
                fileOut.WriteLine("BigMarioBrickBottomCollision: Failed");
            }
        }
Ejemplo n.º 3
0
        public void SmallMarioFlowerCollision()
        {
            //arrange
            game.level.mario = new Mario(game, starting);
            CollisionDetector collision = new CollisionDetector(game);
            IAnimatedSprite   flower    = factory.build(SpriteFactory.sprites.fireFlower);
            Item item = new Item(flower);

            item.xpos = 250;
            item.ypos = 450;
            levelItems.Add(item);
            //act
            collision.Detect(game.level.mario, levelEnemies, levelBlocks, levelItems);
            //assert
            if ((new RightIdleFireMS(game).GetType()) == game.level.mario.state.GetType())
            {
                fileOut.WriteLine("SmallMarioFlowerCollision: Passed");
            }
            else
            {
                fileOut.WriteLine("SmallMarioFlowerCollision: Failed");
            }
        }
Ejemplo n.º 4
0
        public void MarioStarCollision()
        {
            //arrange
            game.level.mario = new Mario(game, starting);
            CollisionDetector collision = new CollisionDetector(game);
            IAnimatedSprite   star      = factory.build(SpriteFactory.sprites.star);
            Item item = new Item(star);

            item.xpos = 250;
            item.ypos = 450;
            levelItems.Add(item);
            //act
            collision.Detect(game.level.mario, levelEnemies, levelBlocks, levelItems);
            //assert
            if (game.level.mario.marioIsStar)
            {
                fileOut.WriteLine("MarioStarCollision: Passed");
            }
            else
            {
                fileOut.WriteLine("MarioStarCollision: Failed");
            }
        }
Ejemplo n.º 5
0
        public void Mario1UpCollision()
        {
            //arrange
            game.level.mario = new Mario(game, starting);
            levelItems       = new List <Item>();
            CollisionDetector collision = new CollisionDetector(game);
            IAnimatedSprite   oneUp     = factory.build(SpriteFactory.sprites.oneUpMushroom);
            Item item = new Item(oneUp);

            item.xpos = 250;
            item.ypos = 450;
            levelItems.Add(item);
            //act
            collision.Detect(game.level.mario, levelEnemies, levelBlocks, levelItems);
            //assert
            if (levelItems == new List <Item>())
            {
                fileOut.WriteLine("Mario1UpCollision: Passed");
            }
            else
            {
                fileOut.WriteLine("Mario1UpCollision: Failed");
            }
        }
Ejemplo n.º 6
0
        public void Update(GameTime gameTime)
        {
            game.background.CurrentSprite.Update(gameTime);
            foreach (KeyValuePair <IAnimatedSprite, Vector2> backgroundObject in levelBackgroundObjects)
            {
                backgroundObject.Key.Update(gameTime);
            }
            foreach (Trampoline trampolineDrawer in levelTrampolines)
            {
                if (game.gameCamera.InCameraView(trampolineDrawer.GetBoundingBox()))
                {
                    trampolineDrawer.Update(gameTime);
                }
            }
            foreach (Enemy enemy in levelEnemies)
            {
                if (game.gameCamera.InCameraView(enemy.GetBoundingBox()))
                {
                    enemy.Update(gameTime);
                }
            }
            foreach (ICollectable item in levelItems)
            {
                if (game.gameCamera.InCameraView(item.GetBoundingBox()))
                {
                    item.Update(gameTime);
                }
            }
            foreach (Block blockUpdater in levelBlocks)
            {
                if (game.gameCamera.InCameraView(blockUpdater.GetBoundingBox()))
                {
                    blockUpdater.Update(gameTime);
                }
            }
            foreach (Pipe pipeUpdater in levelPipes)
            {
                if (game.gameCamera.InCameraView(pipeUpdater.GetBoundingBox()))
                {
                    pipeUpdater.Update(gameTime);
                }
            }
            if (game.gameCamera.InCameraView(exitPole.GetBoundingBox(exitPosition)))
            {
                exitPole.Update(gameTime);
            }
            foreach (Spike spike in levelSpikes)
            {
                if (game.gameCamera.InCameraView(spike.GetBoundingBox()))
                {
                    spike.Update(gameTime);
                }
            }
            foreach (Fireball fireball in levelFireballs)
            {
                fireball.Update(gameTime);
                if (fireball.fireballLifespan == 0)
                {
                    deadFireballs.Add(fireball);
                    if (mario.fireballCount > 0)
                    {
                        mario.fireballCount--;
                    }
                }
            }
            foreach (Fireball fireball in deadFireballs)
            {
                levelFireballs.Remove(fireball);
            }
            foreach (ThrowingStar throwingStar in levelThrowingStars)
            {
                throwingStar.Update(gameTime);
                if (throwingStar.throwingStarLifespan == 0)
                {
                    deadThrowingStars.Add(throwingStar);
                    if (mario.throwingStarCount > 0)
                    {
                        mario.throwingStarCount--;
                    }
                }
            }
            foreach (ThrowingStar throwingStar in deadThrowingStars)
            {
                levelThrowingStars.Remove(throwingStar);
            }

            collision.Detect(mario, levelFireballs, levelThrowingStars, levelEnemies, levelBlocks, levelItems, levelPipes, levelSpikes, levelTrampolines);

            mario.Update(gameTime);
            if (mario.position.X < 0)
            {
                mario.position.X = 0;
            }
            if (mario.position.X > exitPosition.X && !isVictory && !isUnderground)
            {
                game.gameState = new VictoryGameState();
                exitPole       = new GateSprite(Game1.gameContent.Load <Texture2D>("Items/gateBroken"), 1, 1);
                isVictory      = true;
            }
            game.gameCamera.LookAt(mario.position);
        }