Tweezers: Hairs fall after being plucked. Eye growing implemented.

This commit is contained in:
Jenny Crowe
2022-02-10 08:29:53 -07:00
parent 9977c8e524
commit 5dba944412
29 changed files with 11517 additions and 30 deletions

View File

@ -13,7 +13,9 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
[NonSerialized] public Animator anim;
private Animator vegetableAnim;
private RhythmTweezers game;
private bool plucking;
private bool pluckingThisFrame;
private bool holdingHair;
public SpriteRenderer heldHairSprite;
private void Start()
{
@ -27,17 +29,20 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
{
if (PlayerInput.Pressed())
{
if (!plucking) // Did you do a successful pluck earlier in the frame?
if (!pluckingThisFrame) // Did you do a successful pluck earlier in the frame?
{
DropHeldHair();
anim.Play("Tweezers_Pluck", 0, 0);
}
}
plucking = false;
pluckingThisFrame = false;
}
public void Pluck(bool ace, Hair hair)
{
DropHeldHair();
if (ace)
{
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
@ -46,11 +51,12 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
hair.stubbleSprite.SetActive(true);
game.hairsLeft--;
game.eyeSize = Mathf.Clamp(game.eyeSize + 1, 0, 10);
if (game.hairsLeft <= 0)
vegetableAnim.Play("HopFinal", 0, 0);
else
vegetableAnim.Play("Hop", 0, 0);
vegetableAnim.Play("Hop" + game.eyeSize.ToString(), 0, 0);
anim.Play("Tweezers_Pluck_Success", 0, 0);
}
@ -67,7 +73,8 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
anim.Play("Tweezers_Pluck_Fail", 0, 0);
}
plucking = true; // Prevents standard pluck from playing in LateUpdate().
pluckingThisFrame = true; // Prevents standard pluck from playing in LateUpdate().
holdingHair = true;
}
public void LongPluck(bool ace, LongHair hair)
@ -88,5 +95,24 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
Destroy(hair.gameObject);
}
}
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)
droppedHair.GetComponent<Rigidbody2D>().angularVelocity = UnityEngine.Random.Range(-120f, 120f);
holdingHair = false;
}
}
}