Пример #1
0
        /// <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)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            // TODO: Add your update logic here

            MouseState mouse = Mouse.GetState();

            // Game State Managing
            switch (currentGameState)
            {
                case GameState.MainMenu:

                    if (buttonPlay.isClicked == true)
                    {
                        currentGameState = GameState.Playing;

                        // Player Initialization
                        player = new Player(Content.Load<Texture2D>("res/player/playerRifle"));
                        player.setPosition(50, 50);
                    }

                    buttonPlay.Update(mouse);
                    break;

                case GameState.Playing:

                    player.Update(Keyboard.GetState(), Mouse.GetState(), this);

                    foreach (Zombie z in zombies)
                    {
                        z.Update(player, Keyboard.GetState(), mouse, this);
                    }

                    // Shooting The Weapon
                    if (mouse.LeftButton == ButtonState.Pressed)
                    {
                        if (!leftClicked)
                        {
                            bullets.Add(new Bullet(Content.Load<Texture2D>("res/bullets/bullet2"),
                            mouse, player.position, 20));
                            leftClicked = true;
                        }
                    }
                    // Clearing The Mouse Button
                    else
                    {
                        leftClicked = false;
                    }

                    // Making Zombies
                    if (mouse.RightButton == ButtonState.Pressed)
                    {
                        if (!rightClicked)
                        {
                            zombies.Add(new Zombie(Content.Load<Texture2D>("res/ZomTest/zTest"),Mouse
                                .GetState().X, Mouse.GetState().Y));
                            rightClicked = true;
                        }
                    }
                    // Clearing The Mouse Button
                    else
                    {
                        rightClicked = false;
                    }

                    // Bullet Updating
                    foreach (Bullet b in bullets)
                    {
                        b.Update();
                        if (Vector2.Distance(b.position, player.position) > 750)
                            b.isVisible = false;
                    }

                    // Clearing Lost Bullets
                    for (int x = 0; x < bullets.Count; x++)
                    {
                        if (!bullets[x].isVisible)
                            bullets.RemoveAt(x);
                    }

                        break;

                case GameState.Options:

                    break;
            }

            base.Update(gameTime);
        }