Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        float angle = transform.rotation.eulerAngles.z;

        if (isTurn && !isAir)
        {
            // TODO : GetKeyDown will be changed GetKey
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                if (angle < 285 && angle >= 270 || wallDirection == 1 || tankData.m_iRemainMove <= 0)
                {
                }
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                if (angle > 75 && angle <= 90 || wallDirection == 2 || tankData.m_iRemainMove <= 0)
                {
                    audio.Stop();
                    audio.clip = tankData.m_audioClips[clip_move + 1];
                    audio.loop = false;
                    audio.Play(0);
                }
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                if (renderer.flipX == true)
                {
                    renderer.flipX = false;
                }

                if (angle < 285 && angle >= 270 || wallDirection == 1 || tankData.m_iRemainMove <= 0)
                {
                    if (audio.clip != tankData.m_audioClips[clip_move + 1])
                    {
                        audio.Stop();
                        audio.clip = tankData.m_audioClips[clip_move + 1];
                        audio.loop = false;
                        audio.Play(0);
                    }
                    return;
                }

                float remainGauge = (float)(--tankData.m_iRemainMove) / tankData.m_iMaxMove * smallGaugeWidth;
                SetGaugeFill(moveGauge.transform.Find("Fill").GetComponent <RectTransform>(), remainGauge);
                transform.Translate(new Vector3(-Time.deltaTime * moveSpeed, 0, 0), Space.Self);
                CalculateAngle();
                cameraController.FollowCamera(transform.position);

                if (audio.clip != tankData.m_audioClips[clip_move])
                {
                    audio.Stop();
                    audio.clip = tankData.m_audioClips[clip_move];
                    audio.loop = true;
                    audio.Play(0);
                }
            }
            else if (Input.GetKey(KeyCode.RightArrow))
            {
                if (renderer.flipX == false)
                {
                    renderer.flipX = true;
                }

                if (angle > 75 && angle <= 90 || wallDirection == 2 || tankData.m_iRemainMove <= 0)
                {
                    if (audio.clip != tankData.m_audioClips[clip_move + 1])
                    {
                        audio.Stop();
                        audio.clip = tankData.m_audioClips[clip_move + 1];
                        audio.loop = false;
                        audio.Play(0);
                    }
                    return;
                }

                float remainGauge = (float)(--tankData.m_iRemainMove) / tankData.m_iMaxMove * smallGaugeWidth;
                SetGaugeFill(moveGauge.transform.Find("Fill").GetComponent <RectTransform>(), remainGauge);
                transform.Translate(new Vector3(Time.deltaTime * moveSpeed, 0, 0), Space.Self);
                CalculateAngle();
                cameraController.FollowCamera(transform.position);

                if (audio.clip != tankData.m_audioClips[clip_move])
                {
                    audio.Stop();
                    audio.clip = tankData.m_audioClips[clip_move];
                    audio.loop = true;
                    audio.Play(0);
                }
            }
            else
            {
                if (audio.clip)
                {
                    audio.Stop();
                    audio.clip = null;
                }
            }
            if (Input.GetKey(KeyCode.UpArrow))
            {
                if (tankData.m_iCurrentAngle >= tankData.m_iMaxAngle)
                {
                    return;
                }

                // angle change sound
                tankData.m_iCurrentAngle++;
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                if (tankData.m_iCurrentAngle <= tankData.m_iMinAngle)
                {
                    return;
                }

                // angle change sound
                tankData.m_iCurrentAngle--;
            }
            if (Input.GetKey(KeyCode.Space))
            {
                RectTransform fill    = powerGauge.transform.Find("Fill").GetComponent <RectTransform>();
                int           current = tankData.m_iShootingValue;
                if (tankData.m_isShooting == false)
                {
                    tankData.m_isShooting     = true;
                    tankData.m_iShootingValue = 0;

                    RectTransform lastFill = powerGauge.transform.Find("LastFill").GetComponent <RectTransform>();
                    float         gauge    = fill.sizeDelta.x;
                    if (gauge > 40)
                    {
                        SetGaugeFill(lastFill, gauge);
                    }
                    else
                    {
                        SetGaugeFill(lastFill, fill.GetComponent <Image>().fillAmount * 40);
                    }
                }
                else
                {
                    if (++current > maxPower)
                    {
                        current = maxPower;
                    }

                    tankData.m_iShootingValue = current;
                    SetGaugeFill(fill, current * bigGaugeWidth / maxPower);
                }
            }
            else
            {
                if (tankData.m_isShooting)
                {
                    tankData.m_isShooting = false;
                    isTurn = false;
                    // shoot bomb
                    Tool.EmitWeaponSound(tankData.m_audioClips[clip_fire + tankData.m_iBombType]);

                    cameraController.StopCameraSmoothMove();

                    float shootAngle = (renderer.flipX ? angle + tankData.m_iCurrentAngle : 180 + angle - tankData.m_iCurrentAngle);
                    Bomb  bomb       = Bomb.Create(collider.bounds.center, shootAngle, tankData.m_iShootingValue, tankData.m_audioClips[clip_bomb + tankData.m_iBombType], (renderer.flipX ? 1 : -1));
                    bomb.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Images/UI/Weapons/" + tankData.GetTankPath() + "/" + tankData.m_iBombType);

                    bomb.radius = tankData.m_iBombRadius[tankData.m_iBombType];
                    bomb.remain = tankData.m_iBombCount[tankData.m_iBombType];
                    cameraController.FollowCamera(bomb.transform.position, true);

                    RectTransform lastFill = powerGauge.transform.Find("LastFill").GetComponent <RectTransform>();
                    SetGaugeFill(lastFill, 0);
                }
            }
        }
        if (transform.position.y <= 0)
        {
            tankData.m_isDeadTank = true;
            if (isTurn)
            {
                TankController tank = GameDirector.GetNextTank();
                if (tank)
                {
                    tank.NextTurn(1);
                }
                else
                {
                    // Game End
                }

                audio.Stop();
                isTurn = false;
            }
            //gameObject.SetActive(false);
            renderer.color = new Color(1, 1, 1, 0);
            return;
        }

        int groundHeight = groundController.GetGroundHeight(transform.position);

        if (groundHeight == int.MinValue)
        {
            Debug.Log("can't get ground height " + transform.position);
            return;
        }
        // 움직이다가 땅속으로 빠지는것 방지
        if (!isAir && groundHeight < -2 && !((angle > 89 && angle < 91) || (angle > 269 && angle < 271)))
        {
            transform.Translate(new Vector3(0, 0.0125f * -groundHeight), Space.World);
            groundHeight = groundController.GetGroundHeight(transform.position);
        }
        if (groundHeight > 0)
        {
            if (groundHeight > 30)
            {
                cameraController.FollowCamera(transform.position);

                // angle reset
                transform.rotation = Quaternion.Euler(new Vector3());
                audio.Stop();
            }
            else
            {
                CalculateAngle();
            }
            float maxDropHeight = (float)groundHeight / 80 * -1;
            transform.Translate(new Vector3(0, Mathf.Max(maxDropHeight, -Time.deltaTime * dropSpeed), 0), Space.World);
            //transform.position = new Vector3(transform.position.x, (float)((int)(transform.position.y * 80)) / 80);

            isAir = true;
            return;
        }

        if (isAir)
        {
            CalculateAngle();
        }
    }