Spaceball cleanup and small bug fix (#236)

* Spaceball cleanup and small bug fix

* Replace old hit sound in spaceball
This commit is contained in:
Braedon Lewis
2023-01-25 10:29:31 -05:00
committed by GitHub
parent e49c0825c5
commit e822a22f54
16 changed files with 411 additions and 1539 deletions

View File

@ -5,53 +5,92 @@ using UnityEngine;
using HeavenStudio.Util;
using DG.Tweening;
using NaughtyBezierCurves;
namespace HeavenStudio.Games.Scripts_Spaceball
{
public class SpaceballBall : PlayerActionObject
{
#region Public
public float startBeat;
public Animator anim;
public bool high;
private Minigame.Eligible e = new Minigame.Eligible();
public GameObject Holder;
public Transform Holder;
public SpriteRenderer Sprite;
public bool hit;
public float hitBeat;
public Vector3 hitPos;
public float hitRot;
public float randomEndPosX;
#endregion
#region Private
private Minigame.Eligible e = new Minigame.Eligible();
[SerializeField] private BezierCurve3D pitchLowCurve;
[SerializeField] private BezierCurve3D pitchHighCurve;
private bool hit;
private float hitBeat;
private Vector3 hitPos;
private float hitRot;
private float randomEndPosX;
private float startRot;
#endregion
#region MonoBehaviour
private void Awake()
{
anim = GetComponent<Animator>();
e.gameObject = this.gameObject;
float rot = Random.Range(0, 360);
Sprite.gameObject.transform.eulerAngles = new Vector3(0, 0, rot);
startRot = Random.Range(0, 360);
isEligible = true;
}
private void Start()
private void Start()
{
Spaceball.instance.ScheduleInput(startBeat, high ? 2f : 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
}
private void Update()
{
if (hit)
{
float nba = Conductor.instance.GetPositionFromBeat(hitBeat, 14);
Holder.localPosition = Vector3.Lerp(hitPos, new Vector3(randomEndPosX, 0f, -600f), nba);
Holder.eulerAngles = Vector3.Lerp(new Vector3(0, 0, hitRot), new Vector3(0, 0, -2260), nba);
}
else
{
var beatLength = (high) ? 2f : 1f;
var normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(
startBeat,
beatLength + 0.15f
);
var animCurve = (high) ? pitchHighCurve : pitchLowCurve;
Holder.position = animCurve.GetPoint(normalizedBeatAnim);
Sprite.transform.localEulerAngles = new Vector3(0, 0, Mathf.Lerp(startRot, startRot - 210, normalizedBeatAnim));
}
}
#endregion
#region PlayerActionObject
private void Hit()
{
hit = true;
hitBeat = Conductor.instance.songPositionInBeats;
hitPos = Holder.transform.localPosition;
hitRot = Holder.transform.eulerAngles.z;
hitPos = Holder.localPosition;
hitRot = Holder.eulerAngles.z;
Jukebox.PlayOneShotGame("spaceball/hit");
// jank fix for a bug with autoplay - freeform
if (GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput)
{
@ -60,71 +99,51 @@ namespace HeavenStudio.Games.Scripts_Spaceball
randomEndPosX = Random.Range(40f, 55f);
anim.enabled = false;
SpaceballPlayer.instance.Swing(this);
}
private void NearMiss()
{
Holder.transform.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -55;
Holder.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -325;
enabled = false;
anim.enabled = false;
// Rigidbody physics, in MY rhythm game??!!!
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>();
rb.interpolation = RigidbodyInterpolation2D.Interpolate;
rb.bodyType = RigidbodyType2D.Dynamic;
rb.AddForce(transform.up * 1100);
rb.AddForce(transform.right * 400);
rb.gravityScale = 9;
Jukebox.PlayOneShot("miss");
}
private void Update()
{
var cond = Conductor.instance;
if (hit)
{
float nba = cond.GetPositionFromBeat(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
{
float beatLength = 1f;
if (high) beatLength = 2f;
Destroy(gameObject, 5f);
float normalizedBeatAnim = cond.GetPositionFromBeat(startBeat, beatLength + (float)cond.SecsToBeats(Minigame.EndTime()-1, cond.GetBpmAtBeat(startBeat + beatLength)));
if (high)
{
anim.Play("BallHigh", 0, normalizedBeatAnim);
}
else
{
anim.Play("BallLow", 0, normalizedBeatAnim);
}
anim.speed = 0;
}
Spaceball.instance.ScoreMiss();
}
private void Just(PlayerActionEvent caller, float state)
{
if (state >= 1f || state <= -1f) {
if (state >= 1f || state <= -1f)
{
NearMiss();
return;
return;
}
Hit();
}
private void Miss(PlayerActionEvent caller)
private void Miss(PlayerActionEvent caller)
{
Jukebox.PlayOneShotGame("spaceball/fall");
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
Destroy(this.gameObject);
Spaceball.instance.ScoreMiss();
}
private void Out(PlayerActionEvent caller) {}
private void Out(PlayerActionEvent caller) { }
#endregion
}
}