示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.y > 0.65f && _curWhaleState == WhaleState.Climbing)
        {
            _curWhaleState = WhaleState.Breathing;
            _curBreathTime = 0f;
        }

        if (_curBreathTime > MaxBreathTime && _curWhaleState == WhaleState.Breathing)
        {
            _curWhaleState = WhaleState.Diving;
            //Debug.Log("Breathing");
            //start particle effect
            GetComponentInChildren<ParticleSystem>().Play();
        }

        if (_curWhaleState == WhaleState.Breathing && _curBreathTime < MaxBreathTime)
        {
            _curBreathTime += Time.deltaTime;
            return;
        }

        if (_curWhaleState == WhaleState.Diving && transform.position.y < 0.1f)
        {
            Destroy(gameObject);
        }

        _curAngle += RotateSpeed * Time.deltaTime;
        float curSin = Mathf.Sin(_curAngle * Frequency);
        transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, curSin * Magnitude);
        transform.position += Time.deltaTime * MoveSpeed * transform.right;
    }
示例#2
0
 void OnTriggerExit(Collider col)
 {
     if (col.CompareTag("Ocean"))
     {
         InWater       = false;
         State         = WhaleState.AIRBORNE;
         rb.useGravity = true;
     }
 }
示例#3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (GameController.GameOver)
        {
            State = WhaleState.POSTGAME;
        }
        switch (State)
        {
        case WhaleState.MOVE:
            RotateWhaleDirection();
            MoveWhale(MoveSpeed);
            if (Input.GetMouseButtonDown(0))    //left mouse
            {
                Dash();
            }
            break;

        case WhaleState.DASH:
            DashWhale(DashSpeed * DashVelocityCurve.Evaluate(DashTimer / DashDuration));
            if (DashTimer < DashDuration)
            {
                DashTimer += Time.deltaTime;
            }
            else
            {
                State = WhaleState.MOVE;
            }
            break;

        case WhaleState.DEAD:
            break;

        case WhaleState.AIRBORNE:
            RotateWhaleDirection();
            rb.AddForce(Vector3.down * 4, ForceMode.Acceleration);
            break;

        case WhaleState.POSTGAME:
            rb.velocity *= 0.9f;
            break;

        case WhaleState.STOPPED:
            if (StoppedTimer > 0)
            {
                StoppedTimer -= Time.deltaTime;
            }
            else
            {
                State = WhaleState.MOVE;
            }
            RotateWhaleDirection();
            break;
        }
        KeepWhaleUpright();
    }
示例#4
0
 void Awake()
 {
     Source       = GetComponent <AudioSource>();
     MainCam      = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
     rb           = GetComponent <Rigidbody>();
     State        = WhaleState.MOVE;
     DashTimer    = DashDuration;
     XRotation    = transform.rotation.eulerAngles.x;
     MaxSpeed     = MoveSpeed;
     StoppedTimer = 0;
 }
示例#5
0
    // Use this for initialization
    void Start()
    {
        audio = GameObject.Find("WhaleNoises").GetComponent <AudioSource> ();
        GetComponent <TrailRenderer> ().enabled = false;
        body         = GetComponent <Rigidbody2D> ();
        state        = WhaleState.Sitting;
        timeAllotted = 0;
        currentAngle = 0;
        isPastCoast  = false;

        EventBroadcaster.broadcastEvent(new WhaleSpawned());
    }
示例#6
0
 void OnTriggerStay(Collider col)
 {
     if (col.CompareTag("Ocean"))
     {
         InWater       = true;
         rb.useGravity = false;
         if (State == WhaleState.AIRBORNE)
         {
             StartCoroutine(SpawnSplashPrefab(.05f));
             if (transform.rotation.eulerAngles.z > 268 && transform.rotation.eulerAngles.z < 330)
             {
                 StopWhaleTemporarily(LandInWaterParalysisDuration);
             }
             else
             {
                 State = WhaleState.MOVE;
             }
         }
     }
 }
示例#7
0
        public override string GetNextLine()
        {
            string line = null;

            switch (state)
            {
            case WhaleState.INTRO_2:
                AudioSource.PlayClipAtPoint(clip, new Vector3(0, 0, 0));
                state = WhaleState.INTRO_3;
                line  = "Ah, hello my faithful little companion. Ummmm... What was your name again?";
                break;

            case WhaleState.INTRO_3:
                state = WhaleState.INTRO_4;
                line  = "Right then, Small Fry. I have chosen you for a very important task! Huehuehuehue";
                break;

            case WhaleState.INTRO_4:
                state = WhaleState.INTRO_5;
                line  = "I need you to go up to Cheesecake Island as an emissary of our people, and make contact with the bird king!";
                break;

            case WhaleState.INTRO_5:
                state = WhaleState.CLOSE;
                line  = "...Well, off you go then! Good luck!!! Huehuehuehuehue";
                break;

            case WhaleState.CLOSE:
                GlobalState.instance.talkedToWhale = true;
                state = WhaleState.RAND_1_PREP;
                line  = null;
                SceneManager.LoadScene("Comic");
                break;
            }
            return(line);
        }
示例#8
0
 // Use this for initialization
 void Start()
 {
     state = WhaleState.INTRO_2;
 }
