Ejemplo n.º 1
0
    private Vector2 GetGroundMovement(PlayerInputState inputs)
    {
        float x = inputs.x;
        float y = inputs.y;

        return(new Vector2(x * World.instance.GroundMovementSpeed, y * World.instance.AirMovementSpeed));
    }
Ejemplo n.º 2
0
 public void Construct(Selection selection, Image pointer, PlayerInputState iS, MenuItemFactory menuItemFactory)
 {
     _pointer           = pointer;
     _selection         = selection;
     _inputState        = iS;
     _actionMenuFactory = menuItemFactory;
 }
Ejemplo n.º 3
0
    public void OnPlayer2Move(InputAction.CallbackContext context)
    {
        Entity           player           = player2Entity;
        PlayerInputState playerInputState = EntityManager.GetComponentData <PlayerInputState>(player);

        playerInputState.Move = context.ReadValue <Vector2>();
        EntityManager.SetComponentData(player, playerInputState);
    }
Ejemplo n.º 4
0
 private void CheckChanges(PlayerInputState type)
 {
     if (_clickState != type)
     {
         _clickState = type;
         OnChangeClickState?.Invoke(_clickState);
     }
 }
    public PlayerInputHandler(IActionMenu aM, PlayerInputState inputState, GameState g)
    {
        _actionMenu = aM;
        _gameState  = g;
        _inputState = inputState;

        _inputState.IsEscapeAction = _gameState.NextPlayer;
    }
Ejemplo n.º 6
0
 ActionMenuState(IActionMenu aM, BaseUnit unit, PlayerInputState iS)
 {
     _actionMenu = aM;
     _unit       = unit;
     _inputState = iS;
     _inputState.IsCancelAction    = Cancel;
     _inputState.IsConfirmedAction = Confirm;
 }
Ejemplo n.º 7
0
    public void OnPlayer2Shoot(InputAction.CallbackContext context)
    {
        Entity           player           = player2Entity;
        PlayerInputState playerInputState = EntityManager.GetComponentData <PlayerInputState>(player);

        playerInputState.Firing = context.ReadValue <float>();
        EntityManager.SetComponentData(player, playerInputState);
    }
Ejemplo n.º 8
0
    FireState(CanFire cf, Selection selection, PlayerInputState iS, MapEntetiesManager entetiesManager)
    {
        _selection       = selection;
        _fireComponent   = cf;
        _entetiesManager = entetiesManager;

        iS.IsCancelAction    = Cancel;
        iS.IsConfirmedAction = Confirm;
    }
Ejemplo n.º 9
0
    protected override void DoAwake()
    {
        titleScreenState = this.stateMachine.GetState <PlayerInputTitleScreenState>();
        defaultState     = this.stateMachine.GetState <PlayerInputDefaultState>();
        pauseMenuState   = this.stateMachine.GetState <PlayerInputPauseMenuState>();

        player = player ?? ReInput.players.GetPlayer(playerId);

        gameStateMachine = gameStateMachine ?? FindObjectOfType <GameStateTitleScreen>().GetComponent <StateMachine>();
    }
Ejemplo n.º 10
0
    bool ReadFire(ref PlayerInputState result)
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            result.buttonPressedFire = true;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 11
0
    bool ReadJump(ref PlayerInputState result)
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            result.buttonPressedJump = true;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 12
0
    bool ReadPlayerInputStateInto(ref PlayerInputState result)
    {
        bool didReadAny = false;

        didReadAny |= ReadJump(ref result);
        didReadAny |= ReadFire(ref result);
        didReadAny |= ReadMoveAxes(ref result);
        didReadAny |= ReadMouseMoveAxes(ref result);

        return(didReadAny);
    }
        private void HandleControllerProcessing()
        {
            PlayerInputState inputState  = new PlayerInputState();
            Vector2          _moveVector = moveAction.ReadValue <Vector2>();

            inputState.MoveAxisRight   = _moveVector.x;
            inputState.MoveAxisForward = _moveVector.y;
            inputState.CameraRotation  = cameraController.GetCameraRotation();

            kinController.SetPlayerInput(ref inputState);
        }
