mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:37:37 +02:00
Improved inputs (A SHIT MORE DYNAMIC BETWEEN GAMES) and a whole lot cleaner code in general
This commit is contained in:
@ -8,12 +8,10 @@ using DG.Tweening;
|
||||
|
||||
namespace RhythmHeavenMania.Games.Spaceball
|
||||
{
|
||||
public class SpaceballBall : MonoBehaviour
|
||||
public class SpaceballBall : PlayerActionObject
|
||||
{
|
||||
public float startBeat;
|
||||
private Animator anim;
|
||||
private int lastState;
|
||||
private bool inList = false;
|
||||
public Animator anim;
|
||||
|
||||
public bool high;
|
||||
|
||||
@ -22,6 +20,12 @@ namespace RhythmHeavenMania.Games.Spaceball
|
||||
public GameObject Holder;
|
||||
public SpriteRenderer Sprite;
|
||||
|
||||
public bool hit;
|
||||
public float hitBeat;
|
||||
public Vector3 hitPos;
|
||||
public float hitRot;
|
||||
public float randomEndPosX;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
@ -30,120 +34,56 @@ namespace RhythmHeavenMania.Games.Spaceball
|
||||
|
||||
float rot = Random.Range(0, 360);
|
||||
Sprite.gameObject.transform.eulerAngles = new Vector3(0, 0, rot);
|
||||
|
||||
|
||||
PlayerActionInit(this.gameObject, startBeat, Spaceball.instance.EligibleHits);
|
||||
|
||||
isEligible = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float beatLength = 1f;
|
||||
if (high) beatLength = 2f;
|
||||
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, beatLength + 0.15f);
|
||||
// print(normalizedBeatAnim + " " + Time.frameCount);
|
||||
|
||||
if (high)
|
||||
if (hit)
|
||||
{
|
||||
anim.Play("BallHigh", 0, normalizedBeatAnim);
|
||||
float nba = Conductor.instance.GetLoopPositionFromBeat(hitBeat, 14);
|
||||
Holder.transform.localPosition = Vector3.Lerp(hitPos, new Vector3(randomEndPosX, 0f, -600f), nba);
|
||||
Holder.transform.eulerAngles = Vector3.Lerp(new Vector3(0, 0, hitRot), new Vector3(0, 0, -2260), nba);
|
||||
}
|
||||
else
|
||||
{
|
||||
anim.Play("BallLow", 0, normalizedBeatAnim);
|
||||
}
|
||||
float beatLength = 1f;
|
||||
if (high) beatLength = 2f;
|
||||
|
||||
anim.speed = 0;
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(startBeat, beatLength + 0.15f);
|
||||
// print(normalizedBeatAnim + " " + Time.frameCount);
|
||||
|
||||
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, beatLength);
|
||||
|
||||
if (normalizedBeat > Minigame.EarlyTime() && normalizedBeat < Minigame.PerfectTime() && lastState == 0)
|
||||
{
|
||||
MakeEligible(true, false, false);
|
||||
lastState++;
|
||||
}
|
||||
// Perfect State
|
||||
else if (normalizedBeat > Minigame.PerfectTime() && normalizedBeat < Minigame.LateTime() && lastState == 1)
|
||||
{
|
||||
MakeEligible(false, true, false);
|
||||
lastState++;
|
||||
}
|
||||
// Late State
|
||||
else if (normalizedBeat > Minigame.LateTime() && normalizedBeat < Minigame.EndTime() && lastState == 2)
|
||||
{
|
||||
MakeEligible(false, false, true);
|
||||
lastState++;
|
||||
}
|
||||
else if (normalizedBeat < Minigame.EarlyTime() || normalizedBeat > Minigame.EndTime())
|
||||
{
|
||||
MakeInEligible();
|
||||
}
|
||||
|
||||
// too lazy to make a proper fix for this
|
||||
float endTime = 1.2f;
|
||||
if (high) endTime = 1.1f;
|
||||
|
||||
if (normalizedBeat > endTime)
|
||||
{
|
||||
Jukebox.PlayOneShotGame("spaceball/fall");
|
||||
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
if (PlayerInput.Pressed())
|
||||
{
|
||||
if (e.perfect)
|
||||
if (high)
|
||||
{
|
||||
Jukebox.PlayOneShotGame("spaceball/hit");
|
||||
Holder.transform.DOLocalMove(new Vector3(Random.Range(5, 18), 0, -600), 4f).SetEase(Ease.Linear);
|
||||
Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -245;
|
||||
|
||||
this.enabled = false;
|
||||
gameObject.GetComponent<Animator>().enabled = false;
|
||||
anim.Play("BallHigh", 0, normalizedBeatAnim);
|
||||
}
|
||||
else if (e.late || e.early)
|
||||
else
|
||||
{
|
||||
Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -55;
|
||||
anim.Play("BallLow", 0, normalizedBeatAnim);
|
||||
}
|
||||
|
||||
this.enabled = false;
|
||||
gameObject.GetComponent<Animator>().enabled = false;
|
||||
anim.speed = 0;
|
||||
|
||||
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>();
|
||||
rb.bodyType = RigidbodyType2D.Dynamic;
|
||||
rb.AddForce(transform.up * 1100);
|
||||
rb.AddForce(transform.right * 400);
|
||||
rb.gravityScale = 9;
|
||||
float normalizedBeat = Conductor.instance.GetLoopPositionFromBeat(startBeat, beatLength);
|
||||
|
||||
Jukebox.PlayOneShot("miss");
|
||||
StateCheck(normalizedBeat);
|
||||
|
||||
// too lazy to make a proper fix for this
|
||||
float endTime = 1.2f;
|
||||
if (high) endTime = 1.1f;
|
||||
|
||||
if (normalizedBeat > endTime)
|
||||
{
|
||||
Jukebox.PlayOneShotGame("spaceball/fall");
|
||||
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeEligible(bool early, bool perfect, bool late)
|
||||
{
|
||||
// print($"{early}, {perfect}, {late}");
|
||||
|
||||
if (!inList)
|
||||
{
|
||||
e.early = early;
|
||||
e.perfect = perfect;
|
||||
e.late = late;
|
||||
|
||||
SpaceballPlayer.instance.EligibleHits.Add(e);
|
||||
inList = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Minigame.Eligible es = SpaceballPlayer.instance.EligibleHits[SpaceballPlayer.instance.EligibleHits.IndexOf(e)];
|
||||
es.early = early;
|
||||
es.perfect = perfect;
|
||||
es.late = late;
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeInEligible()
|
||||
{
|
||||
if (!inList) return;
|
||||
|
||||
SpaceballPlayer.instance.EligibleHits.Remove(e);
|
||||
inList = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user