Ejemplo n.º 1
0
        /// <summary>
        /// Updates the player's logic - reads input and do actions. It suppresses the human's automatic behaviour.
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();
            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (Math.Abs(Health) + 1 > 0 && System.Windows.Forms.Form.ActiveForm == (System.Windows.Forms.Control.FromHandle(Game.Window.Handle) as System.Windows.Forms.Form))
            {
                Vector2 actualLastPosition = this.Position.PositionInQuarter;
                if (keyboardState.IsKeyDown(Keys.LeftControl) && keyboardState.IsKeyDown(GodModeSwitch) && gameTime.TotalGameTime - lastKeyPressedGameTime[GodModeSwitch] > KeyPressedTimeout)
                {
                    InGodMode = !InGodMode;
                    lastKeyPressedGameTime[GodModeSwitch] = gameTime.TotalGameTime;
                }

                if (keyboardState.IsKeyDown(Game.Settings.StepLeft))
                {
                    Step(true, seconds);
                }
                if (keyboardState.IsKeyDown(Game.Settings.StepRight))
                {
                    Step(false, seconds);
                }
                if (keyboardState.IsKeyDown(Game.Settings.Forward))
                {
                    Go(seconds);
                }
                if (keyboardState.IsKeyDown(Game.Settings.Backward))
                {
                    GoBack(seconds);
                }

                if (keyboardState.IsKeyDown(Game.Settings.TurnLeft))
                    Rotate(true, seconds);
                if (keyboardState.IsKeyDown(Game.Settings.TurnRight))
                    Rotate(false, seconds);
                if (keyboardState.IsKeyDown(Game.Settings.TurnUp))
                    LookAngle += Human.RotateAngle * seconds;
                if (keyboardState.IsKeyDown(Game.Settings.TurnDown))
                    LookAngle -= Human.RotateAngle * seconds;
                if (keyboardState.IsKeyDown(Game.Settings.RunWalkSwitch) && gameTime.TotalGameTime - lastKeyPressedGameTime[Game.Settings.RunWalkSwitch] > KeyPressedTimeout)
                {
                    Running = !Running;
                    lastKeyPressedGameTime[Game.Settings.RunWalkSwitch] = gameTime.TotalGameTime;
                }
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    DoToolAction(gameTime);
                }
                if (mouseState.RightButton == ButtonState.Pressed && HasAvailableAnyAction)
                {
                    if (usedActionObject != FirstActionObject && usedActionObject != null)
                    {
                        usedActionObject.EndAction(this, gameTime);
                    }
                    usedActionObject = FirstActionObject;
                    usedActionObject.StartAction(this, gameTime);
                }
                else
                {
                    if (usedActionObject != null)
                    {
                        usedActionObject.EndAction(this, gameTime);
                    }
                }

                SelectNextGun((mouseState.ScrollWheelValue - lastMouseWheelState) / 120);
                lastMouseWheelState = mouseState.ScrollWheelValue;

                int windowWidth = Game.Settings.ScreenSize.Width;
                int windowHeight = Game.Settings.ScreenSize.Height;
                if (Game.Settings.MouseIgnoresWindow || (mouseState.X >= 0 && mouseState.X < windowWidth && mouseState.Y >= 0 && mouseState.Y < windowHeight))
                {
                    const float maxLookAngle = 0.52f;
                    azimuth += ( (mouseState.X - defaultMousePosition.X) / (float)windowWidth) * Game.Settings.MouseXSensitivity * MouseXSensitivityCoef * seconds * Human.RotateAngle * (Game.Settings.MouseXInvert ? -1 : 1);
                    LookAngle += ((mouseState.Y - defaultMousePosition.Y) / (float)windowWidth) * Game.Settings.MouseYSensitivity * MouseYSensitivityCoef * seconds * Human.RotateAngle * (Game.Settings.MouseYInvert ? 1 : -1);
                    if (LookAngle > maxLookAngle)
                        LookAngle = maxLookAngle;
                    if (LookAngle < -maxLookAngle)
                        LookAngle = -maxLookAngle;
                    //lastMousePosition = new Point(mouseState.X, mouseState.Y);
                }
                Mouse.SetPosition(defaultMousePosition.X, defaultMousePosition.Y);
                LastPosition = actualLastPosition;
            }

            CheckHits(false, gameTime);

            //Supress human instincts
            //base.Update(gameTime);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new action object task.
 /// </summary>
 /// <param name="actionObject">The specified action object</param>
 /// <param name="holder">The holder of this task</param>
 public ActionObjectTask(ActionObject actionObject, Human holder)
     : base(holder)
 {
     this.actionObject = actionObject;
 }