Beispiel #1
0
 protected override void Update(GameTime gameTime)
 {
     InputManager.Instance.Update(gameTime);
     _fpsCounter.Update(gameTime);
     Scene.Update(gameTime);
     base.Update(gameTime);
 }
Beispiel #2
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)
        {
            // Update frame time
            _dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            _fps.Update(gameTime);

            // Update the current scene
            if (_scenes.Top != null)
            {
                _bgColor = _scenes.Top.WindowBackgroundColor;
                _scenes.Top.DeltaTime = _dt;
            }

            // Check for quit request
            if (ForceQuit)
            {
                Exit();
            }

            _scenes.Update();

            _debugConsole.Update();

            base.Update(gameTime);             // Monogame update
        }
Beispiel #3
0
        public void Update(GameTime gameTime)
        {
            var context = CallContext <GlobalContextPresentation> .GetData("GlobalContextPresentation");

            var gameWindow     = context.GameWindow;
            var graphicsDevice = context.GraphicsDevice;
            var camera         = context.Camera;

            _fps.Update(gameTime, _viewport);

            var mouseState    = Mouse.GetState();
            var worldPosition = camera.ScreenPixelToWorldPixel(mouseState.Position);
            var worldHex      = camera.ScreenPixelToWorldHex(mouseState.Position);

            ((Label)Controls["lblFps2"]).Text            = $"{_fps.UpdateFramesPerSecond}/{_fps.DrawFramesPerSecond}";
            ((Label)Controls["lblGcCount2"]).Text        = $"{GC.CollectionCount(0)},{GC.CollectionCount(1)},{GC.CollectionCount(2)}";
            ((Label)Controls["lblMemory2"]).Text         = $"{(GC.GetTotalMemory(false) / 1024):N0} KB";
            ((Label)Controls["lblScreenPosition2"]).Text = $"({mouseState.Position.X},{mouseState.Position.Y})";
            ((Label)Controls["lblWorldPosition2"]).Text  = $"({worldPosition.X:F0},{worldPosition.Y:F0})";
            ((Label)Controls["lblWorldHex2"]).Text       = $"{worldHex.Col},{worldHex.Row}";
            ((Label)Controls["lblZoom2"]).Text           = $"{camera.Zoom}";

            //((Label)Controls["lblResolution12"]).Text = $"{gameWindow.ClientBounds.Width}x{gameWindow.ClientBounds.Height}";
            //((Label)Controls["lblResolution22"]).Text = $"{_viewportAdapter.Viewport.Width}x{_viewportAdapter.Viewport.Height}";
            //((Label)Controls["lblResolution32"]).Text = $"{graphicsDevice.DisplayMode.Width}x{graphicsDevice.DisplayMode.Height}";
            //((Label)Controls["lblResolution42"]).Text = $"{GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width}x{GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height}";

            //("lblResolution11", "ClientBounds:"),
            //("lblResolution21", "Viewport:"),
            //("lblResolution31", "DisplayMode:"),
            //("lblResolution41", "CurrentDisplayMode:")
        }
Beispiel #4
0
        protected override void Update(GameTime gameTime)
        {
            var keyboard     = Keyboard.GetState();
            var gamePadState = GamePad.GetState(PlayerIndex.One);

            if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var index = 0; index < _sprites.Length; index++)
            {
                var sprite = _sprites[index];

                if (index % 2 == 0)
                {
                    sprite.Rotation = (sprite.Rotation + MathHelper.ToRadians(0.5f)) % MathHelper.TwoPi;
                }
                else
                {
                    sprite.Rotation = (sprite.Rotation - MathHelper.ToRadians(0.5f) + MathHelper.TwoPi) % MathHelper.TwoPi;
                }

                sprite.Color = ColorHelper.FromHsl(sprite.Rotation / MathHelper.TwoPi, 0.5f, 0.3f);

                sprite.TransformMatrix = Matrix2D.CreateFrom(sprite.Position, sprite.Rotation, _spriteScale, _spriteOrigin);

                _sprites[index] = sprite;
            }

            _fpsCounter.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #5
0
        protected override void Update(GameTime gameTime)
        {
#if DEBUG
            _frames.Update(gameTime);
#endif
            base.Update(gameTime);
        }
