コード例 #1
0
        public bool Update(Starfield stars, Player player, AlienManager aliens, UFOManager ufo, GraphicsDevice gDev)
        {
            bool gameover = false;

            stars.Update(gDev);
            gameover = !aliens.Update(gDev, player.Y);
            ufo.Update(gDev, player);
            player.UpdateBullets();

            return(!gameover);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: scott-cannard/invader-clone
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            bEvents.Update(GamePad.GetState(PlayerIndex.One), Keyboard.GetState());

            switch (phase)
            {
            case gamePhase.DEVINTRO:
                phase = scrIntro.HandleInput(bEvents, phase);
                if (scrIntro.IsDone())
                {
                    phase = gamePhase.SPLASH;
                }
                break;

            case gamePhase.SPLASH:
                //Move objects
                scrSplash.SplashDance(GraphicsDevice, ufo);
                //Check for input
                phase = scrSplash.HandleInput(bEvents, phase, ufo, player);
                break;

            case gamePhase.HIGHSCORES:
                break;

            case gamePhase.LOADLEVEL:
                //Initialize for play state
                scrLoader.Initialize(player, aliens, ufo);
                //Move objects
                scrLoader.Update(stars, player, aliens, ufo, GraphicsDevice);
                //Check timer
                if (scrLoader.IsDone())
                {
                    phase = gamePhase.PLAY;
                }
                break;

            case gamePhase.PLAY:
                //Move non-player objects
                if (!scrPlay.Update(stars, player, aliens, ufo, GraphicsDevice))
                {
                    phase = gamePhase.GAMEOVER;       //aliens have reached the bottom
                }
                //Random appearances
                ufo.Spawn(GraphicsDevice, player.level);
                aliens.Fire(player.level);

                //Check for input
                phase = scrPlay.HandleInput(bEvents, phase, player, GraphicsDevice);

                //Check for collisions
                scrPlay.DetectCollisions(player, aliens, ufo);

                //Change of state?
                if (player.lives == 0)
                {
                    phase = gamePhase.GAMEOVER;
                }
                else if (aliens.count() == 0)
                {
                    player.level++;
                    phase = gamePhase.LOADLEVEL;
                }
                break;

            case gamePhase.PAUSE:
                phase = scrPause.HandleInput(bEvents, phase);
                break;

            case gamePhase.GAMEOVER:
                //Move objects
                stars.Update(GraphicsDevice);
                //Check for input
                phase = scrGameover.HandleInput(bEvents, phase);
                break;

            case gamePhase.QUIT:
            default:
                this.Exit();
                break;
            }
            base.Update(gameTime);
        }