Exemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            switch (state)
            {
            case GameState.Splash:
                splashCurrent += time;
                if (splashCurrent > splashColorInterval)
                {
                    splashCurrent   = 0f;
                    splashColor     = nextSplashColor;
                    nextSplashColor = new Color(Utility.Rand(0f, 1f), Utility.Rand(0f, 1f), Utility.Rand(0f, 1f));
                }
                if (input.KeyClicked(Keys.Space))
                {
                    state = GameState.Loading;
                }
                break;

            case GameState.Loading:
                if (loaded)
                {
                    state = GameState.Loaded;
                }
                break;

            case GameState.Loaded:
                Start();
                state = GameState.None;
                break;

            case GameState.GameOver:
                splashCurrent += time;
                if (splashCurrent > splashColorInterval)
                {
                    splashCurrent   = 0f;
                    splashColor     = nextSplashColor;
                    nextSplashColor = new Color(Utility.Rand(0f, 1f), Utility.Rand(0f, 1f), Utility.Rand(0f, 1f));
                }
                if (input.KeyClicked(Keys.Space) || input.KeyClicked(Keys.Enter) || input.KeyClicked(Keys.Escape))
                {
                    this.Exit();
                }
                break;

            case GameState.None:
                if (!paused)
                {
                    if (input.KeyClicked(Keys.Escape))
                    {
                        paused = true;
                        audio.PlaySound("blip");
                        audio.PauseAll();
                    }
                }
                else if (paused)
                {
                    if (input.KeyClicked(Keys.Escape))
                    {
                        this.Exit();
                    }
                    if (input.KeyClicked(Keys.Enter))
                    {
                        paused = false;
                        audio.ResumeAll();
                    }
                }


                if (!paused)
                {
                    bgFlicker += blurFactor * (0.0005f * time);
                    if (bgFlicker < 0f)
                    {
                        bgFlicker   = 0f;
                        blurFactor *= -1f;
                    }
                    if (bgFlicker > 1f)
                    {
                        bgFlicker   = 1f;
                        blurFactor *= -1f;
                    }

                    level.Update(time, pMan, character);
                    character.Update(time, input, level);
                    if (!character.alive)
                    {
                        if (!character.splatted)
                        {
                            pMan.BloodSplat(new Vector2(character.CollRect.Center.X, character.CollRect.Center.Y));
                            character.splatted = true;
                        }
                        currentDeath += time;
                        if (currentDeath > deathWait || input.KeyClicked(Keys.Space))
                        {
                            currentDeath = 0;
                            RestartLevel();
                        }
                    }
                    pMan.Update(time, character);
                }
                else
                {
                }
                if (level.Cleared(character, input))
                {
                    NextLevel();
                }
                else
                {
                    fadeIn.Update(time);
                    cam.Move(character.position);
                    cam.Update(time);
                    hud.Update(time);
                }
                audio.Update();
                break;

            default:
                break;
            }
            input.Update(time);

            base.Update(gameTime);
        }