Exemplo n.º 1
0
    public void reset()
    {
        if (collide == null)
        {
            collide = GetComponent <Collider2D>();
        }

        animator.enabled   = true;
        state              = State.Waiting;
        transform.position = initialPosition;
        head.GetComponent <Collider2D>().enabled = false;

        leftString.gameObject.SetActive(true);
        rightString.gameObject.SetActive(true);

        rigidThing.velocity     = Vector2.zero;
        rigidThing.gravityScale = 0f;
        rigidThing.isKinematic  = true;
        transform.rotation      = Quaternion.identity;

        target.reset();

        setSlingshotAngle(0f);

        backString.gameObject.SetActive(true);

        audio.pitch = audio.volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
        audio.Stop();
    }
Exemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (state == State.Flung && other.name == "Target")
        {
            target.rigidThing.isKinematic  = false;
            target.rigidThing.gravityScale = target.hitGravity;
            target.rigidThing.velocity     = target.hitVelocity;
            target.hit = true;
            target.hitParticles.Play();
            target.hitParticles.transform.parent = transform.parent;

            state = State.Broken;
            rigidThing.isKinematic  = false;
            rigidThing.velocity     = brokenVelocity * 1.5f;
            rigidThing.gravityScale = 0f;

            updateAudioPan();
            audio.volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
            audio.pitch  = Time.timeScale;
            audio.PlayOneShot(hitClip);

            CameraShake.instance.setScreenShake(hitShake);

            MicrogameController.instance.setVictory(true, true);
        }
    }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (dead == true)
     {
         if (isChenshadow == true)
         {
             chenAnimator.Play("ChenShadowExit");
         }
         else
         {
             chenAnimator.Play("ChenRIP");
             honkSource.pitch = Time.timeScale;
             MicrogameController.instance.setVictory(false, true);
             chenspeed.speed = 1;
             Destroy(disablecounter);
             if (check_for_light == true)
             {
                 camera_darken.enabled = true;
                 alt_light.enabled     = true;
                 light_system.enabled  = false;
             }
             if (audiocheck == true)
             {
                 float volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
                 if (volume > 0f)
                 {
                     honkSource.PlayOneShot(FailSound, volume);
                 }
                 audiocheck = false;
             }
         }
     }
 }
Exemplo n.º 4
0
 public void updateVolume()
 {
     for (int i = 0; i < sources.Length; i++)
     {
         sources[i].volume = initialVolumes[i] * PrefsHelper.getVolume(volumeType);
     }
     instanceVolumeSetting = PrefsHelper.getVolume(volumeType);
 }
Exemplo n.º 5
0
    public void onClick()
    {
        float volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);

        if (volume > 0f)
        {
            sfxSource.PlayOneShot(pressClip, volume);
        }
    }
Exemplo n.º 6
0
    public void spin()
    {
        _rigidBody.freezeRotation = true;
        _rigidBody.freezeRotation = false;
        _rigidBody.AddTorque(MathHelper.randomRangeFromVector(zoomRotateBounds) * (_rigidBody.velocity.x >= 0f ? -1f : 1f));

        sfxSource.volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
        sfxSource.PlayOneShot(hopClip);
    }
Exemplo n.º 7
0
    public void fling()
    {
        _rigidBody.velocity = MathHelper.getVector2FromAngle(zoomAngle, MathHelper.randomRangeFromVector(zoomSpeedBounds));

        sfxSource.volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
        sfxSource.PlayOneShot(zoomClip);
        hopping = false;
        hopAnimator.SetBool("Hop", hopping);
        clickCollider.enabled = true;
    }
Exemplo n.º 8
0
 void Update()
 {
     if (tieToTimescale && Time.timeScale != instanceTimeScale)
     {
         updatePitch();
     }
     if (tieToVolumeSettings && PrefsHelper.getVolume(volumeType) != instanceVolumeSetting)
     {
         updateVolume();
     }
 }
