예제 #1
0
        public static void Update(GameTime gameTime)
        {
            if (switchLevel)
            {
                setNum    = 1 - setNum;
                spriteSet = LevelManager.SwitchLevel(spriteSet, setNum, currentFilename);
                spriteSet.players[0].SetLocation(new Vector2(marioStartLocation.X, marioStartLocation.Y - 16));
                switchLevel = false;
            }

            CollisionChecker gameCollisionChecker = new CollisionChecker();

            gameCollisionChecker.CheckEachCollision(spriteSet.players, spriteSet.blocks, spriteSet.pipes, spriteSet.goombas, spriteSet.koopas, spriteSet.coins, spriteSet.items, spriteSet.projectiles);

            //When we are within a 1/3 of the camera's width from an enemy, begin to animate
            camera = GetCamera();
            int rightThreshold = (int)camera.GetPosition().X;

            foreach (Mario mario in spriteSet.players)
            {
                if (mario.IsDead())
                {
                    ResetAllCommand reset = new ResetAllCommand();
                    int             lives = mario.GetLives();
                    reset.Execute(game);
                    if (lives - 1 <= 0)
                    {
                        GameOver.ResetTimer();
                        GameOver.EndGame();
                    }
                    else
                    {
                        mario.SetLives(lives - 1);
                    }
                }

                mario.Update();
            }

            foreach (IPipe pipe in spriteSet.pipes)
            {
                pipe.Update();
            }

            foreach (Goomba goomba in spriteSet.goombas)
            {
                //If the goomba's x position is within 4/ of the width of the rectangle
                if (goomba.GetRectangle().X < ((20 + camera.GetPosition().X) + camera.GetWidth()))
                {
                    goomba.Update();
                }
            }

            foreach (Koopa koopa in spriteSet.koopas)
            {
                if (koopa.GetRectangle().X < ((20 + camera.GetPosition().X) + camera.GetWidth()))
                {
                    koopa.Update();
                }
            }

            foreach (IItem item in spriteSet.items)
            {
                item.Update();
            }

            foreach (IBlock block in spriteSet.blocks)
            {
                block.Update(gameTime);
            }

            foreach (Fireball fireball in spriteSet.projectiles)
            {
                fireball.Update();
            }

            camera.Update(gameTime);

            Display.Update(gameTime);
        }