/// <summary>
        /// Handle the input of the user relative to the <c>MainGameScreen</c> screen.
        /// </summary>
        /// <param name="input">Current state of the player input.</param>
        /// <param name="gameTime">Current time of the game.</param>
        public override void HandleInput(GameComponents.Input input, GameTime gameTime)
        {
            if (input.Up)
            {
                if (_player.PlayerYDirection != Player.YDirection.Up)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionYChanged(ref _player, Player.YDirection.Up));
                }
            }

            if (input.Down)
            {
                if (_player.PlayerYDirection != Player.YDirection.Down)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionYChanged(ref _player, Player.YDirection.Down));
                }
            }

            if (!input.Up && !input.Down)
            {
                if (_player.PlayerYDirection != Player.YDirection.None)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionYChanged(ref _player, Player.YDirection.None));
                }
            }

            if (input.Left)
            {
                if (_player.PlayerXDirection != Player.XDirection.Left)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionXChanged(ref _player, Player.XDirection.Left));
                }

                if (_player.PlayerState == Player.State.Waiting)
                {
                    EventManager.QueueEvent(new EventData_UnitStateChanged(_player, Player.State.Running));
                }
            }

            if (input.Right)
            {
                if (_player.PlayerXDirection != Player.XDirection.Right)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionXChanged(ref _player, Player.XDirection.Right));
                }

                if (_player.PlayerState == Player.State.Waiting)
                {
                    EventManager.QueueEvent(new EventData_UnitStateChanged(_player, Player.State.Running));
                }
            }

            if (!input.Left && !input.Right)
            {
                if (_player.PlayerXDirection != Player.XDirection.None)
                {
                    EventManager.QueueEvent(new EventData_UnitDirectionXChanged(ref _player, Player.XDirection.None));
                }

                if (_player.PlayerState == Player.State.Running)// || _player.PlayerState == GameUnit.State.Jumping)
                {
                    EventManager.QueueEvent(new EventData_UnitStateChanged(_player, Player.State.Waiting));
                }
            }

            if (input.Attack)
            {
                _amount += (float)(gameTime.ElapsedGameTime.Milliseconds / 1000f);
                if (_player.PlayerGun != null && _amount > _player.ShotSpeed)
                {
                    Vector3 origin = Vector3.Zero;
                    Vector3 up     = Vector3.Zero;
                    Vector3 speed  = Vector3.Zero;

                    if (_player.PlayerState == Player.State.Jumping)
                    {
                        if (_player.PlayerXDirection == Character.XDirection.Left ||
                            (_player.PlayerXDirection == Character.XDirection.None &&
                             _player.LastPlayerXDirection == Character.XDirection.Left))
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X - _player.DModel.BSphere.Radius / 1f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 2.5f,
                                _player.DModel.BSphere.Center.Z);
                            up    = -Vector3.Up;
                            speed = new Vector3(-10f, 0, 0);
                        }
                        else if (_player.PlayerXDirection == Character.XDirection.Right ||
                                 (_player.PlayerXDirection == Character.XDirection.None &&
                                  _player.LastPlayerXDirection == Character.XDirection.Right))
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X + _player.DModel.BSphere.Radius / 1.2f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 4.5f,
                                _player.DModel.BSphere.Center.Z);
                            up    = Vector3.Up;
                            speed = new Vector3(10f, 0, 0);
                        }
                    }
                    else if (_player.PlayerXDirection == Character.XDirection.None &&
                             _player.PlayerYDirection == Character.YDirection.Up)
                    {
                        origin = new Vector3(
                            _player.DModel.BSphere.Center.X,
                            _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius * 1.5f,
                            _player.DModel.BSphere.Center.Z);
                        up    = new Vector3(-1f, 0, 0);
                        speed = new Vector3(0, 10f, 0);
                    }
                    else if (_player.PlayerXDirection == Character.XDirection.Left ||
                             (_player.PlayerXDirection == Character.XDirection.None && _player.LastPlayerXDirection == Character.XDirection.Left))
                    {
                        if (_player.PlayerYDirection == Character.YDirection.Up)
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X - _player.DModel.BSphere.Radius / 1.3f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 0.85f,
                                _player.DModel.BSphere.Center.Z);
                            up    = new Vector3(-0.75f, -0.75f, 0);
                            speed = new Vector3(-10f, 10f, 0);
                        }
                        else
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X - _player.DModel.BSphere.Radius / 0.9f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 4.5f,
                                _player.DModel.BSphere.Center.Z);
                            up    = Vector3.Up;
                            speed = new Vector3(-10f, 0, 0);
                        }
                    }
                    else if (_player.PlayerXDirection == Character.XDirection.Right ||
                             (_player.PlayerXDirection == Character.XDirection.None && _player.LastPlayerXDirection == Character.XDirection.Right))
                    {
                        if (_player.PlayerYDirection == Character.YDirection.Up)
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X + _player.DModel.BSphere.Radius / 1.3f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 0.9f,
                                _player.DModel.BSphere.Center.Z);
                            up    = new Vector3(-0.75f, 0.75f, 0);
                            speed = new Vector3(10f, 10f, 0);
                        }
                        else
                        {
                            origin = new Vector3(
                                _player.DModel.BSphere.Center.X + _player.DModel.BSphere.Radius / 1.2f,
                                _player.DModel.BSphere.Center.Y + _player.DModel.BSphere.Radius / 4.5f,
                                _player.DModel.BSphere.Center.Z);
                            up    = Vector3.Up;
                            speed = new Vector3(10f, 0, 0);
                        }
                    }

                    if (_player.PlayerState != Player.State.Climbing)
                    {
                        if (_player.PlayerGun.CurrentAmmo != 0)
                        {
                            if (_player.PlayerGun.GunType == Gun.ShotType.Laser)
                            {
                                SoundManager.GetSound("LaserShot").Volume = GameSettings.DefaultInstance.SoundVolume;
                                SoundManager.GetSound("LaserShot").Play(true, false);
                            }
                            else
                            {
                                SoundManager.GetSound("MetalShot").Volume = GameSettings.DefaultInstance.SoundVolume;
                                SoundManager.GetSound("MetalShot").Play(true, false);
                            }

                            _shotManager.AddShot(new Shot(_player.PlayerGun.GunType, origin, up, speed));

                            _player.PlayerGun.CurrentAmmo -= 1;
                        }
                        else
                        {
                            foreach (Objects.Object playerObject in _player.Objects)
                            {
                                if (playerObject is Objects.Ammo &&
                                    ((Objects.Ammo)playerObject).Type == _player.PlayerGun.GunType)
                                {
                                    EventManager.Trigger(new EventData_ReloadGun(_player, playerObject));
                                    ((AnimatedModel)_player.DModel).Animation.StartClip("Reload", false);
                                }
                            }
                        }
                    }

                    _amount = 0.0f;
                }
            }

            if (input.Jump)
            {
                EventManager.QueueEvent(new EventData_UnitStateChanged(_player, Player.State.Jumping));
            }

            if (input.Select)
            {
                Input.Continuous = false;
                ScreenManager.AddScreen("AGameMenu", new GameMenuScreen(this, "AGameMenu", 25f));
            }

            if (input.Start)
            {
                ((ChaseCamera)CameraManager.ActiveCamera).Position = new Vector3(10f, 7.5f, 18f);
                ((ChaseCamera)CameraManager.ActiveCamera).Target   = new Vector3(10f, 7.5f, 5f);

                _player.Position = new Vector3(10, 6.5f, 5f);
            }

            if (input.Inventory)
            {
                SoundManager.GetSound("Running").Pause();
                ScreenManager.AddScreen("Inventory", new InventoryScreen(
                                            this, "Inventory", "InventoryBackground", _player));
            }

            /*((FreeCamera)CameraManager.ActiveCamera).Rotate(input.MouseMoved.X * 0.01f, input.MouseMoved.Y * 0.01f);
             *
             * Vector3 moveVector = Vector3.Zero;
             * if (input.Up)    moveVector += Vector3.Forward;
             * if (input.Down)  moveVector += Vector3.Backward;
             * if (input.Right) moveVector += Vector3.Left;
             * if (input.Left)  moveVector += Vector3.Right;
             * moveVector *= ((float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f) * 30.0f;
             *
             * ((FreeCamera)CameraManager.ActiveCamera).Move(moveVector);*/
        }
Beispiel #2
0
 private void PlayerShotFired(object sender, ShotFiredEventArgs e)
 {
     _shotManager.AddShot(e);
 }