2021-12-25 12:16:40 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-01-14 02:33:51 +00:00
|
|
|
using DG.Tweening;
|
2023-01-25 15:29:31 +00:00
|
|
|
using NaughtyBezierCurves;
|
2022-01-14 02:33:51 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_Spaceball
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2022-01-17 05:00:26 +00:00
|
|
|
public class SpaceballBall : PlayerActionObject
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2023-01-25 15:29:31 +00:00
|
|
|
#region Public
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
public float startBeat;
|
|
|
|
|
2021-12-25 13:32:52 +00:00
|
|
|
public bool high;
|
2023-01-31 16:16:01 +00:00
|
|
|
public bool isTacobell;
|
2021-12-25 13:32:52 +00:00
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
public Transform Holder;
|
|
|
|
public SpriteRenderer Sprite;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Private
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
private Minigame.Eligible e = new Minigame.Eligible();
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
[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
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
#region MonoBehaviour
|
2022-01-17 05:00:26 +00:00
|
|
|
|
2022-03-26 02:08:46 +00:00
|
|
|
private void Awake()
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
|
|
|
e.gameObject = this.gameObject;
|
2021-12-28 07:38:55 +00:00
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
startRot = Random.Range(0, 360);
|
2022-01-17 05:00:26 +00:00
|
|
|
|
|
|
|
isEligible = true;
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
private void Start()
|
2022-01-23 07:01:59 +00:00
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
Spaceball.instance.ScheduleInput(startBeat, high ? 2f : 1f, InputType.STANDARD_DOWN, Just, Miss, Out);
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
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
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
private void Hit()
|
|
|
|
{
|
|
|
|
hit = true;
|
|
|
|
hitBeat = Conductor.instance.songPositionInBeats;
|
2023-01-25 15:29:31 +00:00
|
|
|
hitPos = Holder.localPosition;
|
|
|
|
hitRot = Holder.eulerAngles.z;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
2023-01-31 16:16:01 +00:00
|
|
|
if (isTacobell)
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/tacobell");
|
|
|
|
}
|
2022-01-23 07:01:59 +00:00
|
|
|
Jukebox.PlayOneShotGame("spaceball/hit");
|
2023-01-25 15:29:31 +00:00
|
|
|
|
2022-05-06 22:14:01 +00:00
|
|
|
// jank fix for a bug with autoplay - freeform
|
|
|
|
if (GameManager.instance.autoplay && Conductor.instance.isPlaying && GameManager.instance.canInput)
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/swing");
|
|
|
|
}
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
randomEndPosX = Random.Range(40f, 55f);
|
|
|
|
|
|
|
|
SpaceballPlayer.instance.Swing(this);
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
private void NearMiss()
|
2022-01-23 07:01:59 +00:00
|
|
|
{
|
2023-01-25 15:29:31 +00:00
|
|
|
Holder.GetChild(0).gameObject.AddComponent<Rotate>().rotateSpeed = -325;
|
2022-01-23 07:01:59 +00:00
|
|
|
|
|
|
|
enabled = false;
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
// Rigidbody physics, in MY rhythm game??!!!
|
2022-01-23 07:01:59 +00:00
|
|
|
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>();
|
2023-01-25 15:29:31 +00:00
|
|
|
rb.interpolation = RigidbodyInterpolation2D.Interpolate;
|
2022-01-23 07:01:59 +00:00
|
|
|
rb.bodyType = RigidbodyType2D.Dynamic;
|
|
|
|
rb.AddForce(transform.up * 1100);
|
|
|
|
rb.AddForce(transform.right * 400);
|
|
|
|
rb.gravityScale = 9;
|
|
|
|
|
|
|
|
Jukebox.PlayOneShot("miss");
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
Destroy(gameObject, 5f);
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
Spaceball.instance.ScoreMiss();
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2023-01-16 03:05:25 +00:00
|
|
|
private void Just(PlayerActionEvent caller, float state)
|
|
|
|
{
|
2023-01-25 15:29:31 +00:00
|
|
|
if (state >= 1f || state <= -1f)
|
|
|
|
{
|
2023-01-16 03:05:25 +00:00
|
|
|
NearMiss();
|
2023-01-25 15:29:31 +00:00
|
|
|
return;
|
2022-01-17 05:00:26 +00:00
|
|
|
}
|
2023-01-16 03:05:25 +00:00
|
|
|
Hit();
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
private void Miss(PlayerActionEvent caller)
|
2023-01-16 03:05:25 +00:00
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceball/fall");
|
|
|
|
Instantiate(Spaceball.instance.Dust, Spaceball.instance.Dust.transform.parent).SetActive(true);
|
|
|
|
Destroy(this.gameObject);
|
2023-01-25 15:29:31 +00:00
|
|
|
|
|
|
|
Spaceball.instance.ScoreMiss();
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 15:29:31 +00:00
|
|
|
private void Out(PlayerActionEvent caller) { }
|
|
|
|
|
|
|
|
#endregion
|
2023-01-16 03:05:25 +00:00
|
|
|
}
|
2022-05-06 22:14:01 +00:00
|
|
|
}
|