예제 #1
0
        protected override void OnUpdate(GameTime gameTime)
        {
            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.Escape) || this.btContinue.OnClick())
            {
                if (!isPaused)
                {
                    this.Game.IsMouseVisible = true;
                    this.isPaused            = true;
                    this.pausePanel.Show();
                }
                else
                {
                    this.isPaused = false;
                    this.pausePanel.Hide();
                    this.Game.IsMouseVisible = false;
                }
            }

            if (isPaused)
            {
                if (this.btEndGame.OnClick())
                {
                    SwitchScene <GameOverScene>();
                    ////this.pausePanel.Hide();
                }

                if (this.btBackToMain.OnClick())
                {
                    SwitchScene <MainMenuScene>();
                }

                return;
            }

            ////if (KeyboardManager.IsKeyDown(Keys.Tab))    //only show scoreboard in multiplayer
            ////{
            ////    this.scoreboardUI.Show();
            ////}
            ////else
            ////{
            ////    this.scoreboardUI.Hide();
            ////}

            this.Camera.Origin = WindowSettings.RenderArea.Size.ToVector2() / 2f;
            this.Camera.SetBounds(Vector2.Zero, (GameConfig.WorldSize - WindowSettings.RenderArea.Size + WindowSettings.RenderArea.Location).ToVector2());

#if DEBUG
            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.N))
            {
                this.entityFactory.CreateAsteroid(GameConfig.PlayArea);
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.M))
            {
                this.entityFactory.SpawnAsteroids(GameConfig.PlayArea, 100);
            }

            if (MouseInput.OnScrollWheelUp())
            {
                this.Camera.Zoom *= 1.125f;
                Console.WriteLine($"EntityZoom: {this.Camera.Zoom}");
            }

            if (MouseInput.OnScrollWheelDown())
            {
                this.Camera.Zoom /= 1.125f;
                Console.WriteLine($"EntityZoom: {this.Camera.Zoom}");
            }
#endif

            float elapsedSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            this.inputManager.Update();

            if (this.countdownValue <= 0)
            {
                this.entityWorld.Update(elapsedSeconds);
                this.particleEngine.Update(elapsedSeconds);

                this.ProcessSignals();

                if (this.tagCountSystem.EntityCount(GameConfig.Asteroid.Tag) == 0)
                {
                    // game won
                    SwitchScene <GameOverScene>();
                }

                if (this.tagCountSystem.EntityCount(GameConfig.Spaceship.Tag) == 0)
                {
                    // game lost
                    SwitchScene <GameOverScene>();
                }

                if (myEntity != null)
                {
                }
            }
            else
            {
                this.entityWorld.Update(0);
                this.timeSinceCountdownChange += elapsedSeconds;
                if (this.timeSinceCountdownChange > 1)
                {
                    this.timeSinceCountdownChange = 0;
                    this.countdownValue--;
                    this.CheckCountdownValue();
                }
            }

            if (this.myEntity != null)
            {
                TransformComponent transform = this.entityWorld.ComponentManager.GetComponent <TransformComponent>(this.myEntity.EntityId);
                this.Camera.FocusOn(transform.Position * WindowSettings.UnitScale, 0.05f);
            }
        }