Exemple #1
0
    private void ChangedSpeedX(PlayerMovingState movingState)
    {
        CurrentMovingState = movingState;

        float speedX;

        switch (movingState)
        {
        case PlayerMovingState.idleLeft:
        case PlayerMovingState.idleRight:
            speedX = 0;
            break;

        case PlayerMovingState.runningLeft:
            speedX = -RunSpeed;
            break;

        case PlayerMovingState.runningRight:
            speedX = RunSpeed;
            break;

        case PlayerMovingState.sprintingLeft:
            speedX = -SprintSpeed;
            break;

        default:     //same as -> case PlayerMovingState.sprintingRight:
            speedX = SprintSpeed;
            break;
        }
        SpeedX = speedX;
    }
Exemple #2
0
    // TCP extra 40B = TCP Header 20B + IPv4 Header 20B
    // UDP extra 28B = UDP Header 8B + IPv4 Header 20B
    //TODO: Make all the constantly sent packets to be compressed into 1
    //      Add a byte which contains 1s for which states changed or not, e.g.
    //      position, movingState, localPosition, localRotation
    //      0b_0000_xyzw       where x=1 if movingState is sent, y=1 if position is sent...
    //TODO: perhaps set the Nagle Algorithm to false on TCP, Socket.NoDelay = true;
    //


    // TCP max 13B + 40B = 53B  (byte 1B packetLen + byte 1B packetID (+ UDP byte 1B clientID)
    // UDP max 14B + 28B = 42B  + byte 1B whatShouldSend/Read
    //                          + byte 1B MoveState + worldVector2 4B playerPosition
    //                          + localVector2 2B armPosition + localRotation 3B armRotation
    internal static void ConstantPlayerData(
        bool shouldSendMoveState, PlayerMovingState moveState,
        bool shouldSendWorldPosition, Vector2 playerPosition,
        bool shouldSendArmPosition, Vector2 armPosition,
        bool shouldSendArmRotation, Quaternion armRotation)
    {
        using (Packet packet = new Packet((byte)ClientPackets.constantPlayerData))
        {
            packet.Write8BoolsAs1Byte(false, false, false, false,
                                      shouldSendMoveState, shouldSendWorldPosition, shouldSendArmPosition, shouldSendArmRotation);

            if (shouldSendArmRotation)
            {
                packet.Write(armRotation);
            }

            if (shouldSendArmPosition)
            {
                packet.WriteLocalPosition(armPosition);
            }

            if (shouldSendWorldPosition)
            {
                packet.WriteWorldUVector2(playerPosition);
            }

            if (shouldSendMoveState)
            {
                packet.Write((byte)moveState);
            }

            SendConstantlySentPacket(packet);
        }
    }
    // Class Functions:
    protected override void InitializeStates()
    {
        #region Create States:
        #region Movement States:
        standingState       = new PlayerStandingState(this, stateMachine);
        combatIdleState     = new PlayerCombatIdleState(this, stateMachine);
        movingState         = new PlayerMovingState(this, stateMachine);
        jumpingState        = new PlayerJumpingState(this, stateMachine);
        fallingState        = new PlayerFallingState(this, stateMachine);
        crouchingState      = new PlayerCrouchingState(this, stateMachine);
        dashingState        = new PlayerDashingState(this, stateMachine);
        sprintingState      = new PlayerSprintingState(this, stateMachine);
        sprintRecoveryState = new PlayerSprintRecoveryState(this, stateMachine);
        slidingState        = new PlayerSlidingState(this, stateMachine);
        slidingJumpState    = new PlayerSlidingJumpState(this, stateMachine);
        standingGuardState  = new PlayerStandingGuardState(this, stateMachine);
        walkingState        = new PlayerWalkingState(this, stateMachine);
        crouchingGuardState = new PlayerCrouchingGuardState(this, stateMachine);
        #endregion // Movement States
        #region Action States:
        lightActionState  = new PlayerLightActionState(this, stateMachine);
        mediumActionState = new PlayerMediumActionState(this, stateMachine);
        heavyActionState  = new PlayerHeavyActionState(this, stateMachine);
        #endregion // Action States
        #region Reaction States:
        //burstState = new PlayerBurstState(this, stateMachine);
        //hitHighState = new PlayerHitHighState(this, stateMachine);
        //hitMedState = new PlayerHitMedState(this, stateMachine);
        //hitLowState = new PlayerHitLowState(this, stateMachine);
        //hitAirState = new PlayerHitAirState(this, stateMachine);
        //recoveryState = new PlayerRecoveryState(this, stateMachine);
        //knockbackState = new PlayerKnockbackState(this, stateMachine);
        //knockdownState = new PlayerKnockdownState(this, stateMachine);
        //deathState = new PlayerDeathState(this, stateMachine);
        #endregion // Reaction States
        #region Combat States:
        #region Unarmed States:
        #region Normals:
        #endregion // Normals
        #region Specials:
        //airAxeKick = new AirAxeKick(this, stateMachine);
        //airDragonPunch = new AirDragonPunch(this, stateMachine);
        feintRoll = new FeintRoll(this, stateMachine);
        //groundDragonPunch = new GroundDragonPunch(this, stateMachine);
        //hookKick = new HookKick(this, stateMachine);
        //lowKick = new LowKick(this, stateMachine);
        //rollingAxeKick = new RollingAxeKick(this, stateMachine);
        //snapKick = new SnapKick(this, stateMachine);
        //thrustKick = new ThrustKick(this, stateMachine);
        //verticalKick = new VerticalKick(this, stateMachine);
        #endregion // Specials
        #endregion // Unarmed States
        #endregion // Combat States
        #endregion // Create States

        // Initialize the starting states
        startState = standingState;
    }
