2022-02-09 03:58:25 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-02-10 11:59:20 +00:00
|
|
|
using System;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_RhythmTweezers
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
|
|
|
public class Tweezers : MonoBehaviour
|
|
|
|
{
|
|
|
|
public int hitOnFrame;
|
2022-02-10 11:59:20 +00:00
|
|
|
[NonSerialized] public Animator anim;
|
2022-02-09 06:52:50 +00:00
|
|
|
private Animator vegetableAnim;
|
2022-02-10 08:13:54 +00:00
|
|
|
private RhythmTweezers game;
|
2022-02-10 15:29:53 +00:00
|
|
|
private bool pluckingThisFrame;
|
|
|
|
private bool holdingHair;
|
|
|
|
public SpriteRenderer heldHairSprite;
|
2022-02-11 07:21:43 +00:00
|
|
|
public Transform tweezerSpriteTrans;
|
2022-02-09 03:58:25 +00:00
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
|
|
|
anim = GetComponent<Animator>();
|
2022-02-09 06:52:50 +00:00
|
|
|
vegetableAnim = RhythmTweezers.instance.VegetableAnimator;
|
2022-02-10 08:13:54 +00:00
|
|
|
|
|
|
|
game = RhythmTweezers.instance;
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
{
|
2022-02-22 05:43:31 +00:00
|
|
|
if (PlayerInput.Pressed(true))
|
2022-02-09 03:58:25 +00:00
|
|
|
{
|
2022-02-10 15:29:53 +00:00
|
|
|
if (!pluckingThisFrame) // Did you do a successful pluck earlier in the frame?
|
2022-02-10 11:59:20 +00:00
|
|
|
{
|
2022-02-10 15:29:53 +00:00
|
|
|
DropHeldHair();
|
2022-02-10 11:59:20 +00:00
|
|
|
anim.Play("Tweezers_Pluck", 0, 0);
|
|
|
|
}
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
2022-02-10 11:59:20 +00:00
|
|
|
|
2022-02-10 15:29:53 +00:00
|
|
|
pluckingThisFrame = false;
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Pluck(bool ace, Hair hair)
|
|
|
|
{
|
2022-02-10 15:29:53 +00:00
|
|
|
DropHeldHair();
|
|
|
|
|
2022-02-09 03:58:25 +00:00
|
|
|
if (ace)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
|
2022-02-10 11:59:20 +00:00
|
|
|
|
|
|
|
hair.hairSprite.SetActive(false);
|
|
|
|
hair.stubbleSprite.SetActive(true);
|
2022-02-09 10:29:09 +00:00
|
|
|
|
|
|
|
game.hairsLeft--;
|
2022-02-10 15:29:53 +00:00
|
|
|
game.eyeSize = Mathf.Clamp(game.eyeSize + 1, 0, 10);
|
2022-02-09 10:29:09 +00:00
|
|
|
|
|
|
|
if (game.hairsLeft <= 0)
|
|
|
|
vegetableAnim.Play("HopFinal", 0, 0);
|
|
|
|
else
|
2022-02-10 15:29:53 +00:00
|
|
|
vegetableAnim.Play("Hop" + game.eyeSize.ToString(), 0, 0);
|
2022-02-10 11:59:20 +00:00
|
|
|
|
|
|
|
anim.Play("Tweezers_Pluck_Success", 0, 0);
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
2022-02-10 11:59:20 +00:00
|
|
|
else
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
|
|
|
|
SoundByte.PlayOneShot("miss");
|
2022-02-10 11:59:20 +00:00
|
|
|
|
|
|
|
hair.hairSprite.SetActive(false);
|
|
|
|
hair.missedSprite.SetActive(true);
|
|
|
|
|
|
|
|
vegetableAnim.Play("Blink", 0, 0);
|
|
|
|
|
|
|
|
anim.Play("Tweezers_Pluck_Fail", 0, 0);
|
|
|
|
}
|
|
|
|
|
2022-02-10 15:29:53 +00:00
|
|
|
pluckingThisFrame = true; // Prevents standard pluck from playing in LateUpdate().
|
|
|
|
holdingHair = true;
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
2022-02-10 08:13:54 +00:00
|
|
|
|
|
|
|
public void LongPluck(bool ace, LongHair hair)
|
|
|
|
{
|
2022-02-11 02:14:09 +00:00
|
|
|
DropHeldHair();
|
2022-02-10 08:13:54 +00:00
|
|
|
|
|
|
|
if (ace)
|
|
|
|
{
|
2023-06-10 19:17:06 +00:00
|
|
|
SoundByte.PlayOneShotGame("rhythmTweezers/longPullEnd");
|
2022-02-11 07:21:43 +00:00
|
|
|
|
2022-02-11 02:14:09 +00:00
|
|
|
hair.hairSprite.SetActive(false);
|
|
|
|
hair.stubbleSprite.SetActive(true);
|
2022-02-11 07:21:43 +00:00
|
|
|
// Making transparent instead of disabling because animators are silly.
|
|
|
|
hair.loop.GetComponent<SpriteRenderer>().color = Color.clear;
|
2022-02-11 02:14:09 +00:00
|
|
|
|
|
|
|
game.hairsLeft--;
|
|
|
|
game.eyeSize = Mathf.Clamp(game.eyeSize + 1, 0, 10);
|
2022-02-10 08:13:54 +00:00
|
|
|
|
2022-02-11 02:14:09 +00:00
|
|
|
if (game.hairsLeft <= 0)
|
|
|
|
vegetableAnim.Play("HopFinal", 0, 0);
|
|
|
|
else
|
|
|
|
vegetableAnim.Play("Hop" + game.eyeSize.ToString(), 0, 0);
|
|
|
|
|
|
|
|
anim.Play("Tweezers_Pluck_Success", 0, 0);
|
2022-02-10 08:13:54 +00:00
|
|
|
}
|
2022-02-11 02:14:09 +00:00
|
|
|
|
|
|
|
pluckingThisFrame = true;
|
|
|
|
holdingHair = true;
|
2022-02-10 08:13:54 +00:00
|
|
|
}
|
2022-02-10 15:29:53 +00:00
|
|
|
|
|
|
|
public void DropHeldHair()
|
|
|
|
{
|
|
|
|
if (!holdingHair) return;
|
|
|
|
|
|
|
|
var droppedHair = GameObject.Instantiate(game.pluckedHairBase, game.DroppedHairsHolder.transform).GetComponent<SpriteRenderer>();
|
|
|
|
droppedHair.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
droppedHair.transform.position = heldHairSprite.transform.position;
|
|
|
|
droppedHair.transform.rotation = heldHairSprite.transform.rotation;
|
|
|
|
|
|
|
|
droppedHair.sprite = heldHairSprite.sprite;
|
|
|
|
|
|
|
|
// Make the hair spin.
|
|
|
|
// (The prefab has a Rigidbody2D component already so that it falls)
|
2022-02-11 02:14:09 +00:00
|
|
|
droppedHair.GetComponent<Rigidbody2D>().interpolation = RigidbodyInterpolation2D.Interpolate;
|
2022-02-10 15:29:53 +00:00
|
|
|
droppedHair.GetComponent<Rigidbody2D>().angularVelocity = UnityEngine.Random.Range(-120f, 120f);
|
|
|
|
|
|
|
|
holdingHair = false;
|
|
|
|
}
|
2022-02-09 03:58:25 +00:00
|
|
|
}
|
|
|
|
}
|