Esempio n. 1
0
    private void CheckCanHook()
    {
        if (gm.gameState == GameManager.GameStates.mountain)
        {
            worldMousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            facingDir     = worldMousePos - transform.position;

            LayerMask    mask = LayerMask.GetMask("Obstacles");
            RaycastHit2D hit  = Physics2D.Raycast(transform.position, facingDir, hookDist, mask);

            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, hit.point);

            Debug.DrawRay(transform.position, facingDir, Color.red);

            if (Input.GetMouseButtonDown(0) && hit && gm.GrappleAmmoAmount > 0)
            {
                lineRenderer.enabled = true;
                lineRenderer.SetPosition(0, transform.position);
                lineRenderer.SetPosition(1, hit.point);
                Debug.Log("Button Down");
                hookDirOnClick        = facingDir;
                gm.GrappleAmmoAmount -= 1;
                moveState             = movementStates.hook;
            }
            if (Input.GetMouseButtonUp(0))
            {
                lineRenderer.enabled = false;
                moveState            = movementStates.regMovement;
            }
        }
    }
Esempio n. 2
0
    private void Awake()
    {
        animator      = holder2D.GetComponent <Animator>();
        movementQueue = new Queue <int>();
        combatQueue   = new Queue <int>();

        x                   = (int)transform.position.x;
        y                   = (int)transform.position.z;
        unitMoveState       = movementStates.Unselected;
        currentHealthPoints = maxHealthPoints;
        hitPointsText.SetText(currentHealthPoints.ToString());
    }
Esempio n. 3
0
 void EnterState(movementStates state)
 {
     switch (state)
     {
     case movementStates.STANDING:
         this.GetComponent<MeshRenderer>().material.color = Color.black;
         inputManager.standing = new Job (inputManager.standingState(
                                         ()=> {moveState = movementStates.WALKING;},
                                         ()=> {moveState = movementStates.SPRINTING;},
                                         ()=> {moveState = movementStates.AIR;},
                                         ()=> {moveState = movementStates.CROUCHING;},
                                         ()=> {moveState = movementStates.SHIELDING;},
                                         ()=> {moveState = movementStates.GRABBING;}),true);
         break;
     case movementStates.WALKING:
         this.GetComponent<MeshRenderer>().material.color = Color.blue;
         inputManager.walking = new Job (inputManager.walkingState(
                                         ()=> {moveState = movementStates.STANDING;},
                                         ()=> {moveState = movementStates.AIR;},
                                         ()=> {moveState = movementStates.SHIELDING;},
                                         ()=> {moveState = movementStates.GRABBING;}),true);
         break;
     case movementStates.SPRINTING:
         this.GetComponent<MeshRenderer>().material.color = Color.cyan;
         inputManager.sprinting = new Job (inputManager.sprintingState(
                                         ()=> {moveState = movementStates.STANDING;},
                                         ()=> {moveState = movementStates.AIR;},
                                         ()=> {moveState = movementStates.SHIELDING;},
                                         ()=> {moveState = movementStates.GRABBING;}),true);
         break;
     case movementStates.AIR:
         this.GetComponent<MeshRenderer>().material.color = Color.magenta;
         inputManager.air = new Job (inputManager.airState(
                                     ()=> {moveState = movementStates.STANDING;}),true);
         break;
     case movementStates.CROUCHING:
         this.GetComponent<MeshRenderer>().material.color = Color.gray;
         inputManager.crouching = new Job (inputManager.crouchState(
                                         ()=> {moveState = movementStates.STANDING;},
                                         ()=> {moveState = movementStates.SHIELDING;},
                                         ()=> {moveState = movementStates.AIR;}),true);
         break;
     case movementStates.GRABBING:
         this.GetComponent<MeshRenderer>().material.color = Color.green;
         break;
     case movementStates.SHIELDING:
         this.GetComponent<MeshRenderer>().material.color = Color.red;
         break;
     case movementStates.ONLEDGE:
         this.GetComponent<MeshRenderer>().material.color = Color.yellow;
         break;
     }
 }
