Beispiel #1
0
 void not_near_stairs(stair_info info)
 {
     // If we overlap stairs, dont "exit" the new stairs
     if (this.cur_stairs.pos.x == info.pos.x)
     {
         print("leaving stairs");
         Vector2 pos;
         pos.x          = 0;
         pos.y          = 0;
         cur_stairs.pos = pos;
     }
     else
     {
         print("overlapping stairs");
     }
 }
Beispiel #2
0
 void not_near_stairs(stair_info info)
 {
     // If we overlap stairs, dont "exit" the new stairs
     if (this.cur_stairs.pos.x == info.pos.x){
         print("leaving stairs");
         Vector2 pos;
         pos.x = 0;
         pos.y = 0;
         cur_stairs.pos = pos;
     }
     else {
         print ("overlapping stairs");
     }
 }
Beispiel #3
0
 void near_stairs(stair_info info)
 {
     this.cur_stairs = info;
 }
Beispiel #4
0
    void input()
    {
        float h = Input.GetAxis ("Horizontal");

        Vector2 vel = rigidbody2D.velocity;
        if (grounded && !animator.GetBool ("whipping")) {
            vel.x = h * speed;
        }

        if (Input.GetKeyDown(KeyCode.Z)) {
            if (grounded && !animator.GetBool ("crouch")) {
                vel.y = jumpSpeed;
            }
        }

        if (Input.GetKey (KeyCode.DownArrow) && !gettingOnStairs) {
            if (grounded) {
                vel.x = 0;
                animator.SetBool ("crouch", true);
            }
        }
        else {
            animator.SetBool ("crouch", false);
        }

        if (Input.GetKeyDown (KeyCode.X)) {
            animator.SetBool("whipping", true);
            whip_end = Time.time + whip_time;
            whip_dir = animator.GetInteger ("direction_x");
            if (grounded) {
                vel.x = 0;
            }
        }

        // Get on stairs if we are close
        if (Input.GetKeyDown (KeyCode.UpArrow)) {
            // If we are on the ground by the bottom of a staircase
            if (grounded && cur_stairs.pos.x != 0
                && (cur_stairs.dir == 0 || cur_stairs.dir == 3)
                && !on_stairs) {
                gettingOnStairs = true;
                on_stair_info = cur_stairs;
            }
        }
        if (Input.GetKeyDown (KeyCode.DownArrow)){
            if (grounded && cur_stairs.pos.x != 0
                && (cur_stairs.dir == 1 || cur_stairs.dir == 2)
                && !on_stairs) {
                gettingOnStairs=true;
                on_stair_info = cur_stairs;
            }
        }

        // Stairs movement
        if (on_stairs){
            if (on_stair_info.dir == 0 || on_stair_info.dir == 1) {
                // We are on a up/right stair
                if (Input.GetKey (KeyCode.UpArrow)
                    || Input.GetKey (KeyCode.RightArrow)) {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 1) {
                        if (transform.position.y < cur_stairs.pos.y-.2) {
                            vel.x = 2;
                            vel.y = 2;
                        }
                        else {
                            gettingOffStairs = true;
                        }
                    }
                    else {
                        vel.x = 2;
                        vel.y = 2;
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow)
                         || Input.GetKey(KeyCode.LeftArrow)) {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 0){
                        if (transform.position.y > cur_stairs.pos.y+.2) {
                            vel.x=-2;
                            vel.y=-2;
                        }
                        else {
                            gettingOffStairs = true;
                        }
                    }
                    else {
                        vel.x=-2;
                        vel.y=-2;
                    }

                }
                else {
                    vel.x=0;
                    vel.y=0;
                }
            }
            else {
                // We are on a down/left stair
                if (Input.GetKey (KeyCode.UpArrow)
                    || Input.GetKey (KeyCode.LeftArrow)) {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 2) {
                        if (transform.position.y < cur_stairs.pos.y-.2) {
                            vel.x = -2;
                            vel.y = 2;
                        }
                        else {
                            gettingOffStairs = true;
                        }
                    }
                    else {
                        vel.x = -2;
                        vel.y = 2;
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow)
                         || Input.GetKey(KeyCode.RightArrow)) {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 3){
                        if (transform.position.y > cur_stairs.pos.y+.2) {
                            vel.x=2;
                            vel.y=-2;
                        }
                        else {
                            gettingOffStairs = true;
                        }
                    }
                    else {
                        vel.x=2;
                        vel.y=-2;
                    }

                }
                else {
                    vel.x=0;
                    vel.y=0;
                }
            }
        }
        rigidbody2D.velocity = vel;
    }
