Пример #1
0
        public void HandleInput(Vector2 a_offset, SquareGrid a_grid)
        {
            bool pressedSpace = Globals.MyKeyboard.GetPress("Space");

            if (OnGround && HSpeed == 0 && _state != State.ATTACKING && _state != State.JUMP_ATTACKING && _state != State.DYING)
            {
                _state = State.STANDING;
            }

            if (_state != State.ATTACKING && _state != State.JUMP_ATTACKING && _state != State.DYING)
            {
                // Runing stuff
                if (Globals.MyKeyboard.GetPress("A") || Globals.MyKeyboard.GetPress("Left"))
                {
                    HSpeed -= MovSpeed;
                }
                if (Globals.MyKeyboard.GetPress("D") || Globals.MyKeyboard.GetPress("Right"))
                {
                    HSpeed += MovSpeed;
                }

                // Jumping stuff
                if (Globals.MyKeyboard.GetNewPress("Space"))
                {
                    _jumpTimer = TimeSpan.FromMilliseconds(0);
                }
                if (!pressedSpace && _wasOnGround && !OnGround)
                {
                    _extraGroundTimer = TimeSpan.FromMilliseconds(0);
                }

                _jumpTimer        += Globals.GlobalGameTime.ElapsedGameTime;
                _extraGroundTimer += Globals.GlobalGameTime.ElapsedGameTime;

                if (_jumpTimer.TotalMilliseconds < 150 && (_extraGroundTimer.TotalMilliseconds < 75 || OnGround))
                {
                    VSpeed     = -JumpSpeed;
                    _jumpTimer = TimeSpan.FromMilliseconds(151);
                    _state     = State.JUMPING;
                }
                if (!pressedSpace && VSpeed < 0 && !OnGround)
                {
                    VSpeed *= 0.8f;
                }

                if (Globals.MyMouse.LeftClick())
                {
                    if (OnGround && Stamina >= 1)
                    {
                        _state = State.ATTACKING;
                    }
                }

                if (!OnGround && Stamina >= 1 && (Globals.MyKeyboard.GetPress("S") || Globals.MyKeyboard.GetPress("Down")))
                {
                    if (VSpeed < 0)
                    {
                        VSpeed = -0.1f;
                    }
                    Stamina--;
                    _state = State.JUMP_ATTACKING;
                }

                if (Stamina >= 3 && !Swapping && (Globals.MyKeyboard.GetPress("R")))
                {
                    SwapPositionWithClosestEnemy();
                }
            }
            else if (_state == State.JUMP_ATTACKING)
            {
                if (Globals.MyKeyboard.GetPress("A") || Globals.MyKeyboard.GetPress("Left"))
                {
                    HSpeed -= MovSpeed;
                }
                if (Globals.MyKeyboard.GetPress("D") || Globals.MyKeyboard.GetPress("Right"))
                {
                    HSpeed += MovSpeed;
                }
                if (Globals.MyMouse.LeftClick())
                {
                    _state = State.JUMPING;
                }
            }

            if (Globals.MyMouse.RightClick())
            {
                Vector2 tmpLocation = a_grid.GetLocationFromPixel(Globals.NewVector(Globals.MyMouse.NewMousePos) - a_offset, Vector2.Zero);

                GridLocation location = a_grid.GetSlotFromLocation(tmpLocation);

                if (location != null && !location.Filled && !location.Impassible)
                {
                    //location.SetToFilled(true);
                    FirstEnemy tmpEnemy = new FirstEnemy(Vector2.Zero, new Vector2(1, 1));

                    tmpEnemy.Position = location.Position + tmpEnemy.Dimension / 2;

                    GameGlobals.PassNpc(tmpEnemy);
                }
            }

            if (Globals.MyKeyboard.GetPress("LeftShift") && _state != State.DASHING && Stamina >= 3)
            {
                _state          = State.DASHING;
                IgnoringPhysics = true;
                VSpeed          = 0;
                Stamina        -= 3;
            }

            if (_state == State.STANDING && HSpeed != 0)
            {
                _state = State.RUNNING;
            }
        }