Tweezers: Plucking animation additions. Autoplay support.

This commit is contained in:
Jenny Crowe
2022-02-10 04:59:20 -07:00
parent 7ee19eb3ad
commit c9ac1608e2
21 changed files with 4253 additions and 91 deletions

View File

@ -166,6 +166,11 @@ namespace RhythmHeavenMania
return a;
}
public float GetPositionFromMargin(float targetBeat, float margin)
{
return GetPositionFromBeat(targetBeat - margin, margin);
}
public float GetSongPosFromBeat(float beat)
{
return secPerBeat * beat;

View File

@ -1,14 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace RhythmHeavenMania.Games.RhythmTweezers
{
public class Hair : PlayerActionObject
{
public float createBeat;
public GameObject hairSprite;
public GameObject stubbleSprite;
public GameObject missedSprite;
private RhythmTweezers game;
private Tweezers tweezers;
private bool plucked;
private void Awake()
{
@ -18,23 +23,41 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
private void Update()
{
float stateBeat = Conductor.instance.GetPositionFromBeat(createBeat + game.tweezerBeatOffset, game.beatInterval);
if (plucked) return;
float stateBeat = Conductor.instance.GetPositionFromMargin(createBeat + game.tweezerBeatOffset + game.beatInterval, 1f);
StateCheck(stateBeat);
if (PlayerInput.Pressed() && tweezers.hitOnFrame == 0)
if (PlayerInput.Pressed())
{
if (state.perfect)
{
Ace();
}
else if (state.notPerfect())
{
Miss();
}
}
}
public void Ace()
{
tweezers.Pluck(true, this);
tweezers.hitOnFrame++;
plucked = true;
}
public void Miss()
{
tweezers.Pluck(false, this);
tweezers.hitOnFrame++;
plucked = true;
}
public override void OnAce()
{
Ace();
}
}
}

View File

@ -150,7 +150,7 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
foreach (Transform t in HairsHolder.transform)
{
var go = t.gameObject;
if (go != hairBase)
if (go != hairBase && go != longHairBase)
{
GameObject.Destroy(go);
}

View File

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using RhythmHeavenMania.Util;
@ -9,9 +10,10 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
public class Tweezers : MonoBehaviour
{
public int hitOnFrame;
private Animator anim;
[NonSerialized] public Animator anim;
private Animator vegetableAnim;
private RhythmTweezers game;
private bool plucking;
private void Start()
{
@ -25,21 +27,23 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
{
if (PlayerInput.Pressed())
{
hitOnFrame = 0;
if (!plucking) // Did you do a successful pluck earlier in the frame?
{
anim.Play("Tweezers_Pluck", 0, 0);
}
}
plucking = false;
}
public void Pluck(bool ace, Hair hair)
{
anim.Play("Tweezers_Pluck", 0, 0);
if (hitOnFrame > 0) return;
// tweezer pluck anim here
if (ace)
{
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{Random.Range(1, 21)}");
Destroy(hair.gameObject);
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
hair.hairSprite.SetActive(false);
hair.stubbleSprite.SetActive(true);
game.hairsLeft--;
@ -47,7 +51,23 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
vegetableAnim.Play("HopFinal", 0, 0);
else
vegetableAnim.Play("Hop", 0, 0);
anim.Play("Tweezers_Pluck_Success", 0, 0);
}
else
{
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
Jukebox.PlayOneShot("miss");
hair.hairSprite.SetActive(false);
hair.missedSprite.SetActive(true);
vegetableAnim.Play("Blink", 0, 0);
anim.Play("Tweezers_Pluck_Fail", 0, 0);
}
plucking = true; // Prevents standard pluck from playing in LateUpdate().
}
public void LongPluck(bool ace, LongHair hair)
@ -61,7 +81,7 @@ namespace RhythmHeavenMania.Games.RhythmTweezers
float beat = Conductor.instance.songPositionInBeats;
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound($"rhythmTweezers/longPull{Random.Range(1, 5)}", beat),
new MultiSound.Sound($"rhythmTweezers/longPull{UnityEngine.Random.Range(1, 5)}", beat),
new MultiSound.Sound("rhythmTweezers/longPullEnd", beat + 0.5f),
});