2022-01-24 02:15:23 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using NaughtyBezierCurves;
|
|
|
|
using RhythmHeavenMania.Util;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania.Games.SpaceSoccer
|
|
|
|
{
|
2022-01-25 01:02:45 +00:00
|
|
|
public class Ball : MonoBehaviour
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
|
|
|
[Header("Components")]
|
|
|
|
[SerializeField] private Kicker kicker;
|
|
|
|
[SerializeField] private GameObject holder;
|
|
|
|
[SerializeField] private GameObject spriteHolder;
|
|
|
|
[Space(10)]
|
|
|
|
[SerializeField] private BezierCurve3D dispenseCurve;
|
|
|
|
[SerializeField] private BezierCurve3D kickCurve;
|
|
|
|
[SerializeField] private BezierCurve3D highKickCurve;
|
|
|
|
[SerializeField] private BezierCurve3D toeCurve;
|
|
|
|
|
|
|
|
[Header("Properties")]
|
|
|
|
public float dispensedBeat = 0;
|
|
|
|
public bool dispensing;
|
2022-01-26 22:23:18 +00:00
|
|
|
public float hitTimes;
|
2022-01-24 02:15:23 +00:00
|
|
|
private float lastSpriteRot;
|
|
|
|
public bool canKick;
|
2022-01-25 01:02:45 +00:00
|
|
|
public GameEvent kicked = new GameEvent();
|
|
|
|
public GameEvent highKicked = new GameEvent();
|
|
|
|
public GameEvent toe = new GameEvent();
|
|
|
|
private bool lastKickLeft;
|
2022-01-24 02:15:23 +00:00
|
|
|
|
|
|
|
public void Kick()
|
|
|
|
{
|
|
|
|
Jukebox.PlayOneShotGame("spaceSoccer/ballHit");
|
2022-01-25 01:02:45 +00:00
|
|
|
|
|
|
|
lastSpriteRot = spriteHolder.transform.eulerAngles.z;
|
2022-01-24 02:15:23 +00:00
|
|
|
|
|
|
|
dispensing = false;
|
|
|
|
kicked.enabled = true;
|
2022-01-26 22:23:18 +00:00
|
|
|
// kicked.startBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
kicked.startBeat = dispensedBeat + 2 + hitTimes;
|
2022-01-24 02:15:23 +00:00
|
|
|
|
|
|
|
hitTimes++;
|
|
|
|
|
2022-01-25 01:02:45 +00:00
|
|
|
lastKickLeft = kicker.kickLeft;
|
|
|
|
|
|
|
|
if (kicker.kickLeft)
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
|
|
|
kickCurve.transform.localScale = new Vector3(-1, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kickCurve.transform.localScale = new Vector3(1, 1);
|
|
|
|
}
|
|
|
|
kickCurve.KeyPoints[0].transform.position = holder.transform.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HighKick()
|
|
|
|
{
|
2022-01-26 22:23:18 +00:00
|
|
|
hitTimes += 1.5f;
|
|
|
|
|
2022-01-24 10:13:46 +00:00
|
|
|
lastSpriteRot = spriteHolder.transform.eulerAngles.z;
|
|
|
|
|
2022-01-25 01:02:45 +00:00
|
|
|
dispensing = false;
|
2022-01-24 02:15:23 +00:00
|
|
|
kicked.enabled = false;
|
|
|
|
highKicked.enabled = true;
|
|
|
|
highKicked.startBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
|
|
|
highKickCurve.KeyPoints[0].transform.position = holder.transform.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Toe()
|
|
|
|
{
|
2022-01-26 22:23:18 +00:00
|
|
|
hitTimes += 1.5f;
|
|
|
|
|
2022-01-24 10:13:46 +00:00
|
|
|
lastSpriteRot = spriteHolder.transform.eulerAngles.z;
|
|
|
|
|
2022-01-24 02:15:23 +00:00
|
|
|
highKicked.enabled = false;
|
|
|
|
kicked.enabled = false;
|
|
|
|
|
|
|
|
toe.enabled = true;
|
|
|
|
toe.startBeat = Conductor.instance.songPositionInBeats;
|
|
|
|
|
|
|
|
toeCurve.KeyPoints[0].transform.position = holder.transform.position;
|
2022-01-26 05:38:12 +00:00
|
|
|
if (lastKickLeft)
|
|
|
|
{
|
|
|
|
toeCurve.KeyPoints[1].transform.localPosition = new Vector3(5.39f, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
toeCurve.KeyPoints[1].transform.localPosition = new Vector3(6.49f, 0);
|
|
|
|
}
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (dispensing)
|
|
|
|
{
|
2022-01-25 03:49:40 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(dispensedBeat, 2.35f);
|
2022-01-30 23:40:12 +00:00
|
|
|
holder.transform.localPosition = dispenseCurve.GetPoint(normalizedBeatAnim);
|
2022-01-24 02:15:23 +00:00
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(0f, -1440f, normalizedBeatAnim));
|
|
|
|
|
2022-01-25 01:02:45 +00:00
|
|
|
/*if (PlayerInput.Pressed())
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
2022-01-24 10:13:46 +00:00
|
|
|
Kick();
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-01-25 01:02:45 +00:00
|
|
|
}*/
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
else if (kicked.enabled)
|
|
|
|
{
|
|
|
|
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(kicked.startBeat, 1.5f);
|
2022-01-30 23:40:12 +00:00
|
|
|
holder.transform.localPosition = kickCurve.GetPoint(normalizedBeatAnim);
|
2022-01-25 01:02:45 +00:00
|
|
|
if (!lastKickLeft)
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
2022-01-25 01:02:45 +00:00
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot - 360f, normalizedBeatAnim));
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-25 01:02:45 +00:00
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot + 360f, normalizedBeatAnim));
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 01:02:45 +00:00
|
|
|
/*if (PlayerInput.Pressed())
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
2022-01-24 10:13:46 +00:00
|
|
|
if (kicker.canHighKick)
|
|
|
|
{
|
|
|
|
HighKick();
|
|
|
|
}
|
|
|
|
else if (kicker.canKick)
|
|
|
|
{
|
|
|
|
Kick();
|
|
|
|
}
|
2022-01-24 02:15:23 +00:00
|
|
|
// print(normalizedBeat);
|
|
|
|
}
|
2022-01-25 01:02:45 +00:00
|
|
|
}*/
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
else if (highKicked.enabled)
|
|
|
|
{
|
2022-01-25 03:49:40 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(highKicked.startBeat, 1.8f);
|
2022-01-30 23:40:12 +00:00
|
|
|
holder.transform.localPosition = highKickCurve.GetPoint(normalizedBeatAnim);
|
2022-01-25 03:49:40 +00:00
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot + 360f, normalizedBeatAnim));
|
2022-01-24 02:15:23 +00:00
|
|
|
|
2022-01-24 10:13:46 +00:00
|
|
|
// if (state.perfect) Debug.Break();
|
|
|
|
|
2022-01-25 01:02:45 +00:00
|
|
|
/*if (PlayerInput.Pressed())
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
|
|
|
kickPrepare = true;
|
|
|
|
kicker.Kick(this);
|
|
|
|
}
|
|
|
|
if (kickPrepare)
|
|
|
|
{
|
|
|
|
if (PlayerInput.PressedUp())
|
|
|
|
{
|
2022-01-24 10:13:46 +00:00
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Toe();
|
|
|
|
}
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-01-25 01:02:45 +00:00
|
|
|
}*/
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
else if (toe.enabled)
|
|
|
|
{
|
|
|
|
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(toe.startBeat, 1.85f);
|
2022-01-30 23:40:12 +00:00
|
|
|
holder.transform.localPosition = toeCurve.GetPoint(normalizedBeatAnim);
|
2022-01-24 02:15:23 +00:00
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, -860f, normalizedBeatAnim));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|