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
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
public enum State { Dispensing, Kicked, HighKicked, Toe };
|
2022-01-24 02:15:23 +00:00
|
|
|
[Header("Components")]
|
2022-02-02 08:36:20 +00:00
|
|
|
[HideInInspector] public Kicker kicker;
|
2022-01-24 02:15:23 +00:00
|
|
|
[SerializeField] private GameObject holder;
|
|
|
|
[SerializeField] private GameObject spriteHolder;
|
2022-02-02 08:36:20 +00:00
|
|
|
[SerializeField] private GameObject kickFX;
|
2022-01-24 02:15:23 +00:00
|
|
|
[Space(10)]
|
|
|
|
[SerializeField] private BezierCurve3D dispenseCurve;
|
|
|
|
[SerializeField] private BezierCurve3D kickCurve;
|
|
|
|
[SerializeField] private BezierCurve3D highKickCurve;
|
|
|
|
[SerializeField] private BezierCurve3D toeCurve;
|
|
|
|
|
|
|
|
[Header("Properties")]
|
2022-02-26 07:27:51 +00:00
|
|
|
public float startBeat;
|
|
|
|
public State state;
|
|
|
|
public float nextAnimBeat;
|
2022-02-06 08:28:14 +00:00
|
|
|
public float highKickSwing = 0f;
|
2022-01-24 02:15:23 +00:00
|
|
|
private float lastSpriteRot;
|
|
|
|
public bool canKick;
|
2022-01-25 01:02:45 +00:00
|
|
|
private bool lastKickLeft;
|
2022-01-24 02:15:23 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
public void Init(Kicker kicker, float dispensedBeat)
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
this.kicker = kicker;
|
|
|
|
kicker.ball = this;
|
|
|
|
kicker.dispenserBeat = dispensedBeat;
|
|
|
|
state = State.Dispensing;
|
|
|
|
startBeat = dispensedBeat;
|
|
|
|
kicker.kickTimes = 0;
|
|
|
|
if (kicker.player)
|
|
|
|
{
|
|
|
|
MultiSound.Play(new MultiSound.Sound[]
|
|
|
|
{
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseNoise", dispensedBeat),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble1", dispensedBeat + 0.25f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble2", dispensedBeat + 0.5f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble2B",dispensedBeat + 0.5f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble3", dispensedBeat + 0.75f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble4", dispensedBeat + 1f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble5", dispensedBeat + 1.25f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble6", dispensedBeat + 1.5f),
|
|
|
|
new MultiSound.Sound("spaceSoccer/dispenseTumble6B",dispensedBeat + 1.75f),
|
|
|
|
});
|
|
|
|
}
|
2022-02-02 08:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Kick(bool player)
|
|
|
|
{
|
|
|
|
if (player)
|
2022-01-24 02:15:23 +00:00
|
|
|
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
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
SetState(State.Kicked);
|
2022-01-24 02:15:23 +00:00
|
|
|
|
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;
|
2022-02-02 08:36:20 +00:00
|
|
|
|
|
|
|
HitFX();
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void HighKick()
|
|
|
|
{
|
2022-01-24 10:13:46 +00:00
|
|
|
lastSpriteRot = spriteHolder.transform.eulerAngles.z;
|
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
SetState(State.HighKicked);
|
2022-01-24 02:15:23 +00:00
|
|
|
|
|
|
|
highKickCurve.KeyPoints[0].transform.position = holder.transform.position;
|
2022-02-02 08:36:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
HitFX();
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Toe()
|
|
|
|
{
|
2022-01-26 22:23:18 +00:00
|
|
|
|
2022-01-24 10:13:46 +00:00
|
|
|
lastSpriteRot = spriteHolder.transform.eulerAngles.z;
|
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
SetState(State.Toe);
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-01-24 02:15:23 +00:00
|
|
|
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-02-02 08:36:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
HitFX();
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
switch (state)
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
case State.Dispensing:
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, 2.35f);
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
dispenseCurve.KeyPoints[0].transform.position = new Vector3(kicker.transform.position.x - 6f, kicker.transform.position.y - 6f);
|
|
|
|
dispenseCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 1f, kicker.transform.position.y - 6f);
|
2022-01-24 02:15:23 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
holder.transform.localPosition = dispenseCurve.GetPoint(normalizedBeatAnim);
|
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(0f, -1440f, normalizedBeatAnim));
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
/*if (PlayerInput.Pressed())
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Kick();
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case State.Kicked:
|
2022-01-24 02:15:23 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, 1.5f);
|
|
|
|
|
|
|
|
if (!lastKickLeft)
|
2022-01-24 10:13:46 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
kickCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x + 0.5f, kicker.transform.position.y - 6f);
|
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot - 360f, normalizedBeatAnim));
|
2022-01-24 10:13:46 +00:00
|
|
|
}
|
2022-02-26 07:27:51 +00:00
|
|
|
else
|
2022-01-24 10:13:46 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
kickCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 2.5f, kicker.transform.position.y - 6f);
|
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot + 360f, normalizedBeatAnim));
|
2022-01-24 10:13:46 +00:00
|
|
|
}
|
2022-02-26 07:27:51 +00:00
|
|
|
|
|
|
|
holder.transform.localPosition = kickCurve.GetPoint(normalizedBeatAnim);
|
|
|
|
|
|
|
|
/*if (PlayerInput.Pressed())
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
if (kicker.canHighKick)
|
|
|
|
{
|
|
|
|
HighKick();
|
|
|
|
}
|
|
|
|
else if (kicker.canKick)
|
|
|
|
{
|
|
|
|
Kick();
|
|
|
|
}
|
|
|
|
// print(normalizedBeat);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
break;
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-02-26 07:27:51 +00:00
|
|
|
case State.HighKicked:
|
|
|
|
{
|
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, GetAnimLength(State.HighKicked) + 0.3f);
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
highKickCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 3.5f, kicker.transform.position.y - 6f);
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
holder.transform.localPosition = highKickCurve.GetPoint(normalizedBeatAnim);
|
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot + 360f, normalizedBeatAnim));
|
2022-01-24 02:15:23 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
// if (state.perfect) Debug.Break();
|
2022-01-24 10:13:46 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
/*if (PlayerInput.Pressed())
|
2022-01-24 10:13:46 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
kickPrepare = true;
|
|
|
|
kicker.Kick(this);
|
2022-01-24 10:13:46 +00:00
|
|
|
}
|
2022-02-26 07:27:51 +00:00
|
|
|
if (kickPrepare)
|
|
|
|
{
|
|
|
|
if (PlayerInput.PressedUp())
|
|
|
|
{
|
|
|
|
if (state.perfect)
|
|
|
|
{
|
|
|
|
Toe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
break;
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-02-26 07:27:51 +00:00
|
|
|
case State.Toe:
|
|
|
|
{
|
|
|
|
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, GetAnimLength(State.Toe) + 0.35f);
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
if (!lastKickLeft)
|
|
|
|
{
|
|
|
|
toeCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x + 0.5f, kicker.transform.position.y - 6f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
toeCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 1.0f, kicker.transform.position.y - 6f);
|
|
|
|
}
|
2022-02-02 08:36:20 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
holder.transform.localPosition = toeCurve.GetPoint(normalizedBeatAnim);
|
|
|
|
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, -860f, normalizedBeatAnim));
|
|
|
|
break;
|
|
|
|
}
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-02-02 08:36:20 +00:00
|
|
|
|
|
|
|
holder.transform.position = new Vector3(holder.transform.position.x, holder.transform.position.y, kicker.transform.localPosition.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HitFX()
|
|
|
|
{
|
|
|
|
GameObject kickfx = Instantiate(kickFX.gameObject, SpaceSoccer.instance.transform);
|
|
|
|
kickfx.SetActive(true);
|
|
|
|
kickfx.transform.position = holder.transform.position;
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
2022-02-06 08:28:14 +00:00
|
|
|
|
2022-02-26 07:27:51 +00:00
|
|
|
private void SetState(State newState)
|
2022-02-06 08:28:14 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
state = newState;
|
|
|
|
startBeat = nextAnimBeat;
|
|
|
|
nextAnimBeat += GetAnimLength(newState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public float GetAnimLength(State anim)
|
|
|
|
{
|
|
|
|
switch(anim)
|
2022-02-06 08:28:14 +00:00
|
|
|
{
|
2022-02-26 07:27:51 +00:00
|
|
|
case State.Dispensing:
|
|
|
|
return 2f;
|
|
|
|
case State.Kicked:
|
|
|
|
return 1f;
|
|
|
|
case State.HighKicked:
|
2022-02-06 08:28:14 +00:00
|
|
|
return 2f - highKickSwing;
|
2022-02-26 07:27:51 +00:00
|
|
|
case State.Toe:
|
|
|
|
return 2f - (1f - highKickSwing);
|
|
|
|
default:
|
|
|
|
Debug.LogError("Ball has invalid state. State number: " + (int)anim);
|
|
|
|
return 0f;
|
2022-02-06 08:28:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-24 02:15:23 +00:00
|
|
|
}
|
|
|
|
}
|