Example #1
0
    internal void SetFacing(AI.Direction playerFacing)
    {
        switch (playerFacing)
        {
        case AI.Direction.NONE:
            break;

        case AI.Direction.UP:
            break;

        case AI.Direction.DOWN:
            break;

        case AI.Direction.LEFT:
            playerBody.transform.localScale   = startingBodyScale;
            weaponParent.transform.localScale = startingWeaponScale;
            break;

        case AI.Direction.RIGHT:
            // flip our x axis scale to flip the sprite
            playerBody.transform.localScale   = new Vector3(-startingBodyScale.x, startingBodyScale.y, startingBodyScale.z);
            weaponParent.transform.localScale = new Vector3(-startingWeaponScale.x, startingWeaponScale.y, startingWeaponScale.z);
            break;
        }
    }
 private void FindClosestWall()
 {
     if (objectOnLeft && objectOnRight)
     {
         // Left object is closer
         if (Vector2.Distance(objectOnLeft.transform.position, transform.position) <
             Vector2.Distance(objectOnRight.transform.position, transform.position))
         {
             wallDirection = AI.Direction.LEFT;
         }
         else
         {
             wallDirection = AI.Direction.RIGHT;
         }
     }
     else if (objectOnLeft)
     {
         wallDirection = AI.Direction.LEFT;
     }
     else if (objectOnRight)
     {
         wallDirection = AI.Direction.RIGHT;
     }
     else
     {
         wallDirection = AI.Direction.NONE;
     }
 }
    private void UpdatePlayerDirectionFromInput()
    {
        if (Mathf.Approximately(xInput, 0f))
        {
            return;
        }

        if (xInput < 0f && playerFacing == AI.Direction.RIGHT ||
            xInput > 0f && playerFacing == AI.Direction.LEFT)
        {
            playerFacing = AI.OppositeDirection(playerFacing);
            cameraFollowScript.SetPlayerTurnaroundX(transform.position.x);
            playerOrganizer.SetFacing(playerFacing);
        }
    }
    }     // END OF UPDATE FUNCTION

    private void SetMotionState(MotionState newMotionState)
    {
        if (newMotionState == motionState)
        {
            // this should never happen, but...
            return;
        }

        prevMotionState   = motionState;
        motionState       = newMotionState;
        currentStateTimer = 0f;

        switch (prevMotionState)
        {
        case MotionState.SWING:
            if (weaponHand.HasRope())
            {
                weaponHand.BreakRope();
            }
            break;
        }


        switch (motionState)
        {
        case MotionState.DODGE:
            dodgeDirection = AI.FloatToHorizontalDirection(dodgeInput);
            // Make us invulnerable for the duration of the dodge.
            SetInvulnerabilityTime(dodgeStateTime);
            break;

        case MotionState.FALL:
            // Set an angle in our motion curve.
            // We move up slowly but as soon as our speed hits zero, shoot us downwards.
            // Increase to decrease feeling of suddenly falling at top of jump.
            yVel = -1f;
            break;
        }

        prevMotionState = motionState;
        motionState     = newMotionState;

        if (debugStateText)
        {
            debugStateText.text = motionState.ToString();
        }
    }
Example #5
0
    protected void SetDirection(AI.Direction dir)
    {
        direction = dir;

        // Update scaling for appropriate local axis directions and sprite reorientation
        Vector3 scale = transform.localScale;

        switch (direction)
        {
        case AI.Direction.NONE:
            break;

        case AI.Direction.UP:
            break;

        case AI.Direction.DOWN:
            break;

        case AI.Direction.LEFT:
            scale   = transform.localScale;
            scale.x = -Mathf.Abs(scale.x);
            transform.localScale = scale;

            scale   = healthBarLocation.transform.localScale;
            scale.x = -Mathf.Abs(scale.x);
            healthBarLocation.transform.localScale = scale;     // flip the health bar again to keep it correct
            break;

        case AI.Direction.RIGHT:
            scale   = transform.localScale;
            scale.x = Mathf.Abs(scale.x);
            transform.localScale = scale;

            scale   = healthBarLocation.transform.localScale;
            scale.x = Mathf.Abs(scale.x);
            healthBarLocation.transform.localScale = scale;     // flip the health bar again to keep it correct
            break;
        }
    }
 public void Load(PlayerData data)
 {
     playerFacing = data.facingLeft ? (AI.Direction.LEFT) : (AI.Direction.RIGHT);
 }