예제 #1
0
    // ==================================================
    private void Update()
    {
        float dt = Time.deltaTime;

        if (SCR_Gameplay.instance.gameState == GameState.BOSS_FALLING)
        {
            dt = 0;
        }

        if (state >= BossState.FLY_1 && state <= BossState.FLY_6)
        {
            if (SCR_Profile.showTutorial == 1)
            {
                if (SCR_Gameplay.instance.tutorialStep == TutorialStep.AIM)
                {
                    predictY         = y - (SCR_Gameplay.GRAVITY * BOSS_TUTORIAL_DELTA * BOSS_TUTORIAL_DELTA) * 0.5f;
                    tutorialCounter += dt * 100;
                    tutorialFinger.transform.localPosition = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + SCR_Helper.Sin(tutorialCounter) * SCR_Gameplay.SCREEN_W * 0.3f, predictY, tutorialTarget.transform.localPosition.z);
                    tutorialFinger.SetActive(true);
                    tutorialFinger.GetComponent <SCR_TutorialFinger>().Stop();
                }
                else if (SCR_Gameplay.instance.tutorialStep == TutorialStep.PUNCH)
                {
                    predictX = x + speedX * BOSS_TUTORIAL_DELTA;
                    predictY = y - (SCR_Gameplay.GRAVITY * BOSS_TUTORIAL_DELTA * BOSS_TUTORIAL_DELTA) * 0.5f;
                    tutorialTarget.transform.localPosition = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + predictX, predictY, tutorialTarget.transform.localPosition.z);
                    tutorialTarget.SetActive(true);
                    //tutorialFinger.transform.localPosition = new Vector3 (SCR_Gameplay.SCREEN_W * 0.5f + predictX, predictY, tutorialTarget.transform.localPosition.z);
                    tutorialFinger.SetActive(false);
                    //tutorialFinger.GetComponent<SCR_TutorialFinger>().Animate();

                    if (!tutorialRange)
                    {
                        tutorialRange = Instantiate(PFB_TutorialRange);
                        tutorialRange.transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * 3, SCR_Gameplay.SCREEN_SCALE * 3, 1);
                        tutorialRange.transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + SCR_Gameplay.instance.player.GetComponent <SCR_Player>().x, SCR_Gameplay.instance.cameraHeight - SCR_Player.PLAYER_SIZE, tutorialRange.transform.position.z);
                        float angle = SCR_Helper.AngleBetweenTwoPoint(SCR_Gameplay.instance.player.GetComponent <SCR_Player>().x, SCR_Gameplay.instance.cameraHeight - SCR_Player.PLAYER_SIZE, predictX, predictY);
                        tutorialRange.transform.localEulerAngles = new Vector3(0, 0, -angle);
                    }
                }
            }
            if (SCR_Gameplay.instance.tutorialStep != TutorialStep.AIM && SCR_Gameplay.instance.tutorialStep != TutorialStep.PUNCH)
            {
                float oldSpeedY = speedY;

                if (bubbleTime > 0)
                {
                    speedY -= SCR_Gameplay.GRAVITY * dt * (speedY / 10000);
                }
                else
                {
                    speedY -= SCR_Gameplay.GRAVITY * dt;
                }

                if (speedY < 0 && oldSpeedY >= 0 && SCR_Gameplay.instance.tutorialStep == TutorialStep.THROW)
                {
                    SCR_Gameplay.instance.TriggerTutorial(TutorialStep.AIM);
                }

                if (speedY > maxSpeedY)
                {
                    speedY = maxSpeedY;
                }
                y += speedY * dt;

                //if (speedY > maxSpeedY)	y += maxSpeedY * dt;
                //else                  y += speedY * dt;



                if (magnetTime > 0)
                {
                    if (SCR_Gameplay.instance.player.GetComponent <SCR_Player>().IsFlyingUp())
                    {
                        float flyAngle = SCR_Helper.AngleBetweenTwoPoint(x, y, SCR_Gameplay.instance.player.GetComponent <SCR_Player>().x, SCR_Gameplay.instance.player.GetComponent <SCR_Player>().y);
                        float attractX = BOSS_MAGNET_FORCE * SCR_Helper.Sin(flyAngle);
                        float attractY = BOSS_MAGNET_FORCE * SCR_Helper.Cos(flyAngle);                          // we don't need this actually
                        x += attractX * dt;
                    }
                }

                x += speedX * dt;



                if (x <= -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
                {
                    x = -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                    if (bubbleTime > 0)
                    {
                        speedX = -speedX * 0.7f;
                    }
                    else
                    {
                        speedX = -speedX;
                    }
                    RandomRotate();
                    SCR_Audio.PlayBounceSound();
                }
                else if (x >= (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
                {
                    x = (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                    if (bubbleTime > 0)
                    {
                        speedX = -speedX * 0.7f;
                    }
                    else
                    {
                        speedX = -speedX;
                    }
                    RandomRotate();
                    SCR_Audio.PlayBounceSound();
                }

                if (y <= SCR_Gameplay.instance.cameraHeight - BOSS_SIZE)
                {
                    SwitchState(BossState.FALL);
                    SCR_Gameplay.instance.gameState = GameState.BOSS_FALLING;
                    SCR_Gameplay.instance.Lose();

                    if (size == BossSize.BIG)
                    {
                        Shrink();
                    }

                    SCR_Audio.PlayFallSound();
                }

                rotation += rotateSpeed * dt;

                float r = currentScale.x / originalScale.x;
                atmosBurn.SetActive(true);
                atmosBurn.transform.localPosition = new Vector3(
                    SCR_Gameplay.SCREEN_W * 0.5f + x + BOSS_BURN_OFFSET_X * r,
                    y + BOSS_BURN_OFFSET_Y * r,
                    atmosBurn.transform.localPosition.z);

                float alpha = (speedY - BOSS_BURN_SPEED_MIN) / (BOSS_BURN_SPEED_MAX - BOSS_BURN_SPEED_MIN);
                if (alpha > BOSS_BURN_ALPHA)
                {
                    alpha = BOSS_BURN_ALPHA;
                }
                Color color = atmosBurn.GetComponent <SpriteRenderer>().color;
                color.a = alpha;
                atmosBurn.GetComponent <SpriteRenderer>().color = color;

                if (alpha > 0)
                {
                    SCR_Gameplay.instance.ShakeCamera(0.016f);
                }
            }
        }
        else if (state == BossState.FALL)
        {
            speedY -= SCR_Gameplay.GRAVITY * dt;

            x += speedX * dt;
            y += speedY * dt;

            if (x <= -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                x      = -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                speedX = -speedX;
            }
            else if (x >= (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                x      = (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                speedX = -speedX;
            }

            if (y <= BOSS_START_Y)
            {
                y = BOSS_START_Y;
                SwitchState(BossState.SLIDE);
                SCR_Audio.PlayPunchNormalSound();

                smokeParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x + BOSS_SMOKE_OFFSET_X * direction, y + BOSS_SMOKE_OFFSET_Y, smokeParticle.transform.position.z);

                landParticle.SetActive(true);
                landParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y + BOSS_SMOKE_OFFSET_Y, landParticle.transform.position.z);
            }

            rotation = 0;
        }
        else if (state == BossState.SLIDE)
        {
            if (speedX > 0)
            {
                speedX   -= BOSS_SLIDE_FRICTION * dt;
                direction = 1;
                if (speedX < 0)
                {
                    speedX = 0;
                    SwitchState(BossState.RUN);
                    SCR_RunSound.Play();
                }
            }
            else
            {
                speedX   += BOSS_SLIDE_FRICTION * dt;
                direction = -1;
                if (speedX > 0)
                {
                    speedX = 0;
                    SwitchState(BossState.RUN);
                    SCR_RunSound.Play();
                }
            }

            smokeParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x + BOSS_SMOKE_OFFSET_X * direction, y + BOSS_SMOKE_OFFSET_Y, smokeParticle.transform.position.z);
            ParticleSystem.EmissionModule emission = smokeParticle.GetComponent <ParticleSystem>().emission;
            emission.rateOverTime = Mathf.Abs(speedX) * BOSS_SMOKE_RATE;

            x += speedX * dt;

            if (x <= -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                x         = -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                direction = 1;
                speedX    = -speedX;
            }
            else if (x >= (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                x         = (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X);
                direction = -1;
                speedX    = -speedX;
            }

            rotation = 0;
        }
        else if (state == BossState.RUN)
        {
            x       += direction * BOSS_RUN_SPEED * dt;
            rotation = 0;

            if (x <= -(SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                SCR_RunSound.Fade();
            }
            else if (x >= (SCR_Gameplay.SCREEN_W * 0.5f - BOSS_REVERSE_X))
            {
                SCR_RunSound.Fade();
            }
        }

        transform.position         = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y, transform.position.z);
        transform.localScale       = new Vector3(currentScale.x * (-direction), currentScale.y, currentScale.z);
        transform.localEulerAngles = new Vector3(0, 0, rotation);

        bossName.transform.localPosition = new Vector3(
            SCR_Gameplay.SCREEN_W * 0.5f + x,
            y + BOSS_NAME_OFFSET_Y * currentScale.x / originalScale.x,
            bossName.transform.localPosition.z);


        float shadowScale = 1 - (y - BOSS_START_Y) / BOSS_SHADOW_DISTANCE;

        if (shadowScale < 0)
        {
            shadowScale = 0;
        }
        shadow.transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, shadow.transform.position.y, shadow.transform.position.z);
        shadow.transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * BOSS_SCALE * shadowScale, SCR_Gameplay.SCREEN_SCALE * BOSS_SCALE * shadowScale, SCR_Gameplay.SCREEN_SCALE * BOSS_SCALE);

        for (int i = 0; i < 6; i++)
        {
            moneyParticle[i].transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y, moneyParticle[i].transform.position.z);
        }

        moneyBagParticle.transform.position = moneyParticle[0].transform.position;

        if (enlargeTime > 0)
        {
            enlargeTime -= dt;
            if (enlargeTime <= 0)
            {
                Shrink();
                enlargeTime = 0;
            }
            else if (enlargeTime < BOSS_FLASH_DURATION * 0.8f)
            {
                Flash();
            }
        }

        if (bubbleTime > 0)
        {
            bubbleTime -= dt;
            if (bubbleTime < BOSS_FLASH_DURATION * 0.8f)
            {
                Flash();
            }
        }
        else
        {
            bubble.GetComponent <SCR_Bubble>().FadeOut();
        }

        if (magnetTime > 0)
        {
            magnetTime -= dt;
            if (magnetTime < BOSS_FLASH_DURATION * 0.8f)
            {
                Flash();
            }
        }
        else
        {
            attract.GetComponent <SCR_Attract>().FadeOut();
        }



        if (state == BossState.TALK)
        {
            if (talkCounter < BOSS_TALK_START)
            {
                talkCounter += dt;
                if (talkCounter >= BOSS_TALK_START)
                {
                    SCR_Audio.PlayTalkSound();
                    dialogueID++;
                    if (dialogueID >= dialogue.Length)
                    {
                        dialogueID = 0;
                    }
                    talkBubble.transform.GetChild(0).GetChild(0).gameObject.GetComponent <Text>().text = dialogue[dialogueID];
                    talkBubble.SetActive(true);
                }
            }
            else
            {
                talkCounter += dt;
                if (talkCounter >= BOSS_TALK_END)
                {
                    talkBubble.SetActive(false);
                    talkCounter = 0;
                }
            }
        }
    }