示例#9
0
 private void StopWhaleTemporarily(float duration)
 {
     StoppedTimer = duration;
     State        = WhaleState.STOPPED;
 }
示例#10
0
 private void Dash()
 {
     DashTimer = 0;
     State     = WhaleState.DASH;
     Source.PlayOneShot(DashSound);
 }
示例#11
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (Input.GetKeyDown(KeyCode.Space) && state == WhaleState.Sitting)
        {
            state      = WhaleState.Moving;
            audio.clip = SwimNoise;
            audio.Play();

            if (!userBegunInput)
            {
                EventBroadcaster.broadcastEvent(new WhaleMovedFirst());
                userBegunInput = true;
            }
        }
        if (Input.GetKeyUp(KeyCode.Space) && state == WhaleState.Moving)
        {
            state      = WhaleState.Jump1;
            audio.clip = JumpNoise;
            audio.Play();
        }
        if (isPastCoast && (state == WhaleState.Moving || state == WhaleState.Sitting))
        {
            GetComponent <SpriteRenderer> ().color = new Color(255, 255, 255);
            audio.clip = SkidNoise;
            audio.Play();
            state = WhaleState.Jump2;
        }
        switch (state)
        {
        case WhaleState.Moving:
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                currentAngle -= Time.deltaTime * 4;
                spriteAngle  += Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                currentAngle += Time.deltaTime * 4;
                spriteAngle  -= Time.deltaTime;
            }
            transform.Rotate(Vector3.forward * spriteAngle);
            body.AddForce(new Vector2(currentAngle, 5));

            break;

        case WhaleState.Jump1:
            GetComponent <SpriteRenderer> ().sprite = FirstJump;
            GetComponent <SpriteRenderer> ().color  = new Color(255, 255, 255);
            timeAllotted += Time.deltaTime;
            if (timeAllotted >= 1)
            {
                audio.clip = SkidNoise;
                audio.Play();
                if (isPastCoast)
                {
                    state = WhaleState.Jump2;
                }
                else
                {
                    timeAllotted = 0;
                    GetComponent <SpriteRenderer> ().sprite = Swimming;
                    GetComponent <SpriteRenderer> ().color  = new Color(255, 255, 255);
                    state = WhaleState.Sitting;
                }
            }
            break;

        case WhaleState.Jump2:
            GetComponent <SpriteRenderer> ().sprite          = SecondJump;
            GetComponent <TrailRenderer> ().enabled          = true;
            GetComponent <TrailRenderer> ().sortingLayerName = "Whale";
            GetComponent <TrailRenderer> ().sortingOrder     = 0;
            var            circlePosition2 = new Vector2(transform.position.x, transform.position.y);
            RaycastHit2D[] people2         = Physics2D.CircleCastAll(circlePosition2, 3.0f, Vector2.up, 1.5f);
            foreach (RaycastHit2D person in people2)
            {
                var personPosition2 = person.point;
                var power2          = personPosition2 - circlePosition2;
                power2.Normalize();
                power2 *= Random.Range(0, 10);
                if (person.rigidbody != null)
                {
                    var s = person.rigidbody.gameObject.GetComponent <PeopleState> ();
                    if (s != null)
                    {
                        s.Alive = false;
                    }
                    else if (person.rigidbody.gameObject.tag == "prop")
                    {
                        Destroy(person.rigidbody.gameObject);
                    }
                }
            }
            body.drag     = 3.0f;
            audio.volume -= Time.deltaTime;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                state        = WhaleState.Bloat;
                audio.volume = 1.0f;
                audio.clip   = FartNoise;
                audio.Play();
            }
            break;

        case WhaleState.Bloat:
            GetComponent <SpriteRenderer> ().sprite = Bloated;
            timeAllotted += Time.deltaTime;
            if (timeAllotted >= 3.0)
            {
                audio.Stop();
                audio.clip = ExplosionNoise;
                audio.Play();
                state = WhaleState.Death;
            }
            break;

        case WhaleState.Death:
            GetComponent <SpriteRenderer> ().sprite = DeadChunks;
            GetComponent <Explodable> ().explode();
            Instantiate(CraterPrefab, transform.position, Quaternion.identity);
            var            circlePosition = new Vector2(transform.position.x, transform.position.y);
            RaycastHit2D[] people         = Physics2D.CircleCastAll(circlePosition, 7.5f, Vector2.up, 2.0f);
            foreach (RaycastHit2D person in people)
            {
                var personPosition = person.point;
                var power          = personPosition - circlePosition;
                power.Normalize();
                power *= Random.Range(0, 20);
                if (person.rigidbody != null)
                {
                    person.rigidbody.AddForce(power, ForceMode2D.Impulse);
                    var s = person.rigidbody.gameObject.GetComponent <PeopleState> ();
                    if (s != null)
                    {
                        s.Alive = false;
                    }
                    else if (person.rigidbody.gameObject.tag == "prop")
                    {
                        Destroy(person.rigidbody.gameObject);
                    }
                }
            }
            //body.AddForce (new Vector2 (100, 100), ForceMode2D.Impulse);
            state = WhaleState.Done;
            EventBroadcaster.broadcastEvent(new WhaleHasDiedEvent());
            break;
        }
    }