Beispiel #5
0
 void near_stairs(stair_info info)
 {
     this.cur_stairs = info;
 }
Beispiel #6
0
    void input()
    {
        float h = Input.GetAxis("Horizontal");

        Vector2 vel = rigidbody2D.velocity;

        if (grounded && !animator.GetBool("whipping"))
        {
            vel.x = h * speed;
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            if (grounded && !animator.GetBool("crouch"))
            {
                vel.y = jumpSpeed;
            }
        }

        if (Input.GetKey(KeyCode.DownArrow) && !gettingOnStairs)
        {
            if (grounded)
            {
                vel.x = 0;
                animator.SetBool("crouch", true);
            }
        }
        else
        {
            animator.SetBool("crouch", false);
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            animator.SetBool("whipping", true);
            whip_end = Time.time + whip_time;
            whip_dir = animator.GetInteger("direction_x");
            if (grounded)
            {
                vel.x = 0;
            }
        }

        // Get on stairs if we are close
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            // If we are on the ground by the bottom of a staircase
            if (grounded && cur_stairs.pos.x != 0 &&
                (cur_stairs.dir == 0 || cur_stairs.dir == 3) &&
                !on_stairs)
            {
                gettingOnStairs = true;
                on_stair_info   = cur_stairs;
            }
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            if (grounded && cur_stairs.pos.x != 0 &&
                (cur_stairs.dir == 1 || cur_stairs.dir == 2) &&
                !on_stairs)
            {
                gettingOnStairs = true;
                on_stair_info   = cur_stairs;
            }
        }

        // Stairs movement
        if (on_stairs)
        {
            if (on_stair_info.dir == 0 || on_stair_info.dir == 1)
            {
                // We are on a up/right stair
                if (Input.GetKey(KeyCode.UpArrow) ||
                    Input.GetKey(KeyCode.RightArrow))
                {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 1)
                    {
                        if (transform.position.y < cur_stairs.pos.y - .2)
                        {
                            vel.x = 2;
                            vel.y = 2;
                        }
                        else
                        {
                            gettingOffStairs = true;
                        }
                    }
                    else
                    {
                        vel.x = 2;
                        vel.y = 2;
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow) ||
                         Input.GetKey(KeyCode.LeftArrow))
                {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 0)
                    {
                        if (transform.position.y > cur_stairs.pos.y + .2)
                        {
                            vel.x = -2;
                            vel.y = -2;
                        }
                        else
                        {
                            gettingOffStairs = true;
                        }
                    }
                    else
                    {
                        vel.x = -2;
                        vel.y = -2;
                    }
                }
                else
                {
                    vel.x = 0;
                    vel.y = 0;
                }
            }
            else
            {
                // We are on a down/left stair
                if (Input.GetKey(KeyCode.UpArrow) ||
                    Input.GetKey(KeyCode.LeftArrow))
                {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 2)
                    {
                        if (transform.position.y < cur_stairs.pos.y - .2)
                        {
                            vel.x = -2;
                            vel.y = 2;
                        }
                        else
                        {
                            gettingOffStairs = true;
                        }
                    }
                    else
                    {
                        vel.x = -2;
                        vel.y = 2;
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow) ||
                         Input.GetKey(KeyCode.RightArrow))
                {
                    if (cur_stairs.pos.x != 0 && cur_stairs.dir == 3)
                    {
                        if (transform.position.y > cur_stairs.pos.y + .2)
                        {
                            vel.x = 2;
                            vel.y = -2;
                        }
                        else
                        {
                            gettingOffStairs = true;
                        }
                    }
                    else
                    {
                        vel.x = 2;
                        vel.y = -2;
                    }
                }
                else
                {
                    vel.x = 0;
                    vel.y = 0;
                }
            }
        }
        rigidbody2D.velocity = vel;
    }