Exemplo n.º 9
0
    void LateUpdate()
    {
        if (!canStayActive())
        {
            _rigidBody.bodyType = RigidbodyType2D.Kinematic;
            Vector2 escapeVelocity = MathHelper.getVector2FromAngle(
                ((Vector2)(transform.position - Camera.main.transform.position)).getAngle(), escapeSpeed);
            transform.position += (Vector3)escapeVelocity * Time.deltaTime;
            if (CameraHelper.isObjectOffscreen(transform, 10f))
            {
                Destroy(gameObject);
            }
            return;
        }
        else if (!wallHitCollider.enabled && !CameraHelper.isObjectOffscreen(transform,
                                                                             -colliderExtent))
        {
            wallHitCollider.enabled = true;
        }

        if (lifetime > 0f)
        {
            lifetime -= Time.deltaTime;
            if (lifetime <= 0f)
            {
                setIgnoreWalls(true);
            }
        }

        if (lastVelocity != Vector2.zero)
        {
            sfxSource.panStereo = AudioHelper.getAudioPan(transform.position.x);
            if ((Mathf.Sign(_rigidBody.velocity.x) == -Mathf.Sign(lastVelocity.x)) ||
                (Mathf.Sign(_rigidBody.velocity.y) == -Mathf.Sign(lastVelocity.y)) ||
                Mathf.Abs(_rigidBody.velocity.magnitude - lastVelocity.magnitude) > bounceVolumeSpeedBounds.x)
            {
                float speed  = _rigidBody.velocity.magnitude;
                float volume = Mathf.Pow(Mathf.Lerp(.5f, 1f,
                                                    ((speed - bounceVolumeSpeedBounds.x) / (bounceVolumeSpeedBounds.y - bounceVolumeSpeedBounds.x))),
                                         1f);
                if (volume > .5f && PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX) > 0f && !float.IsNaN(volume))
                {
                    sfxSource.pitch = 1f;
                    sfxSource.PlayOneShot(bounceClip, volume);
                }
            }
        }
        lastVelocity = _rigidBody.velocity;

        if (CameraHelper.isObjectOffscreen(transform, 10f))
        {
            Destroy(gameObject);
        }
    }
Exemplo n.º 10
0
    void playBounceSound(float volume)
    {
        bounceSource.pitch = Time.timeScale * .85f;

        volume  = Mathf.Min(1f, volume);
        volume /= 2f;
        bounceSource.volume = volume * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);

        bounceSource.panStereo = getStereoPan();

        bounceSource.PlayOneShot(bounceClip);
    }
Exemplo n.º 11
0
    void updateTrace()
    {
        //Enable emmissions if mouse is held down
        ParticleSystem.EmissionModule emission = traceParticles.emission;
        emission.enabled    = Input.GetMouseButton(0);
        _audioSource.volume = Input.GetMouseButton(0) ? PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX) : 0f;

        if (!emission.enabled && Input.GetMouseButtonDown(0))
        {
            traceParticles.Emit(1); //When mouse is first pressed, create a particle (otherwise one won't be created before the player moves their cursor
        }
    }
Exemplo n.º 12
0
 void updateValue()
 {
     PrefsHelper.setVolume(type, slider.value);
     if (onChangeSource != null)
     {
         onChangeSource.Stop();
         if (queueChange)
         {
             onChangeSource.PlayOneShot(onChangeClip, PrefsHelper.getVolume(type));
         }
     }
     queueChange = false;
 }
Exemplo n.º 13
0
    private void manageEmissionSound()
    {
        if (inmunity)
        {
            burningSFX.volume = 0;
        }
        else
        {
            burningSFX.volume = (1 - HP) * 1.5f;
        }

        burningSFX.volume *= PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
    }
Exemplo n.º 14
0
    void Update()
    {
        float volumeScale = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);

        if (state != State.Default && volumeScale > 0f)
        {
            if (bubbleSource.volume / volumeScale > 0f)
            {
                bubbleSource.volume -= bubbleFadeSpeed * Time.deltaTime * volumeScale;
                bubbleSource.volume  = Mathf.Max(bubbleSource.volume, 0f) * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
            }
        }
        else if (!bubbleSource.isPlaying && MicrogameTimer.instance.beatsLeft <= 16f && MicrogameTimer.instance.beatsLeft >= 8f)
        {
            //bubbleSource.pitch = Time.timeScale;
            bubbleSource.Play();
        }
    }
Exemplo n.º 15
0
    void Update()
    {
        cup.Fill(Time.deltaTime);
        switch (state)
        {
        case MilkPourGameState.Stopped:
            if (animationSpeedMult.PourSpeedMult <= 0f)
            {
                OnMilkSettled();
                if (!failOnEarlyRelease)
                {
                    state = MilkPourGameState.Start;
                }
            }
            break;

        case MilkPourGameState.Start:
            state = Input.GetKey(KeyCode.Space) ? MilkPourGameState.Filling : MilkPourGameState.Start;
            if (state == MilkPourGameState.Filling)
            {
                OnFill();
                pourSource.Play();
            }
            break;

        case MilkPourGameState.Filling:
        case MilkPourGameState.Idle:
            state = Input.GetKey(KeyCode.Space) ? MilkPourGameState.Filling : MilkPourGameState.Idle;
            if (state == MilkPourGameState.Filling)
            {
                OnFill();
            }
            else
            {
                OnIdle();
            }
            break;
        }

        pourSource.volume = animationSpeedMult.PourSpeedMult * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
    }
