예제 #1
0
        public void Update()
        {
            //playSceneButton.Update(playSceneButton_Delegate);
            Game1.isMouseVisible = true;


            playSceneButton.Update(playSceneButton_Delegate);
            void playSceneButton_Delegate()
            {
                Console.WriteLine("Play!");
                Game1.ChangeScene(WK.Scene.GameScene);
            }
        }
        public void Update()
        {
            // Implementation
            {
                goToMenu.Update(goToMenu_Delegate);
                playAgain.Update(playAgain_Delegate);
            }

            // Helpers
            void goToMenu_Delegate()
            {
                Console.WriteLine("Go to menu");
                Game1.ChangeScene(WK.Scene.Menu);
            }

            void playAgain_Delegate()
            {
                Console.WriteLine("Play again");
                Game1.ChangeScene(WK.Scene.GameScene);
            }
        }
        public void Update()
        {
            // gameover mode

            /*{
             *  KeyboardState keyboardState = Keyboard.GetState();
             *  if (keyboardState.IsKeyDown(Keys.P))
             *  {
             *      spaceship.Health -= 10;
             *      health.Reduce();
             *  }
             * }*/

            switch (gameState)
            {
            case GameState.Play:
                target.Update();
                spaceship.Update(bullets, target);

                asteroids = asteroids.Where(x => x.isActive == true).ToList();
                bullets   = bullets.Where(x => x.isActive == true).ToList();

                foreach (var asteroid in asteroids)
                {
                    asteroid.Update();
                }

                foreach (var bullet in bullets)
                {
                    bullet.Update();
                }


                foreach (var asteroid in asteroids)
                {
                    // destroy asteroids when bullet touch
                    foreach (var bullet in bullets)
                    {
                        if (bullet.rectangle.Intersects(asteroid.rectangle))
                        {
                            asteroid.isActive = false;
                            bullet.isActive   = false;

                            scoreCount += 15;

                            score.Update($"Score: {scoreCount}");
                        }
                    }


                    // destroy asteroids when spaceship touch
                    if (asteroid.rectangle.Intersects(spaceship.rectangle))
                    {
                        asteroid.isActive = false;

                        scoreCount -= 10;
                        if (scoreCount < 0)
                        {
                            scoreCount = 0;
                        }

                        spaceship.Health -= 10;
                        if (spaceship.Health < 0)
                        {
                            spaceship.Health = 0;
                        }

                        score.Update($"Score: {scoreCount}");
                        health.Reduce();
                    }
                }
                //time.Update();
                asteroidShooter.Update(asteroids, spaceship.rectangle.Center.ToVector2());
                break;

            case GameState.Pause:
                break;

            case GameState.GameOver:
                gameOverCanvas.Update();
                Game1.isMouseVisible = true;
                break;

            default:
                Game1.ChangeScene(WK.Scene.Menu);
                break;
            }
        }