示例#1
0
        private void HandleMovementTick(int playerIndex)
        {
            // todo: investigate f****d movement, might just be my controller though.
            var horizontalValue   = KeyboardOrControllerSelectionAxis($"P{playerIndex}_Horizontal");
            var verticalValue     = KeyboardOrControllerSelectionAxis($"P{playerIndex}_Vertical");
            var verticalDownValue = GetAxisRaw($"CONTROLLERP{playerIndex}_VerticalDown");

            if (verticalDownValue < 0f)
            {
                // yeah sorry im just getting this done i dont care if its nested f**k you
                if (Mathf.Abs(verticalValue) < 0.5f)
                {
                    verticalValue = verticalDownValue;
                }
            }

            if (horizontalValue == 0f && verticalValue == 0f)
            {
                return;
            }

            Vector2 direction = new Vector2(
                horizontalValue,
                verticalValue
                );

            var packet = new PlayerInputPacket(
                PlayerActions.MOVEMENT,
                playerIndex,
                direction
                );

            OnMove?.Invoke(packet);
        }
示例#2
0
        public void HandleMove(PlayerInputPacket packet)
        {
            if (isStunned)
            {
                return;
            }

            // Apply movement force
            var direction = packet.MovementDirection;

            // Jump
            // and fly down
            if ((direction.y > 0f && myGroundCheck.isTouchingGround) ||
                (direction.y < 0f && !myGroundCheck.isTouchingGround))
            {
                myRb.AddForce(new Vector2(0, myJumpHeight * direction.y), ForceMode2D.Impulse);

                if (direction.y > 0)
                {
                    myAnimations.PlayAnimation("Jump");
                }
            }

            // Handle x axis
            Vector2 currentPosition = myTransform.position;

            currentPosition.x   += direction.x * (Time.deltaTime * mySpeed);
            myTransform.position = currentPosition;

            // Flip model
            HandleRotation(direction.x);

            // Handle Animation
            myAnimations.Animator.SetBool(
                "isMoving",
                true
                );


            hasStopped = false;
        }
示例#3
0
        private void HandleAttackTick(int playerIndex)
        {
            bool isDefault = KeyboardOrControllerSelectionButton($"P{playerIndex}_Fire");
            bool isSpecial = KeyboardOrControllerSelectionButton($"P{playerIndex}_SpecialFire");

            int type =
                isDefault ? (int)AttackTypes.DEFAULT :
                isSpecial ? (int)AttackTypes.SPECIAL :
                -1;

            if (type < 0)
            {
                return;
            }

            var packet = new PlayerInputPacket(
                PlayerActions.FIRE,
                playerIndex,
                new Vector2()
                );

            OnFire?.Invoke(packet, (AttackTypes)type);
        }