Exemplo n.º 16
0
    void updateFade()
    {
        if (PrefsHelper.getVolume(type) <= 0f)
        {
            return;
        }

        float volumeMult = PrefsHelper.getVolume(type);
        float diff       = fadeSpeed * Time.deltaTime * volumeMult;

        if (fadeInFirst)
        {
            if (_audioSource.volume >= volumeMult)
            {
                _audioSource.volume = volumeMult;
                fadeInFirst         = started = false;
            }
            else
            {
                _audioSource.volume += diff;
            }
        }
        else
        {
            if (_audioSource.volume <= diff)
            {
                _audioSource.volume = 0f;
                //_audioSource.Stop();
                fadeInFirst = true;
                started     = false;
            }
            else
            {
                _audioSource.volume -= diff;
            }
        }
    }
Exemplo n.º 17
0
 void LateUpdate()
 {
     audioSource.volume = volumeMult * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
 }
Exemplo n.º 18
0
    void Update()
    {
        switch (state)
        {
        case (State.Waiting):
            if (Input.GetMouseButtonDown(0) && CameraHelper.isMouseOver(collide))
            {
                state = State.Grabbed;

                cursorOffset = (Vector2)transform.position - (Vector2)CameraHelper.getCursorPosition();
                snapToMouse();
                animator.enabled          = false;
                head.transform.localScale = initialScale;

                backString.gameObject.SetActive(false);

                audio.Play();
                audio.pitch = getStretchPitch();
                updateAudioPan();
            }
            break;

        case (State.Grabbed):
            Vector2 diff = (Vector2)initialPosition - (Vector2)transform.position;
            transform.rotation = Quaternion.Euler(0f, 0f,
                                                  .5f * diff.getAngle()
                                                  * Mathf.Lerp(0f, 1f, Mathf.Abs(diff.y))
                                                  * Mathf.Lerp(0f, 1f, diff.x));
            if (!Input.GetMouseButton(0))
            {
                audio.Stop();
                //audio.pitch = Time.timeScale;
                if (diff.magnitude > 0f)
                {
                    rigidThing.isKinematic  = false;
                    rigidThing.velocity     = diff * flingSpeedMult;
                    rigidThing.gravityScale = 0f;
                    state = State.Flinging;


                    updateAudioPan();
                    audio.pitch  -= .5f * Time.timeScale;
                    audio.volume  = (getStretchPitch() / Time.timeScale) - .75f;
                    audio.volume *= PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
                    audio.PlayOneShot(launchClip);

                    head.GetComponent <Vibrate>().vibrateOn = false;
                }
                else
                {
                    state            = State.Waiting;
                    animator.enabled = true;
                }
            }
            else
            {
                snapToMouse();
                audio.pitch = getStretchPitch();
                updateAudioPan();
                if (transform.position.x > 3.3f)
                {
                    state = State.Broken;
                    rigidThing.isKinematic  = false;
                    rigidThing.velocity     = brokenVelocity;
                    rigidThing.gravityScale = brokenGravity;
                    MicrogameController.instance.setVictory(false, true);

                    audio.Stop();

                    updateAudioPan();
                    audio.volume = PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
                    audio.pitch  = Time.timeScale;
                    audio.PlayOneShot(breakClip);
                }
            }
            tiltSlingShot();
            break;

        case (State.Flinging):
            Vector2 originDiff = (Vector2)initialPosition - (Vector2)transform.position;
            tiltSlingShot();

            if (originDiff.magnitude < rigidThing.velocity.magnitude * 1.5f * Time.deltaTime)
            {
                leftString.gameObject.SetActive(false);
                rightString.gameObject.SetActive(false);
                rigidThing.gravityScale = flingGravity;
                state = State.Flung;
                setSlingshotAngle(0f);

                backString.gameObject.SetActive(true);
            }
            //transform.Translate((Vector3)MathHelper.getVectorFromAngle(flingAngle, flingSpeed * Time.deltaTime));
            break;

        case (State.Flung):
            updateAudioPan();
            if (!MicrogameController.instance.getVictory() && rigidThing.velocity.x > 0f)
            {
                transform.rotation = Quaternion.Euler(0f, 0f, rigidThing.velocity.getAngle() * .5f);
            }

            if (transform.position.x > lossX || (rigidThing.velocity.y < 0f && transform.position.y < lossY))
            {
                MicrogameController.instance.getTraits().failureVoiceDelay = 0f;
                MicrogameController.instance.setVictory(false, true);
                enabled = false;
            }
            break;

        case (State.Broken):
            rigidThing.MoveRotation(rigidThing.rotation + (brokenRotateSpeed * 5f * Time.deltaTime));
            break;

        default:
            break;
        }
    }