Beispiel #6
0
        public override void Update(GameTime gameTime)
        {
            fpsCounter.Update(gameTime);
            state = GetLitteralState();

            PlayerCoordinates = Nocubeless.CubeWorld.GetCoordinatesFromGraphics(Nocubeless.Camera.ScreenPosition);
            ChunkCoordinates  = CubeChunkHelper.FindBaseCoordinates(PlayerCoordinates);

            int margin = 2;

            coordinatesDrawPosition = new Vector2(margin, margin);
            fpsDrawPosition         = new Vector2(GraphicsDevice.Viewport.Width / 2, margin);

            base.Update(gameTime);

            string GetLitteralState()
            {
                switch (Nocubeless.CurrentState)
                {
                case NocubelessState.Playing:
                    return("Playing");

                case NocubelessState.Editing:
                    return("Editing world");

                case NocubelessState.ColorPicking:
                    return("Picking a color...");

                default:
                    return("Unknown");
                }
            }
        }
Beispiel #7
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            _fpsCounter.Update(gameTime);

            var keyboardState = Keyboard.GetState();

            // Manage camera input controller
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Left, keyboardState.IsKeyDown(Keys.A));
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Right, keyboardState.IsKeyDown(Keys.D));
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Forward, keyboardState.IsKeyDown(Keys.W));
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Backward, keyboardState.IsKeyDown(Keys.S));
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Up, keyboardState.IsKeyDown(Keys.Up));
            _controller.SetControlKeyState(CameraInputController.ControlKeys.Down, keyboardState.IsKeyDown(Keys.Down));

            var mouseState = Mouse.GetState();

            _controller.SetTouchState(CameraInputController.TouchType.Move, mouseState.LeftButton == ButtonState.Pressed);
            _controller.SetTouchState(CameraInputController.TouchType.Rotate, mouseState.RightButton == ButtonState.Pressed);

            _controller.SetMousePosition(new Point(mouseState.X, mouseState.Y));

            _controller.Update();
        }
Beispiel #8
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)
        {
            ScreenManager.Instance.Update(gameTime);
            InputManager.Instance.Update(gameTime);
            fpsCounter.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #9
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }


            fps.Update(gameTime);
            base.Update(gameTime);
        }
Beispiel #10
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)
        {
            base.Update(gameTime);
            MusicPlayer.Update(gameTime);
            fps.Update(gameTime);

            UserInterface.Active.Update(gameTime);

            MusicPlayer.MasterVolume = GameSettings.MasterVolume / 100f;
            MusicPlayer.MusicVolume  = (GameSettings.MusicVolume / 100f) * (MusicPlayer.MasterVolume);
            MusicPlayer.SFXVolume    = (GameSettings.EffectsVolume / 100f) * (MusicPlayer.MasterVolume);
        }
Beispiel #11
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)
        {
            _fpsCounter.Update(gameTime);
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F1))
            {
                if (_currentState != GameStates.WIN && _currentState != GameStates.LOSE)
                {
                    var isSolved = IsValidSolution();

                    _score = (10000 + (isSolved ? 500 : 0)) -
                             ((_multiplier / 10) * ((int)_gameTimer.ElapsedMilliseconds / 10000));

                    if (isSolved)
                    {
                        _currentState = GameStates.WIN;
                    }
                    else
                    {
                        _currentState = GameStates.LOSE;
                    }
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F5))
            {
                if (_currentState == GameStates.WIN || _currentState == GameStates.LOSE)
                {
                    CreateNewGame();
                    _currentState = GameStates.PLAYING;
                }
            }

            if (_currentState == GameStates.PLAYING)
            {
                _lastMultiplierReductionTime = (long)_gameTimer.ElapsedMilliseconds;
                _score = 10000 -
                         ((_multiplier / 10) * ((int)_gameTimer.ElapsedMilliseconds / 10000));
                if (_lastMultiplierReductionTime > _rateOfReduction)
                {
                    //reduce multipler every interval
                    _lastMultiplierReductionTime = _gameTimer.ElapsedMilliseconds;
                    _multiplier += 1;
                }
            }

            base.Update(gameTime);
        }
Beispiel #12
0
        protected override void Update(GameTime gameTime)
        {
            var keyboard     = Keyboard.GetState();
            var gamePadState = GamePad.GetState(PlayerIndex.One);

            if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            _fpsCounter.Update(gameTime);
            _ecs.Update(gameTime);
        }
Beispiel #13
0
        public void Update(GameTime gameTime)
        {
            _updateFrames++;
            _updateStopwatch.Start();

            _fps.Update(gameTime);
            _starField.Update(gameTime);

            (IGameState currentGameState, IGameState newGameState)returnGameState = _gameState.Update(gameTime);
            ChangeGameState(returnGameState.currentGameState, returnGameState.newGameState);

            _updateStopwatch.Stop();
            //BenchmarkMetrics.Instance.Metrics["SpaceShooterGame.Update"] = new Metric(_updateStopwatch.Elapsed.TotalMilliseconds, _updateFrames);
        }