Ejemplo n.º 14
0
    bool ReadMoveAxes(ref PlayerInputState result)
    {
        var moveAxes = InputHelper.GetMoveAxes();

        if (moveAxes != Vector2.zero)
        {
            result.moveAxes = moveAxes;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 15
0
    public void HandleRecall(PlayerInputState input, bool recalling)
    {
        if (!recalling)
        {
            return;
        }

        Receiver foreignReceiver = null;

        if (CanRecall(TransmissionType.Jump, input.JumpDown))
        {
            foreignReceiver = foreignReceivers[TransmissionType.Jump];
        }
        if (CanRecall(TransmissionType.Move, input.TransmitMove))
        {
            foreignReceiver = foreignReceivers[TransmissionType.Move];
        }

        if (foreignReceiver)
        {
            if (foreignReceiver.ActionBank.Count() > 0)
            {
                //Pull the transmission from the foreign receiver
                TransmissionType type = foreignReceiver.ActionBank.GetFirst();
                if (MyReceiver.CanReceive(type) && MyReceiver.ReceiveTransmission(type))
                {
                    foreignReceiver.ActionBank.RemoveAction(type);
                    foreignReceivers.Remove(type);

                    Animator anim = foreignReceiver.GetComponentInParent <Animator>();
                    if (anim)
                    {
                        anim.speed /= 3f;
                    }

                    //Grant the appropriate action controller of the receive to the sender.
                    if (type == TransmissionType.Jump)
                    {
                        GameController.S.jumpText.color = Color.green;
                        InputManager.JumpingController  = InputManager.PlayerMovementController;
                    }

                    if (type == TransmissionType.Move)
                    {
                        GameController.S.moveText.color = Color.green;
                        InputManager.MovingController.StopMovement();
                        InputManager.MovingController = InputManager.PlayerMovementController;
                    }
                }
            }
        }
    }
Ejemplo n.º 16
0
    public PlayerState(PlayerState playerState, PlayerInputState inputs)
    {
        stateData            = new PlayerStateData();
        stateData.Collisions = playerState.stateData.Collisions;
        stateData.FrameState = playerState.stateData.FrameState;
        stateData.velocity   = playerState.stateData.velocity;

        _currentDirection = playerState.GetDirection();
        HP = playerState.HP;
        nextActionDelay = playerState.nextActionDelay;

        inputState = inputs;
    }
Ejemplo n.º 17
0
    void Constructor(TileEntity.Factory factory, GameState gS, MapEntetiesManager me, PlayerInputState ps, MapManager mp, PathDrower pathDrower)
    {
        _facTest = factory;

        _gameState        = gS;
        _entetieManager   = me;
        _playerInputState = ps;
        _pathDrower       = pathDrower;
        _currentMap       = mp;


        ReAddActions();
    }
Ejemplo n.º 18
0
    void ApplyInput(PlayerInputState input)
    {
        transform.Rotate(Vector3.up, input.lookHorizontalValue * horizontalRotateSpeed * Time.fixedDeltaTime, Space.Self);

        cameraPosition.transform.Rotate(Vector3.right, input.lookVerticalValue * -verticalRotateSpeed * Time.fixedDeltaTime, Space.Self);

        float frictionFactor;

        if (_controller.isGrounded)
        {
            if (input.jumpPressed)
            {
                _currentVelocity.y = 3.0f;
            }
        }
        else
        {
        }

        _currentVelocity.y -= 5.0f * Time.fixedDeltaTime;

        _currentVelocity.x = 0;
        _currentVelocity.z = 0;
        _currentVelocity  += transform.forward * input.verticalValue + transform.right * input.horizontalValue;

        float horizontalMagnitude = Mathf.Sqrt(_currentVelocity.x * _currentVelocity.x) + (_currentVelocity.z * _currentVelocity.z);

        if (horizontalMagnitude > speed)
        {
            _currentVelocity.x = _currentVelocity.x / horizontalMagnitude * speed;
            _currentVelocity.z = _currentVelocity.z / horizontalMagnitude * speed;
        }

        var result = _controller.Move(_currentVelocity * Time.fixedDeltaTime * speed);

        if ((result & CollisionFlags.Below) != 0)
        {
            if (_currentVelocity.y < 0)
            {
                _currentVelocity.y = 0.0f;
            }
        }

        //-- shooting
        if (input.shootingPressed)
        {
            Shoot(input);
        }
    }
Ejemplo n.º 19
0
    UnitMoveState(Player p, BaseUnit baseUnit, MapManager mP, MapHighlighter mH, PlayerInputState pS, Selection selection, PathDrower pathDrower)
    {
        _player     = p;
        _pathDrower = pathDrower;


        _baseUnit         = baseUnit;
        _mapHighlighter   = mH;
        _mapManagaer      = mP;
        _playerInputState = pS;
        _selection        = selection;

        _playerInputState.IsCancelAction   += Cancel;
        _playerInputState.IsConfirmedAction = Confirm;
    }
Ejemplo n.º 20
0
    //Only called if we are broadcasting
    public void HandleBroadcast(PlayerInputState input, bool broadcasting)
    {
        if (!broadcasting)
        {
            if (tPointer.activeSelf)
            {
                tPointer.SetActive(false);
            }
            transmittingSound.Stop();
            return;
        }

        if (!transmittingSound.isPlaying) //<<OAKWOOD ADDED>>
        {
            transmittingSound.Play();
        }

        //<<OAKWOOD ADDED>>
        // Handle targeting visual aid
        // Should disappear when player is not actively aiming with stick
        var buffer = 0.2f;

        if (Mathf.Abs(input.Horizontal) >= buffer || Mathf.Abs(input.Vertical) >= buffer)
        {
            tPointer.SetActive(true);
            var targetAngle = (Mathf.Atan2(input.Vertical, input.Horizontal) * Mathf.Rad2Deg) - 90;
            tPointer.transform.rotation = Quaternion.Slerp(tPointer.transform.rotation, Quaternion.Euler(0, 0, targetAngle), 10f * Time.deltaTime);
        }
        else
        {
            tPointer.SetActive(false);
        }


        Vector2 targetVector = new Vector2(input.Horizontal, input.Vertical).normalized *bulletSpeed;

        if (input.JumpDown && CanTransmit(TransmissionType.Jump) && targetVector != new Vector2(0, 0))
        {
            ShootTransmissionBullet(TransmissionType.Jump, targetVector, tPointer.transform.rotation);
        }

        if (input.TransmitMove && CanTransmit(TransmissionType.Move) && targetVector != new Vector2(0, 0))
        {
            ShootTransmissionBullet(TransmissionType.Move, targetVector, tPointer.transform.rotation);
        }
    }
Ejemplo n.º 21
0
    void ReadInputInto(InputEntity inputEntity)
    {
        var inputState = new PlayerInputState();
        var didReadAny = ReadPlayerInputStateInto(ref inputState);

        if (!didReadAny)
        {
            return;
        }

        var inputs = inputEntity.playerInputs.inputs;
        //inputs.Clear(); // TEMP Past input records are never removed (yet), so we clear them here to prevent clutter.

        var currentTick = game.currentTick.value;

        inputs.Add(new PlayerInputRecord(currentTick, inputState));
        inputEntity.ReplacePlayerInputs(inputs);
    }
    public static void Update(PlayerInputConfig playerInputConfig, PlayerInputState playerInputState)
    {
        var wasJumpRequested = playerInputState.platformerState.isJumpRequested;

        playerInputState.platformerState.isJumpRequested = Input.GetKey(playerInputConfig.jumpCode);
        foreach (var pair in playerInputConfig.directions)
        {
            if (Input.GetKeyDown(pair.key))
            {
                playerInputState.directions.AddFirst(pair.direction);
            }
            if (Input.GetKeyUp(pair.key))
            {
                playerInputState.directions.Remove(pair.direction);
            }
        }
        var head         = playerInputState.directions.First;
        var oldDirection = playerInputState.platformerState.walkDirection;

        playerInputState.platformerState.walkDirection = head == null ? PlatformerWalkDirection.None : head.Value;
    }
Ejemplo n.º 23
0
    void Shoot(PlayerInputState input)
    {
        Vector3 origin    = cameraPosition.position;
        Vector3 direction = cameraPosition.forward;

        if (isServer && input.serverFrame != ServerSimulation.frameNumber)
        {
            ServerSimulation.Rewind(input.networkTime - _currentLatency);
        }

        RaycastHit hit;

        if (Physics.Raycast(origin, direction, out hit, 1000))
        {
            var instance = Instantiate(hitPrefab, hit.collider.transform, false);
            instance.transform.position = hit.point;
            instance.transform.forward  = hit.normal;
        }

        Debug.DrawRay(origin, direction * 1000);
        Debug.Break();
    }
Ejemplo n.º 24
0
    public void Init()
    {
        anim = this.GetComponent <FGAnimator>();
        anim.Init();
        anim.Play("Idle");

        _currentAttackAnimation = "";

        _inputState = this.GetComponent <PlayerInputState>();
        _inputState.Init();

        _currentState = new PlayerState(startingDirection);
        _lastState    = new PlayerState(startingDirection);

        entityPhysics = this.GetComponent <WorldState2D>();
        entityPhysics.Init(this.GetComponent <RectTransform>().anchoredPosition);
        hurtbox = new Hurtbox(this.GetComponent <RectTransform>());
        entityPhysics.AddCollider(hurtbox);
        //entityPhysics = new Physics2D(this.GetComponent<RectTransform>().anchoredPosition);
        //collision.SetPhysics(entityPhysics);

        initialized = true;
    }
Ejemplo n.º 25
0
 public MessageHandler RegisterNetwork(MessageHandler send, PlatformerCharacterConfig config, string guid, float trustDistance)
 {
     this.trustDistance   = trustDistance;
     platformerInputState = new PlatformerCharacterInputState();
     platformerInputState.isJumpRequested = false;
     platformerInputState.walkDirection   = PlatformerWalkDirection.None;
     playerInputState        = new PlayerInputState(platformerInputState);
     inputMessage.playerGuid = guid;
     inputMessage.state      = playerInputState.platformerState;
     this.platformerConfig   = config;
     this.networkSend        = send;
     return((opCode, message) => {
         if (opCode == OpCode.PLAYER_POSITION)
         {
             UpdateForServerPosition(((PositionMessage)message).position);
         }
         else if (opCode == OpCode.PLAYER_INPUT)
         {
             UpdateForServerPosition(((PlayerInputMessage)message).position.toVector());
         }
         return 1;
     });
 }
Ejemplo n.º 26
0
    /// <summary>
    /// At update, we check the various commands and send them to the player.
    /// </summary>
    void Update()
    {
        PlayerInputState input = GetInputState();

        //Pass input to relevant controllers

        if (!PlayerMovementController.advancedMovementState.broadcasting)
        {
            MovingController.Move(input.Horizontal, input.Vertical);

            if (!PlayerMovementController.advancedMovementState.recalling)
            {
                JumpingController.Jump(input.JumpDown, input.JumpUp);
            }
        }

        PlayerMovementController.Recall(input.Recall);
        Transmitter.HandleRecall(input, PlayerMovementController.advancedMovementState.recalling);

        PlayerMovementController.Broadcast(input.Broadcast);
        Transmitter.HandleBroadcast(input, PlayerMovementController.advancedMovementState.broadcasting);

        if (Input.GetButtonDown("Help"))
        {
            if (GameController.S.controlsText.enabled)
            {
                GameController.S.controlsText.enabled = false;
                GameController.S.helpText.enabled     = true;
            }
            else
            {
                GameController.S.controlsText.enabled = true;
                GameController.S.helpText.enabled     = false;
            }
        }
    }
Ejemplo n.º 27
0
 public PlayerInputRecord(ulong timestamp, PlayerInputState inputState)
 {
     this.timestamp  = timestamp;
     this.inputState = inputState;
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Prompt Sheep player to select piece to move.
        /// </summary>
        /// <param name="player">The player to be prompted.</param>
        /// <returns>The selected piece to be moved. Returns null if player pressed the escape key.</returns>
        private Piece PromptSheepPlayerToSelectPiece(SheepPlayer player)
        {
            ConsoleKey userInput;
            Direction  directionInput;
            Piece      piece;
            int        currentPieceIndex = 0;

            PlayerInputState = PlayerInputState.LeftAndRight;

            CallToAction = "Select the piece you wish to move.";

            // Only leaves loop on player instruction
            while (true)
            {
                RefreshUI();

                piece = player.Pieces[currentPieceIndex];

                HighlightBoardSquare(piece.BoardSquare);

                userInput = GetPlayerInputKey();

                // If player presses enter...
                if (userInput == ConsoleKey.Enter)
                {
                    // ...check if selected piece has any possible move. If not...
                    if (!Board.GetPieceHasPossibleMoves(player, piece))
                    {
                        // ...warn the player...
                        AddLogMessage($"{CurrentPlayerName} you can't select that piece because it doens't have any possible moves.");

                        // ...refresh the UI and continue
                        RefreshUI();

                        continue;
                    }

                    // ...refresh the UI...
                    RefreshUI();

                    // ...and leave loop.
                    break;
                }
                // If the player presses escape...
                else if (userInput == ConsoleKey.Escape)
                {
                    // ...set return object to null...
                    piece = null;

                    // ...set colors to default...
                    SetConsoleColorToDefault();

                    // ...and break.
                    break;
                }

                directionInput = GetDirection(userInput);

                // Left and right to move through the pieces
                if (directionInput == Direction.Left || directionInput == Direction.Right)
                {
                    switch (directionInput)
                    {
                    case Direction.Left:
                        currentPieceIndex--;
                        break;

                    case Direction.Right:
                        currentPieceIndex++;
                        break;
                    }

                    // If the index would be outside of the array.
                    if (currentPieceIndex < 0)
                    {
                        currentPieceIndex = player.Pieces.Length - 1;
                    }
                    else if (currentPieceIndex >= player.Pieces.Length)
                    {
                        currentPieceIndex = 0;
                    }
                }
            }

            return(piece);
        }
Ejemplo n.º 29
0
 void CreateInputState(ref PlayerInputState state)
 {
     state.inputID     = _inputIdMax++;
     state.networkTime = Network.time;
     state.serverFrame = ServerSimulation.frameNumber;
 }
Ejemplo n.º 30
0
 public PlayerInputEvent(OpenPlayer player, PlayerInput input, PlayerInputState state) : base(player)
 {
     Input = input;
     State = state;
 }