Exemple #4
0
    void UpdatePlaying()
    {
        PlayerMovingState state = pm.MovingState;

        animatorBlue.speed = 1;
        animatorRed.speed  = 1;

        if (!pm.FacingRight)
        {
            redSpr.transform.localScale  = new Vector3(-1, 1, 1);
            blueSpr.transform.localScale = new Vector3(-1, 1, 1);
        }
        if (pm.FacingRight)
        {
            blueSpr.transform.localScale = new Vector3(1, 1, 1);
            redSpr.transform.localScale  = new Vector3(1, 1, 1);
        }

        if (state == PlayerMovingState.Iddle)
        {
            animatorRed.SetBool("Jumping", false);
            animatorRed.SetBool("Moving", false);

            animatorBlue.SetBool("Jumping", false);
            animatorBlue.SetBool("Running", false);
        }
        else if (state == PlayerMovingState.Moving)
        {
            animatorRed.SetBool("Jumping", false);
            animatorRed.SetBool("Moving", true);

            animatorBlue.SetBool("Jumping", false);
            animatorBlue.SetBool("Running", true);
        }
        else if (state == PlayerMovingState.Jumping)
        {
            animatorRed.SetBool("Jumping", true);

            animatorBlue.SetBool("Jumping", true);
        }
    }