Beispiel #14
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            _frameCounter.Update(gameTime);

            graphics.GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(transformMatrix: camera.GetViewMatrix());

            GSM.Draw(spriteBatch, gameTime);

            spriteBatch.DrawString(Assets.font, string.Format("FPS: {0} X: {1} Y: {2}", _frameCounter.CurrentFramesPerSecond, camera.Position.X / 32, camera.Position.Y / 32),
                                   new Vector2(camera.Position.X, camera.Position.Y), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
Beispiel #15
0
        protected override void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape) && _previousKeyboardState.IsKeyUp(Keys.Escape))
            {
                Back();
            }

            _fpsCounter.Update(gameTime);
            _guiSystem.Update(gameTime);
            _currentDemo?.OnUpdate(gameTime);

            _previousKeyboardState = keyboardState;
            base.Update(gameTime);
        }
Beispiel #16
0
        public void Update(GameTime gameTime)
        {
            _updateFrames++;
            _updateStopwatch.Start();

            _fps.Update(gameTime);
            _scrollingBackground.Update(gameTime);

            (bool changeGameState, IGameState newGameState)returnGameState = _gameState.Update(gameTime);
            if (returnGameState.changeGameState)
            {
                ChangeGameState(returnGameState.newGameState);
            }

            _updateStopwatch.Stop();
            BenchmarkMetrics.Instance.Metrics["SpaceShooterGame.Update"] = new Metric(_updateStopwatch.Elapsed.TotalMilliseconds, _updateFrames);
        }
Beispiel #17
0
        public override void Update(GameTime gameTime)
        {
            var elapsedSecs   = gameTime.GetElapsedSeconds();
            var keyboardState = KeyboardExtended.GetState();

            if (keyboardState.WasKeyJustDown(Keys.Q))
            {
                ScreenManager.LoadScreen(
                    new TitleScreen(Game),
                    new ExpandTransition(GraphicsDevice, Color.Black)
                    );
            }

            if (keyboardState.WasKeyJustDown(Keys.D))
            {
                if (debug)
                {
                    debug = false;
                }
                else if (!debug)
                {
                    debug = true;
                }
            }

            ball.MoveBall(elapsedSecs, ScreenWidth, ScreenHeight);
            ball.CollisionCheck(aiPaddle);
            ball.CollisionCheck(playerPaddle);

            playerPaddle.MovePaddlePlayer(keyboardState, ScreenHeight);
            aiPaddle.MovePaddleAi(ball, elapsedSecs, 0.85f);

            if (ball.scored == "player")
            {
                playerScore++;
            }
            else if (ball.scored == "ai")
            {
                aiScore++;
            }
            ball.scored = "";

            fpsCounter.Update(gameTime);
            tweener.Update(elapsedSecs);
        }
        protected override void Draw(GameTime gameTime)
        {
            _fpsCounter.Update(gameTime);

            GraphicsDevice.Clear(Color.Black);

            _tiledMap.Draw(_camera);

            _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix());
            _zombie.Draw(_spriteBatch);
            _spriteBatch.End();

            _spriteBatch.Begin();
            _spriteBatch.DrawString(_bitmapFont, string.Format("FPS: {0} Zoom: {1}", _fpsCounter.AverageFramesPerSecond, _camera.Zoom), new Vector2(5, 5), new Color(0.5f, 0.5f, 0.5f));
            _spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #19
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)
        {
            if (Globals.exitgame)
            {
                Exit();
            }
            UserInterface.Active.Update(gameTime);
            _fpsCounter.Update(gameTime);
            if (!Globals.cursorOverride)
            {
                UserInterface.Active.SetCursor(CursorType.Default);
            }

            if (GameLogic.PlayerIndex > -1)
            {
                if (Globals.graphicsChange)
                {
                    SetFullScreen();
                }
                particleEngine.EmitterLocation = new Vector2(Types.Player[GameLogic.PlayerIndex].X, Types.Player[GameLogic.PlayerIndex].Y);
                particleEngine.Update();
            }
            IGUI.lblStatus.Text = ctcp.isOnline ? "Server status:{{GREEN}} online" : "Server status:{{RED}} offline";
            CheckKeys();
            for (var x = 0; x < Explosion.Count; x++)
            {
                Explosion[x].Update();
            }
            for (var x = 0; x < DamageTexts.Count; x++)
            {
                DamageTexts[x].Update();
            }
            LevelUp.Update();
            if (GameLogic.PlayerIndex != -1)    // Update camera position to follow player
            {
                Camera.Position = new Vector2(Types.Player[GameLogic.PlayerIndex].X, Types.Player[GameLogic.PlayerIndex].Y) - new Vector2(Globals.PreferredBackBufferWidth / 2.0f, Globals.PreferredBackBufferHeight / 2.0f);
            }
            IGUI.Update();

            Globals.strobe = (gameTime.TotalGameTime.Seconds % 2 == 0);
            base.Update(gameTime);
        }
