public void Jump(JumperDirection direction)
    {
        currentDirection = direction;

        if (jumping) {
            Debug.Log ("still in the air!!!");
            return;
        }

        rigidBody.isKinematic = true;
        rigidBody.detectCollisions = true;

        switch(currentDirection){
        case JumperDirection.left:
            toPostion = transform.position + new Vector3(-distance,0,0);
            break;
        case JumperDirection.right:
            toPostion = transform.position + new Vector3(distance,0,0);
            break;
        case JumperDirection.backward:
            toPostion = transform.position + new Vector3(0,-stepHeight,-distance);
            break;
        case JumperDirection.forward:
            toPostion = transform.position + new Vector3(0,stepHeight,distance);
            break;
        }

        fromPosition = transform.position;
        startTime = Time.time;
        jumping = true;
    }
 // Use this for initialization
 void Start()
 {
     player.OnJumperEnded += OnJumperEnded;
     finalDirection = JumperDirection.forward;
     jumperQueue = new Queue<JumperDirection> ();
     pressed = false;
 }
Example #3
0
    public void Jump(JumperDirection direction)
    {
        rotateObject.RotateTo (direction);

        internalJump (direction);

        UnSquat ();
    }
    // Update is called once per frame
    void Update()
    {
        // Update is called once per frame

        InputCommand command = inputHandler.InputHandle();

        if (command != InputCommand.None) {
            if (GameController.GameState != GameController.GAME_STATE_PLAY) {

                //GameObject.Find ("_main").GetComponent<GameController> ().StartGame ();
                //player.QuickJump(JumperDirection.forward);
                return;
            }
        }

        if (player.IsDead) {
            return;
        }

        switch (command) {
        case InputCommand.Tap:
            player.QuickJump(JumperDirection.forward);
            break;
        case InputCommand.Left:
            player.Squat();
            finalDirection = JumperDirection.left;
            player.Rotate(finalDirection);
            break;
        case InputCommand.Right:
            player.Squat();
            finalDirection = JumperDirection.right;
            player.Rotate(finalDirection);
            break;
        case InputCommand.Up:
            player.Squat();
            finalDirection = JumperDirection.forward;
            player.Rotate(finalDirection);
            break;
        case InputCommand.Down:
            player.Squat();
            finalDirection = JumperDirection.backward;
            player.Rotate(finalDirection);
            break;
        case InputCommand.Realese:
            player.Jump(finalDirection);
            break;
        case InputCommand.TouchBegin:
            player.Squat();
            break;
        case InputCommand.Canceled:
            player.UnSquat();
            break;
        default:
            break;
        }
        //if(command != InputCommand.None)
        //Debug.Log (command + " " + finalDirection);
    }
Example #5
0
    public void QuickJump(JumperDirection direction)
    {
        if (!jumpSlerpObject.Done())
            return;

        rotateObject.RotateTo (direction);
        internalJump (direction);
        animator.SetBool ("Squeeze",false);
        animator.SetTrigger ("QuickJump");
    }
    void Start()
    {
        objectVision = GetComponent<ObjectVision> ();
        jumpSlerpObject = GetComponent<JumpSlerpObject> ();
        rotateObject = GetComponent<RotateObject> ();

        int startDir = Random.Range (1, 30);

        currentDirection = startDir >= 15 ? JumperDirection.left : JumperDirection.right;
    }
    public override void Action()
    {
        if (objectVision.isOnEdge (currentDirection) || objectVision.hasBarrier(currentDirection)) {

            currentDirection = currentDirection == JumperDirection.left ? JumperDirection.right : JumperDirection.left;
            rotateObject.RotateTo(currentDirection);

        } else {
            rotateObject.RotateTo(currentDirection);
            jumpSlerpObject.Jump(currentDirection);
        }
    }
    public bool isOnEdge(JumperDirection direction = JumperDirection.forward)
    {
        Ray ray = GetOnEndgeRay (direction);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray ,out hitInfo, visionDistance )) {

            if(hitInfo.collider.gameObject != null)
                return false;
        }

        return true;
    }
    public bool hasBarrier(JumperDirection direction)
    {
        Ray ray = GetObstacleRay (direction);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray ,out hitInfo, visionDistance )) {

            if(isInTags(hitInfo.collider.gameObject.tag)){
                return true;
            }
        }

        ray = new Ray(transform.position + barrierCheckOffset ,ray.direction);
        if (Physics.Raycast(ray ,out hitInfo, visionDistance )) {

            if(isInTags(hitInfo.collider.gameObject.tag)){
                return true;
            }
        }

        return false;
    }
    private Vector3 GetVectorFromDirection(JumperDirection direction)
    {
        Vector3 vector = Vector3.forward;

        switch(direction){

        case JumperDirection.left:
            vector = Vector3.left;
            break;
        case JumperDirection.right:
            vector = Vector3.right;
            break;
        case JumperDirection.forward:
            vector = Vector3.forward;
            break;
        case JumperDirection.backward:
            vector = Vector3.back;
            break;

        }

        return vector;//transform.TransformDirection(vector);
    }
Example #11
0
    public void Rotate(JumperDirection direction)
    {
        if (!jumpSlerpObject.Done())
            return;

        rotateObject.RotateTo (direction);
    }
 private Ray GetObstacleRay(JumperDirection direction)
 {
     Vector3 dir = GetVectorFromDirection(direction);
     return new Ray(transform.position + barrierCheckOffset ,dir);
 }
 private Ray GetOnEndgeRay(JumperDirection direction)
 {
     Vector3 diagoanl = GetVectorFromDirection (direction) + Vector3.down;
     return new Ray(transform.position + edgeCheckOffset ,diagoanl);
 }
Example #14
0
    private void internalJump(JumperDirection direction)
    {
        if(!objectVision.hasBarrier(direction) && !objectVision.isOnEdge(direction)){

            jumpSlerpObject.Jump (direction);
            if(!audioSource.isPlaying){
                audioSource.pitch = Random.Range(0.7f,1.3f);
                audioSource.Play();
            }
        }
    }
Example #15
0
    private void OnJumpEnded(JumperDirection direction)
    {
        if (rotateObject.Done()) {
            OnJumperEnded();
        }

        if (direction == JumperDirection.forward) {
            currentStepPostion ++;
            maxPosition++;
        }
        if (direction == JumperDirection.backward) {
            currentStepPostion --;
        }
    }
Example #16
0
 private void OnRotateEnded(JumperDirection direction)
 {
     if (jumpSlerpObject.Done()) {
         OnJumperEnded();
     }
 }
Example #17
0
 private void OnRotateStarted(JumperDirection direction)
 {
 }
    public void RotateTo(JumperDirection direction)
    {
        currentDirection = direction;

        switch (currentDirection) {

        case JumperDirection.left:
            FaceLeft();
            break;
        case JumperDirection.right:
            FaceRight();
            break;
        case JumperDirection.forward:
            FaceForward();
            break;
        case JumperDirection.backward:
            FaceBackward();
            break;
        default: break;
        }
        if (OnRotationStarted != null) {
            OnRotationStarted (currentDirection);
        }
    }