Esempio n. 4
0
    void Start()
    {
        moveState  = movementStates.regMovement;
        controller = GetComponent <Controller2D>();
        anim       = GetComponent <Animator>();
        gm         = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager>();

        //equation for turning movement in to velocity for movement
        gravity         = -(2 * maxJumpHeight) / Mathf.Pow(timeToApex, 2);
        maxJumpVelocity = Mathf.Abs(gravity) * timeToApex;
        minJumpVelocity = Mathf.Sqrt(2 * Mathf.Abs(gravity) * minJumpHeight);

        playerPos = transform.position;
    }
 public void setMovementState(int i)
 {
     if (i == 0)
     {
         unitMoveState = movementStates.Unselected;
     }
     else if (i == 1)
     {
         unitMoveState = movementStates.Selected;
     }
     else if (i == 2)
     {
         unitMoveState = movementStates.Moved;
     }
     else if (i == 3)
     {
         unitMoveState = movementStates.Wait;
     }
 }
Esempio n. 6
0
    public void setMovementState(int i)
    {
        switch (i)
        {
        case 0:
            unitMoveState = movementStates.Unselected;  break;

        case 1:
            unitMoveState = movementStates.Selected; break;

        case 2:
            unitMoveState = movementStates.Moved; break;

        case 3:
            unitMoveState = movementStates.Wait; break;

        default:
            break;
        }
    }
Esempio n. 7
0
    private void Move()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0; //stops accumulation of gravity
        }

        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if (gm.gameState == GameManager.GameStates.mountain)
        {
            if (Input.GetKey(KeyCode.LeftShift) && canDash && gm.dashPotionAmount > 0)
            {
                Debug.Log("is dashing");
                AudioSource.PlayClipAtPoint(dashSFX, Camera.main.transform.position, vol);
                moveState = movementStates.dashing;
                dashTime -= Time.deltaTime;

                if (dashTime <= 0)
                {
                    canDash              = false;
                    dashTime             = dashTimeDefault;
                    gm.dashPotionAmount -= 1;
                    moveState            = movementStates.regMovement;
                }
            }
            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                Debug.Log("is regMovement");
                moveState = movementStates.regMovement;
            }
        } //dashing only works when mountain

        if (doJump)
        {
            //Debug.Log("is jumping");
            Jump(maxJumpVelocity);
        }

        //input for min jump height
        if (doHop)
        {
            if (velocity.y > minJumpVelocity)
            {
                velocity.y = minJumpVelocity;
            }

            doHop = false;
        }

        switch (moveState)
        {
        case movementStates.regMovement:

            float targetVelocityX = input.x * moveSpeed;
            velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocitySmoothing, (controller.collisions.below) ? accelTimeGround : accelTimeAir);
            velocity.y += gravity * Time.deltaTime;

            bool PlayerHasMovement = Mathf.Abs(input.x) > Mathf.Epsilon;

            if (controller.collisions.below)
            {
                anim.SetBool("Running", PlayerHasMovement);
            }
            else
            {
                anim.SetBool("Running", false);
            }

            break;

        case movementStates.dashing:

            velocity = new Vector3(input.x * dashSpeed, 0);     //change to 0 if dont like feel
            break;

        case movementStates.hook:

            velocity = hookDirOnClick * hookSpeed;
            if (controller.collisions.above || controller.collisions.below)
            {
                velocity.x = 0;     //stops accumulation of gravity
            }
            if (controller.collisions.left || controller.collisions.right)
            {
                velocity.y = 0;
            }
            break;
        }
        //movement and acceleration
        controller.Move(velocity * Time.deltaTime);
    }
Esempio n. 8
0
 void ExitState(movementStates state)
 {
     switch (state)
     {
     case movementStates.STANDING:
         if (inputManager.standing != null)
             inputManager.standing.kill();
         break;
     case movementStates.WALKING:
         if (inputManager.walking != null)
             inputManager.walking.kill();
         break;
     case movementStates.SPRINTING:
         if (inputManager.sprinting != null)
             inputManager.sprinting.kill();
         break;
     case movementStates.CROUCHING:
         if (inputManager.crouching != null)
             inputManager.crouching.kill();
         break;
     case movementStates.GRABBING:
         if (inputManager.grabbing != null)
             inputManager.grabbing.kill();
         break;
     case movementStates.AIR:
         if (inputManager.air != null)
             inputManager.air.kill();
         break;
     case movementStates.SHIELDING:
         if (inputManager.shielding != null)
             inputManager.shielding.kill();
         break;
     case movementStates.ONLEDGE:
         if (inputManager.onLedge != null)
             inputManager.onLedge.kill();
         break;
     }
 }