Exemple #5
0
    void GroundedMovement()
    {
        float vx = MoveX * moveAxis;

        if (jumpPressed)
        {
            vy = jump;
            ps = PlayerState.Air;
        }
        else
        {
            vy = -14;
        }

        bool c = MoveY(vy * Time.fixedDeltaTime);

        MovX(vx * Time.fixedDeltaTime);
        if (!c)
        {
            ps = PlayerState.Air;
        }

        movingState = PlayerMovingState.Jumping;
    }
    } // Draw Is grounded ball to visulize.

    void Move()
    {
        cooldownBeforeJump -= Time.deltaTime;


        if (Input.GetButtonDown(sprintButton) && isGrounded) // If Sprint is pressed AND is grounded
        {
            isSprinting = true;
        }
        else if (Input.GetButtonUp(sprintButton)) // Else if Sprint is released OR is not grounded
        {
            isSprinting = false;
        }



        if (!isGrounded)
        {
            // Is Not Moving at all. Is standing still
            if (xInputValue == 0 && zInputValue == 0)
            {
                currentMovingState = PlayerMovingState.standingStill;
            }
            else // If you are moving!
            {
                // If you hold any move direction, has released sprint or is not grounded
                if (!isSprinting && currentMovingState != PlayerMovingState.walking)
                {
                    currentMovingState = PlayerMovingState.walking;
                    currentSpeed       = walkingSpeed;
                }

                // If you hold Sprint, is grounded and where not allready sprinting. You Start Sprinting.
                else if (isSprinting && currentMovingState == PlayerMovingState.walking)
                {
                    currentMovingState = PlayerMovingState.running;
                    currentSpeed      *= sprintingSpeedMultiplaier;
                }
            }// If you are moving!
        }
        else
        {
            isJumping = false;
        }


        // Are you grounded AND able to jump? THEN JUMP!
        if (isGrounded && cooldownBeforeJump <= 0)
        {
            if (Input.GetButtonDown(jumpButton))
            {
                isJumping = true;
                if (currentMovingState == PlayerMovingState.standingStill)
                {
                    NormalJump();
                    Debug.Log("Normal jump");
                }
                else if (currentMovingState == PlayerMovingState.walking)
                {
                    WalkJump();
                    Debug.Log("Walk jump");
                }
                else if (currentMovingState == PlayerMovingState.running)
                {
                    LongJump();
                    Debug.Log("Long jump");
                }

                cooldownBeforeJump = jumpCooldown;
            }
        }
    }
    public void Init(PlayerController pl)
    {
        player          = pl;
        blinkController = player.GetComponent <BlinkController>();

        animator = player.GetComponent <Animator>();

        hexagons = new List <HexagonController>();

        specialAttackDetector = player.specialDetector;
        specialAttackDetector.GetComponent <PlayerSpecialAttackDetector>().Blackboard = this;
        specialAttackDetector.GetComponent <SphereCollider>().radius = player.specialAttackAffectationRadius;

        dashPSRotator = player.transform.Find("ParticleSystems/DashPSRotation");

        if (InputManager.Devices.Count >= player.Id)
        {
            controller = InputManager.Devices[player.Id - 1];
        }

        spawningState        = new PlayerSpawningState();
        idleState            = new PlayerIdleState();
        longIdleState        = new PlayerLongIdleState();
        movingState          = new PlayerMovingState();
        dashingState         = new PlayerDashingState();
        speedBumpState       = new PlayerSpeedBumpState();
        specialState         = new PlayerSpecialState();
        receivingDamageState = new PlayerReceivingDamageState();
        pushedState          = new PlayerPushedState();
        fallingState         = new PlayerFallingState();
        dyingState           = new PlayerDyingState();
        blockedState         = new PlayerBlockedState();
        invisibleState       = new PlayerInvisibleState();
        levelClearedState    = new PlayerLevelClearedState();

        spawningState.Init(this);
        idleState.Init(this);
        longIdleState.Init(this);
        movingState.Init(this);
        dashingState.Init(this);
        speedBumpState.Init(this);
        specialState.Init(this);
        receivingDamageState.Init(this);
        pushedState.Init(this);
        fallingState.Init(this);
        dyingState.Init(this);
        blockedState.Init(this);
        invisibleState.Init(this);
        levelClearedState.Init(this);

        string playerStr = "";

        switch (player.Id)
        {
        case 1: playerStr = "P1"; break;

        case 2: playerStr = "P2"; break;
        }

        moveHorizontal = playerStr + "_Horizontal";
        moveVertical   = playerStr + "_Vertical";
        aimHorizontal  = playerStr + "_AimHorizontal";
        aimVertical    = playerStr + "_AimVertical";
        fire           = playerStr + "_Fire";
        dash           = playerStr + "_Dash";
        special        = playerStr + "_Special";
        greenButton    = playerStr + "_Green";
        redButton      = playerStr + "_Red";
        blueButton     = playerStr + "_Blue";
        yellowButton   = playerStr + "_Yellow";

        playerRayCastMask  = LayerMask.GetMask(playerStr + "RayCast");
        playerPhysicsLayer = LayerMask.NameToLayer("Player");
        enemyPhysicsPlayer = LayerMask.NameToLayer("Enemy");

        ResetLifeVariables();
    }
Exemple #8
0
 public void SetVelocityState(PlayerMovingState movingState) =>
 OnPlayerMovingStateChange?.Invoke(movingState);
    //Unity methods
    void Awake()
    {
        Debug.Log("Player " + playerId + " created.");
        rend = GetComponentInChildren<Renderer>();
        ctrl = GetComponent<CharacterController>();
        voxelization = GetComponent<VoxelizationClient>();

        spawningState = new PlayerSpawningState();
        idleState = new PlayerIdleState();
        longIdleState = new PlayerLongIdleState();
        movingState = new PlayerMovingState();
        dashingState = new PlayerDashingState();
        specialState = new PlayerSpecialState();
        swingingState = new PlayerSwingingState();
        receivingDamageState = new PlayerReceivingDamageState();
        fallingState = new PlayerFallingState();
        dyingState = new PlayerDyingState();

        spawningState.Init(this);
        idleState.Init(this);
        longIdleState.Init(this);
        movingState.Init(this);
        dashingState.Init(this);
        specialState.Init(this);
        swingingState.Init(this);
        receivingDamageState.Init(this);
        fallingState.Init(this);
        dyingState.Init(this);

        currentState = spawningState;

        string player = "";
        switch (playerId)
        {
            case 1: player = "P1"; break;
            case 2: player = "P2"; break;
        }

        moveHorizontal = player + "_Horizontal";
        moveVertical = player + "_Vertical";
        aimHorizontal = player + "_AimHorizontal";
        aimVertical = player + "_AimVertical";
        fire = player + "_Fire";
        dash = player + "_Dash";
        special = player + "_Special";

        playerRayCastMask = LayerMask.GetMask(player + "RayCast");
        animator = GetComponent<Animator>();
    }