示例#1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            frameCounter++;
            string fps = string.Format(" fps: {0}", frameRate);

            Window.Title = "ZombieWallsAndTurrets" + fps;

            spriteBatch.Begin();
            switch (currentGameState)
            {
            case GameState.SplashScreen:

                spriteBatch.Draw(splashScreenBackground, Vector2.Zero, Color.Lerp(Color.Black, Color.White, colorlerp));
                break;

            case GameState.StartScreen:
                spriteBatch.Draw(menubackground, Vector2.Zero, Color.White);
                foreach (Button button in buttons)
                {
                    button.Draw(spriteBatch);
                }
                break;

            case GameState.Playing:
                spriteBatch.Draw(grassBackground, Vector2.Zero, Color.White);
                HomeBase.Draw(spriteBatch);
                foreach (Turret item in Turrets)
                {
                    item.Draw(spriteBatch);
                }
                foreach (Wall item in Walls)
                {
                    item.Draw(spriteBatch);
                }
                foreach (Zombie item in Zombies)
                {
                    item.Draw(spriteBatch);
                }
                foreach (Rectangle rect in worldGrid)
                {
#if Debug
                    Utility.RectClass.DrawBorder(pixel, spriteBatch, rect, 1, Color.Black, Color.Gray * 0.3f);
#endif
                }
                foreach (Zombie item in deadZombies)
                {
                    item.Draw(spriteBatch);
                }
                foreach (BloodPoof obj in bloodPoofs)
                {
                    obj.Draw(spriteBatch);
                }
                foreach (BrainDrop item in brains)
                {
                    item.Draw(spriteBatch);
                }
                prevViewWall.Draw(spriteBatch);
                if (DisplayLevelText)
                {
                    spriteBatch.DrawString(LevelChangeFont, "level " + (level + 1), new Vector2(this.Window.ClientBounds.Width / 2 - LevelChangeFont.MeasureString("level").X / 2, this.Window.ClientBounds.Height / 2 - LevelChangeFont.MeasureString("level").Y / 2), Color.Red);
                    spriteBatch.DrawString(LevelChangeFont, "Press Space", new Vector2(this.Window.ClientBounds.Width / 2 - LevelChangeFont.MeasureString("Press Space").X / 2, this.Window.ClientBounds.Height / 2 - LevelChangeFont.MeasureString("Press Space").Y / 2 + 80), Color.Red);
                }
                else
                {
                    spriteBatch.DrawString(LevelChangeFont, "", new Vector2(this.Window.ClientBounds.Width / 2 - LevelChangeFont.MeasureString("level").X / 2, this.Window.ClientBounds.Height / 2 - LevelChangeFont.MeasureString("level").Y / 2), Color.White);
                }
                invetory.Draw(spriteBatch);
#if Debug
                DrawDebugInfo(new Vector2(0, 0));
#endif
                break;

            case GameState.Paused:
                break;

            case GameState.GameOver:
                break;

            default:
                break;
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
示例#2
0
        protected override void Update(GameTime gameTime)
        {
            Input.Update();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //Fps counter
            elaspedTime += gameTime.ElapsedGameTime;
            if (elaspedTime > TimeSpan.FromSeconds(1))
            {
                elaspedTime -= TimeSpan.FromSeconds(1);
                frameRate    = frameCounter;
                frameCounter = 0;
            }
            //Fps counter
            switch (currentGameState)
            {
            case GameState.SplashScreen:
                if (splashScreenMusicPlaying)
                {
                    SplashScreenMusic.Play();
                    splashScreenMusicPlaying = false;
                }
                colorlerp += 0.004f;
                if (Input.LeftMouseButtonClick())
                {
                    currentGameState = GameState.StartScreen;
                    SplashScreenMusic.Dispose();
                }
                break;

            case GameState.StartScreen:
                foreach (Button button in buttons)
                {
                    button.Update(gameTime);
                }
                if (buttons[0].ButtonSelected && Input.LeftMouseButtonClick())
                {
                    currentGameState = GameState.Playing;
                }
                break;

            case GameState.Playing:
                #region [Input]
                for (int i = 0; i < worldCells.Count; i++)
                {
                    WorldCell cell = worldCells[i];
                    cell.index = i;
                    CreateTurretWithClick(cell);
                    WallPreview(cell);
                    CreateWallWithClick(cell);
                }
                foreach (Wall item in Walls)
                {
                    item.Update(gameTime);
                }
                prevViewWall.Update(gameTime);
                #endregion
                GamePlayingInitialTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                #region level Switch
                while (GamePlayingInitialTime > LEVELINITIALTIME)
                {
                    GamePlayingInitialTime = LEVELINITIALTIME;
                    createLevel(level);
                    if (Zombies.Count == 0)
                    {
                        DisplayLevelText = true;
                        levelChangeTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        if (levelChangeTime >= LEVELCHANGETIMER || Input.KeyPressed(Keys.Space))
                        {
                            created = false;
                            level++;
                            DisplayLevelText = false;
                            levelChangeTime  = 0;
                        }
                    }
                }
                #endregion
                HomeBase.Update();
                invetory.Update(gameTime);
                CreateZombieWithClick();
                UpdateZombiesHits(gameTime);
                RemoveDeadZombies();
                Updateturrets(gameTime);
                PlayGameMusic(gameTime);
                UpdateBloodPoofs(gameTime);
                UpdateBrainDrops(gameTime);
                break;

            case GameState.Paused:
                break;

            case GameState.GameOver:
                break;

            default:
                break;
            }
            base.Update(gameTime);
        }