Exemplo n.º 19
0
    void Update()
    {
        float deltaCompletion = 0;

        // Check if the handle has been grabbed.
        if (canMove && guide.grabbed)
        {
            // Get the points at the centre of the crank and the centre of the mouse guide.
            Vector3 targetPoint = MainCameraSingleton.instance.WorldToScreenPoint(guide.transform.position);
            Vector3 crankPoint  = MainCameraSingleton.instance.WorldToScreenPoint(crank.transform.position);

            // Calculate direction of the mouse from the crank.
            Vector2 offset = new Vector2(targetPoint.x - crankPoint.x, targetPoint.y - crankPoint.y);
            float   angle  = Mathf.Atan2(offset.y, offset.x) * Mathf.Rad2Deg;
            if (angle < 0)
            {
                angle = (180 - Mathf.Abs(angle)) + 180;
            }

            // Calculate angle change from previous.
            float currentAngle = GetCurrentAngle();
            float deltaAngle   = angle - (currentAngle % 360);
            if (deltaAngle > 180)
            {
                deltaAngle = deltaAngle - 360;
            }
            else if (deltaAngle < -180)
            {
                deltaAngle = deltaAngle + 360;
            }

            // Limit change.
            if (deltaAngle > turnLimit)
            {
                deltaAngle = turnLimit;
            }
            else if (deltaAngle < -turnLimit)
            {
                deltaAngle = -turnLimit;
            }

            // Determine target angle.
            float targetAngle = currentAngle + deltaAngle;
            if (targetAngle < minAngle)
            {
                targetAngle = minAngle;
            }
            else if (targetAngle > maxAngle)
            {
                targetAngle = maxAngle;
            }
            cranker.Rotate(targetAngle);

            // Calculate the new completion amount for the whole machine.
            deltaCompletion = ((targetAngle - minAngle) / reach) - completion;
            // Constrain based on time and max speed.
            deltaCompletion = deltaCompletion * Time.deltaTime * maxSpeed;

            float newCompletion = completion + deltaCompletion;
            if (newCompletion > 1F)
            {
                newCompletion = 1F;
            }
            else if (newCompletion < 0F)
            {
                newCompletion = 0F;
            }

            // Set completion.
            completion = newCompletion;

            // Move the machine.
            MoveMechanism();
        }
        else
        {
            // Make sure the guide remains on the handle when not in use.
            ResetGuide();
        }

        if (canMove && !guide.grabbed)
        {
            indicatorMovement.enabled = true;
        }
        else
        {
            indicatorMovement.enabled = false;
        }

        // Play sound
        float speed = Mathf.Abs(deltaCompletion / Time.deltaTime);

        if (Mathf.Abs(deltaCompletion) > 0.0001)
        {
            // Reset
            soundLinger = maxSoundLinger;

            // Volume/pitch control
            crankSound.volume = (soundLinger / maxSoundLinger) * speed * 3
                                * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX);
            crankSound.pitch = speed + 0.8F;

            // Play
            if (!crankSound.isPlaying)
            {
                crankSound.Play();
            }
        }
        else
        {
            // Decay
            soundLinger -= Time.deltaTime;

            // Volume/pitch control
            float newVolume = soundLinger / maxSoundLinger;
            crankSound.volume = newVolume;

            // Pause
            if (soundLinger <= 0)
            {
                crankSound.Pause();
            }
        }
    }
Exemplo n.º 20
0
 /// <summary>
 /// Plays sound effect unaffected by microgame speed
 /// </summary>
 /// <param name="clip"></param>
 /// <param name="panStereo"></param>
 /// <param name="pitch"></param>
 /// <param name="volume"></param>
 public void playSFXUnscaled(AudioClip clip, float panStereo = 0f, float pitch = 1f, float volume = 1f)
 {
     sfxSource.pitch     = pitch;
     sfxSource.panStereo = panStereo;
     sfxSource.PlayOneShot(clip, volume * PrefsHelper.getVolume(PrefsHelper.VolumeType.SFX));
 }