예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (MinigameInputHelper.GetHorizontalAxis(player) < 0.1 &&
            MinigameInputHelper.GetHorizontalAxis(player) > -0.1 /*&&
                                                                  * animator.GetInteger("state") < 2 + TYPE*/)
        {
            animator.SetInteger("state", 0 + TYPE);
        }
        else if (animator.GetInteger("state") < 2 + TYPE)
        {
            animator.SetInteger("state", 1 + TYPE);
        }
        jumpTime += Time.deltaTime;
        if (animator.GetInteger("state") == 2 + TYPE && jumpTime > 1 + TYPE)
        {
            jumpTime = 0;
            animator.SetInteger("state", 0 + TYPE);
        }
        pos       = set_vec2(this.transform.position.x, this.transform.position.y);
        pos2      = set_vec2(other.transform.position.x, other.transform.position.y);
        read_vel2 = (pos2 - pos2_old) / Time.deltaTime;
        pos2_old  = set_vec2(other.transform.position.x, other.transform.position.y);
        joystick  = set_vec2(
            MinigameInputHelper.GetHorizontalAxis(player),
            MinigameInputHelper.GetVerticalAxis(player)
            );
        float ground = (platform.pos.y + platform.height + (float)(0.3 * playerHeight));

        if (joystick.y > 0 && (up == false || pos.y <= ground + 0.1))
        {
            if (pos.x <= platform.pos.x + platform.width / 2 &&
                pos.x >= platform.pos.x - platform.width / 2 &&
                pos.y <= ground)
            {
                jump_count = 0;
            }
            if (jump_count < max_jump)            // || (double_jump && jump_count < 1)){
            {
                jump();
                up = true;
            }
        }
        if (joystick.y > 0)
        {
            up = true;
        }
        else
        {
            up = false;
        }
        //collision with platform
        if (within_bounds(pos, platform) && !up)
        {
            vel.y = 0;            //transform.position.y = platform;
            transform.Translate(0f, (float)(ground - pos.y), 0f);
        }
        else if (pos.y < -8)
        {
            vel.y = 0;            //stops from infinite falling
            vel.x = 0;
            double spawn;
            animator.SetInteger("state", 1);
            if (pos2.x < platform.pos.x)
            {
                spawn = 6.5;    //actually fell on the left side
                gameObject.GetComponent <ActionScript>().setDirection(true);
                dir = -1;
            }
            else
            {
                spawn = -6.5;        //assuming fell on right side
                gameObject.GetComponent <ActionScript>().setDirection(false);
                dir = 1;
            }
            const int start_y = 5;
            transform.Translate((float)(spawn - pos.x), (float)(start_y - pos.y), 0f);
            other.GetComponent <HealthScript>().TakeDamage(5);
            sound.PlayDie();
        }
        if (pos.y <= ground)        //+thresh?
        {
            if (pos.x <= platform.pos.x + platform.width / 2 &&
                pos.x >= platform.pos.x - platform.width / 2 && !up)
            {
                jump_count = 0;
            }
            run((run_vel / 10) * joystick.x);
        }
        else if (abs(joystick.x) > 0)
        {
            run((float)0.9 * joystick.x);                               //slight air movement
        }
        else
        {
            accel.x = (float)(-0.001 * vel.x);
        }
        vel.x += accel.x;
        vel.y += accel.y;
        vel.x  = clamp(-max_vel, max_vel, vel.x);         //clamped at max_vel m/s
        vel.y  = clamp(-2 * max_vel, 2 * max_vel, vel.y); //terminal velocity
        if (abs(pos.x - pos2.x) <= playerWidth && abs(pos.y - pos2.y) <= playerHeight)
        {
            collision(ground);
            is_in = true;
        }
        else
        {
            is_in = false;
        }
        float ballcharge = this.GetComponent <ActionScript>().ballCharge;

        //arrow.transform.Translate(0, 0, 0);
        if (MinigameInputHelper.GetHorizontalAxis(player) < 0)
        {
            dir = -1;
        }
        else if (MinigameInputHelper.GetHorizontalAxis(player) > 0)
        {
            dir = 1;
        }
        if (ballcharge > 0 && TYPE == 0)
        {
            arrow.transform.Rotate(new Vector3(0, 0, 1), dir * ((3 * ballcharge) * Time.deltaTime));
            arrow.transform.localScale = new Vector3((float)(0.2), (float)(0.2), 1);
        }
        else
        {
            arrow.transform.rotation   = Quaternion.identity;
            arrow.transform.localScale = new Vector3(0, 0, 0);
        }
        //if(player == 0){
        if (dir < 0)
        {
            arrow.GetComponent <SpriteRenderer>().flipX = false;
        }
        else if (dir > 0)
        {
            arrow.GetComponent <SpriteRenderer>().flipX = true;
        }

        this.transform.localScale = new Vector3((float)(1.2 * playerWidth), (float)(1.2 * playerHeight), 1);
        transform.Translate(
            vel.x * Time.deltaTime,
            vel.y * Time.deltaTime,
            0.0f
            );
    }