Beispiel #20
0
        protected override void Update(GameTime gameTime)
        {
            var deltaSeconds  = (float)gameTime.ElapsedGameTime.TotalSeconds;
            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            _mapRenderer.Update(_map, gameTime);

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            const float cameraSpeed = 500f;
            const float zoomSpeed   = 0.3f;

            var moveDirection = Vector2.Zero;

            if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up))
            {
                moveDirection -= Vector2.UnitY;
            }

            if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
            {
                moveDirection -= Vector2.UnitX;
            }

            if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down))
            {
                moveDirection += Vector2.UnitY;
            }

            if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
            {
                moveDirection += Vector2.UnitX;
            }

            // need to normalize the direction vector incase moving diagonally, but can't normalize the zero vector
            // however, the zero vector means we didn't want to move this frame anyways so all good
            var isCameraMoving = moveDirection != Vector2.Zero;

            if (isCameraMoving)
            {
                moveDirection.Normalize();
                _camera.Move(moveDirection * cameraSpeed * deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.R))
            {
                _camera.ZoomIn(zoomSpeed * deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.F))
            {
                _camera.ZoomOut(zoomSpeed * deltaSeconds);
            }

            if (_previousKeyboardState.IsKeyDown(Keys.Tab) && keyboardState.IsKeyUp(Keys.Tab))
            {
                _map = LoadNextMap();
                LookAtMapCenter();
            }

            if (_previousKeyboardState.IsKeyDown(Keys.H) && keyboardState.IsKeyUp(Keys.H))
            {
                _showHelp = !_showHelp;
            }

            if (keyboardState.IsKeyDown(Keys.Z))
            {
                _camera.Position = Vector2.Zero;
            }

            if (keyboardState.IsKeyDown(Keys.X))
            {
                _camera.LookAt(Vector2.Zero);
            }

            if (keyboardState.IsKeyDown(Keys.C))
            {
                LookAtMapCenter();
            }

            _previousKeyboardState = keyboardState;

            _fpsCounter.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #21
0
 public void Update(GameTime gameTime)
 {
     _fps.Update(gameTime);
 }
Beispiel #22
0
 public override void Update(GameTime game_time)
 {
     fps_counter.Update(game_time);
 }
Beispiel #23
0
 public void UpdateFpsCounter(GameTime gameTime)
 {
     _fpsCounter.Update(gameTime);
 }
Beispiel #24
0
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            var deltaSeconds  = (float)gameTime.ElapsedGameTime.TotalSeconds;
            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            _mapRenderer.Update(_map, gameTime);

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                Game.Exit();
            }



            if (_player.Update(deltaSeconds, keyboardState))
            {
                if (keyboardState != _previousKeyboardState)
                {
                    _hubProxy.Invoke("MovePlayer", _player.Direction);
                }
            }
            else
            {
                if (keyboardState != _previousKeyboardState)
                {
                    _hubProxy.Invoke("StopMovePlayer");
                }
            }

            if (_player.UpdateCameraposition)
            {
                _player.UpdateCameraposition = false;
                SetCameraPosition(_player.Position);
            }

            foreach (var p in _players)
            {
                p.Update(deltaSeconds, keyboardState);
            }


            const float zoomSpeed = 0.3f;

            if (keyboardState.IsKeyDown(Keys.R))
            {
                _camera.ZoomIn(zoomSpeed * deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.F))
            {
                _camera.ZoomOut(zoomSpeed * deltaSeconds);
            }

            //if (_previousKeyboardState.IsKeyDown(Keys.Tab) && keyboardState.IsKeyUp(Keys.Tab))
            //{
            //    //_map = LoadNextMap();
            //    LookAtMapCenter();
            //}

            //if (_previousKeyboardState.IsKeyDown(Keys.H) && keyboardState.IsKeyUp(Keys.H))
            //    _showHelp = !_showHelp;

            //if (keyboardState.IsKeyDown(Keys.Z))
            //    _camera.Position = Vector2.Zero;

            //if (keyboardState.IsKeyDown(Keys.X))
            //    _camera.LookAt(Vector2.Zero);

            //if (keyboardState.IsKeyDown(Keys.C))
            //    LookAtMapCenter();

            _previousKeyboardState = keyboardState;

            _fpsCounter.Update(gameTime);


            base.Update(gameTime);
        }
Beispiel #25
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            _fpsCounter.Update(gameTime);
        }