Пример #1
0
        protected override void Update(GameTime gameTime)
        {
            var deltaTime     = gameTime.GetElapsedSeconds();
            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

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

            if (_player != null && !_player.IsDestroyed)
            {
                const float acceleration = 5f;

                if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up))
                {
                    _player.Accelerate(acceleration);
                }

                if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down))
                {
                    _player.Accelerate(-acceleration);
                }

                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                {
                    _player.Rotation -= deltaTime * 3f;
                }

                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                {
                    _player.Rotation += deltaTime * 3f;
                }

                if (keyboardState.IsKeyDown(Keys.Space) || mouseState.LeftButton == ButtonState.Pressed)
                {
                    _player.Fire();
                }

                if (_previousMouseState.X != mouseState.X || _previousMouseState.Y != mouseState.Y)
                {
                    _player.LookAt(_camera.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)));
                }

                _camera.LookAt(_player.Position + _player.Velocity * 0.2f);
                _camera.Zoom = 1.0f - _player.Velocity.Length() / 500f;
            }

            _entityManager.Update(gameTime);

            CheckCollisions();

            _previousMouseState = mouseState;

            base.Update(gameTime);
        }
Пример #2
0
        public override void _Process(float delta)
        {
            const float accelFactor = 0.25f;
            const float turnFactor  = 0.05f;

            if (controls.JoystickOutput.y < -0.5f || Input.IsActionPressed("ui_up"))
            {
                spaceship.Accelerate(accelFactor);
            }

            if (controls.JoystickOutput.x < -0.5f || Input.IsActionPressed("ui_left"))
            {
                spaceship.Turn(-turnFactor);
            }

            if (controls.JoystickOutput.x > 0.5f || Input.IsActionPressed("ui_right"))
            {
                spaceship.Turn(turnFactor);
            }
        }