Merge pull request #14 from Slaith12/main

Fixed bug causing space soccer to spam sfx when starting in the middle of it.
This commit is contained in:
Jenny Crowe 2022-02-27 01:53:16 -07:00 committed by GitHub
commit f134e75d86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 311 additions and 240 deletions

View file

@ -1386,9 +1386,9 @@ MonoBehaviour:
perfect: 0 perfect: 0
late: 0 late: 0
createBeat: 0 createBeat: 0
isEligible: 0
eligibleHitsList: [] eligibleHitsList: []
aceTimes: 0 aceTimes: 0
isEligible: 0
canKick: 0 canKick: 0
canHighKick: 0 canHighKick: 0
kickLeft: 0 kickLeft: 0
@ -2004,7 +2004,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &6448989353494316845 --- !u!4 &6448989353494316845
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2044,9 +2044,10 @@ MonoBehaviour:
kickCurve: {fileID: 1507665286932590801} kickCurve: {fileID: 1507665286932590801}
highKickCurve: {fileID: 5471456891558289981} highKickCurve: {fileID: 5471456891558289981}
toeCurve: {fileID: 8336007186072323660} toeCurve: {fileID: 8336007186072323660}
dispensedBeat: 0 startBeat: 0
dispensing: 0 state: 0
hitTimes: 0 nextAnimBeat: 0
highKickSwing: 0
canKick: 0 canKick: 0
--- !u!1 &4365805729759623217 --- !u!1 &4365805729759623217
GameObject: GameObject:
@ -3886,9 +3887,9 @@ MonoBehaviour:
perfect: 0 perfect: 0
late: 0 late: 0
createBeat: 0 createBeat: 0
isEligible: 0
eligibleHitsList: [] eligibleHitsList: []
aceTimes: 0 aceTimes: 0
isEligible: 0
canKick: 0 canKick: 0
canHighKick: 0 canHighKick: 0
kickLeft: 0 kickLeft: 0

View file

@ -11,13 +11,13 @@ namespace RhythmHeavenMania.Games
public bool inList = false; public bool inList = false;
public int lastState; public int lastState;
public Minigame.Eligible state = new Minigame.Eligible(); public Minigame.Eligible state = new Minigame.Eligible();
public bool isEligible;
public List<Minigame.Eligible> eligibleHitsList = new List<Minigame.Eligible>(); public List<Minigame.Eligible> eligibleHitsList = new List<Minigame.Eligible>();
public int aceTimes; //the variables below seem to be mostly unused (they are never used in any meaningful way)
public int aceTimes; //always set to 0 no matter what (also, the one time it's used doesn't seem to make sense)
private bool autoPlayEnabledOnStart; public bool isEligible; //value never used for anything
private bool autoPlayEnabledOnStart; //value never used for anything
public void PlayerActionInit(GameObject g, float createBeat) public void PlayerActionInit(GameObject g, float createBeat)
{ {
@ -31,7 +31,7 @@ namespace RhythmHeavenMania.Games
{ {
if (aceTimes == 0) if (aceTimes == 0)
{ {
if (GameManager.instance.autoplay && normalizedBeat > 0.99f || autoPlay && normalizedBeat > 0.99f) if ((GameManager.instance.autoplay || autoPlay) && normalizedBeat > 0.99f)
{ {
OnAce(); OnAce();
if (!autoPlay) if (!autoPlay)

View file

@ -9,6 +9,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
{ {
public class Ball : MonoBehaviour public class Ball : MonoBehaviour
{ {
public enum State { Dispensing, Kicked, HighKicked, Toe };
[Header("Components")] [Header("Components")]
[HideInInspector] public Kicker kicker; [HideInInspector] public Kicker kicker;
[SerializeField] private GameObject holder; [SerializeField] private GameObject holder;
@ -21,19 +22,101 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
[SerializeField] private BezierCurve3D toeCurve; [SerializeField] private BezierCurve3D toeCurve;
[Header("Properties")] [Header("Properties")]
public float dispensedBeat = 0; public float startBeat;
public bool dispensing; public State state;
public float hitTimes; public float nextAnimBeat;
public float highKickSwing = 0f; public float highKickSwing = 0f;
private float lastSpriteRot; private float lastSpriteRot;
public bool canKick; public bool canKick; //unused
public GameEvent kicked = new GameEvent();
public GameEvent highKicked = new GameEvent();
public GameEvent toe = new GameEvent();
private bool lastKickLeft; private bool lastKickLeft;
private void Start() public void Init(Kicker kicker, float dispensedBeat)
{ {
this.kicker = kicker;
kicker.ball = this;
kicker.dispenserBeat = dispensedBeat;
float currentBeat = Conductor.instance.songPositionInBeats;
if(currentBeat - dispensedBeat < 2f) //check if ball is currently being dispensed (should only be false if starting in the middle of the remix)
{
//Debug.Log("Dispensing");
state = State.Dispensing;
startBeat = dispensedBeat;
nextAnimBeat = startBeat + GetAnimLength(State.Dispensing);
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),
});
}
return;
}
List<Beatmap.Entity> highKicks = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel == "spaceSoccer/high kick-toe!");
int numHighKicks = 0;
//determine what state the ball was in for the previous kick.
for(int i = 0; i < highKicks.Count; i++)
{
if (highKicks[i].beat + highKicks[i].length <= currentBeat)
{
numHighKicks++;
continue;
}
if (highKicks[i].beat > currentBeat)
{
//Debug.Log("Setting state to kicked");
state = State.Kicked;
float relativeBeat = currentBeat - dispensedBeat;
startBeat = dispensedBeat + (int)(relativeBeat - 0.1); //this makes the startBeat be for the kick that is currently in progress, but it won't play the kicker's animation for that kick. the -0.1 makes it so that if playback is started right when the kicker kicks, it still plays the kicker's animation.
nextAnimBeat = startBeat + GetAnimLength(State.Kicked);
kicker.kickTimes = (int)(relativeBeat - 0.1) - numHighKicks - 1; //every high kick has 2 kicks in the same time a regular keep-up does 3 kicks.
break;
}
else
{
highKickSwing = highKicks[i].swing;
if (highKicks[i].beat + GetAnimLength(State.HighKicked) > currentBeat)
{
//Debug.Log("Setting state to high kick");
state = State.HighKicked;
float relativeBeat = highKicks[i].beat - dispensedBeat;
startBeat = dispensedBeat + Mathf.Ceil(relativeBeat); //there is a chance this makes startBeat later than the current beat, but it shouldn't matter too much. It would only happen if the user places the high kicks incorrectly.
nextAnimBeat = startBeat + GetAnimLength(State.HighKicked);
kicker.kickTimes = Mathf.CeilToInt(relativeBeat) - numHighKicks - 1;
break;
}
else
{
//Debug.Log("Setting state to toe");
state = State.Toe;
float relativeBeat = Mathf.Ceil(highKicks[i].beat - dispensedBeat) + GetAnimLength(State.HighKicked); //there is a chance this makes startBeat later than the current beat, but it shouldn't matter too much. It would only happen if the user places the high kicks incorrectly.
startBeat = dispensedBeat + relativeBeat;
nextAnimBeat = startBeat + GetAnimLength(State.Toe);
kicker.kickTimes = (int)(relativeBeat - GetAnimLength(State.HighKicked)) - numHighKicks;
break;
}
}
}
if(state == 0) //if the for loop didn't set the state
{
//Debug.Log("Defaulting to kicked state");
state = State.Kicked;
float relativeBeat = currentBeat - dispensedBeat;
startBeat = dispensedBeat + (int)(relativeBeat - 0.1); //this makes the startBeat be for the kick that is currently in progress, but it won't play the kicker's animation for that kick. the -0.1 makes it so that if playback is started right when the kicker kicks, it still plays the kicker's animation.
nextAnimBeat = startBeat + GetAnimLength(State.Kicked);
kicker.kickTimes = (int)(relativeBeat - 0.1) - numHighKicks - 1;
}
Update(); //make sure the ball is in the right place
} }
public void Kick(bool player) public void Kick(bool player)
@ -43,12 +126,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
lastSpriteRot = spriteHolder.transform.eulerAngles.z; lastSpriteRot = spriteHolder.transform.eulerAngles.z;
dispensing = false; SetState(State.Kicked);
kicked.enabled = true;
// kicked.startBeat = Conductor.instance.songPositionInBeats;
kicked.startBeat = dispensedBeat + 2 + hitTimes;
hitTimes++;
lastKickLeft = kicker.kickLeft; lastKickLeft = kicker.kickLeft;
@ -67,14 +145,9 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
public void HighKick() public void HighKick()
{ {
hitTimes += GetHighKickLength(false);
lastSpriteRot = spriteHolder.transform.eulerAngles.z; lastSpriteRot = spriteHolder.transform.eulerAngles.z;
dispensing = false; SetState(State.HighKicked);
kicked.enabled = false;
highKicked.enabled = true;
highKicked.startBeat = Conductor.instance.songPositionInBeats;
highKickCurve.KeyPoints[0].transform.position = holder.transform.position; highKickCurve.KeyPoints[0].transform.position = holder.transform.position;
@ -84,15 +157,10 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
public void Toe() public void Toe()
{ {
hitTimes += GetHighKickLength(true);
lastSpriteRot = spriteHolder.transform.eulerAngles.z; lastSpriteRot = spriteHolder.transform.eulerAngles.z;
highKicked.enabled = false; SetState(State.Toe);
kicked.enabled = false;
toe.enabled = true;
toe.startBeat = Conductor.instance.songPositionInBeats;
toeCurve.KeyPoints[0].transform.position = holder.transform.position; toeCurve.KeyPoints[0].transform.position = holder.transform.position;
if (lastKickLeft) if (lastKickLeft)
@ -110,9 +178,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
private void Update() private void Update()
{ {
if (dispensing) switch (state) //handle animations
{ {
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(dispensedBeat, 2.35f); case State.Dispensing:
{
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, 2.35f);
dispenseCurve.KeyPoints[0].transform.position = new Vector3(kicker.transform.position.x - 6f, kicker.transform.position.y - 6f); 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); dispenseCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 1f, kicker.transform.position.y - 6f);
@ -127,10 +197,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
Kick(); Kick();
} }
}*/ }*/
break;
} }
else if (kicked.enabled) case State.Kicked:
{ {
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(kicked.startBeat, 1.5f); float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, 1.5f);
if (!lastKickLeft) if (!lastKickLeft)
{ {
@ -160,10 +231,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
// print(normalizedBeat); // print(normalizedBeat);
} }
}*/ }*/
break;
} }
else if (highKicked.enabled) case State.HighKicked:
{ {
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(highKicked.startBeat, GetHighKickLength(false) + 0.3f); float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, GetAnimLength(State.HighKicked) + 0.3f);
highKickCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 3.5f, kicker.transform.position.y - 6f); highKickCurve.KeyPoints[1].transform.position = new Vector3(kicker.transform.position.x - 3.5f, kicker.transform.position.y - 6f);
@ -187,10 +259,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
}*/ }*/
break;
} }
else if (toe.enabled) case State.Toe:
{ {
float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(toe.startBeat, GetHighKickLength(true) + 0.35f); float normalizedBeatAnim = Conductor.instance.GetPositionFromBeat(startBeat, GetAnimLength(State.Toe) + 0.35f);
if (!lastKickLeft) if (!lastKickLeft)
{ {
@ -203,6 +276,8 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
holder.transform.localPosition = toeCurve.GetPoint(normalizedBeatAnim); holder.transform.localPosition = toeCurve.GetPoint(normalizedBeatAnim);
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, -860f, normalizedBeatAnim)); spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, -860f, normalizedBeatAnim));
break;
}
} }
holder.transform.position = new Vector3(holder.transform.position.x, holder.transform.position.y, kicker.transform.localPosition.z); holder.transform.position = new Vector3(holder.transform.position.x, holder.transform.position.y, kicker.transform.localPosition.z);
@ -215,22 +290,28 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
kickfx.transform.position = holder.transform.position; kickfx.transform.position = holder.transform.position;
} }
public float GetHighKickLength(bool fromToe) private void SetState(State newState)
{ {
if (highKickSwing == 0f) state = newState;
{ startBeat = nextAnimBeat;
return 1.5f; nextAnimBeat += GetAnimLength(newState);
} }
else
public float GetAnimLength(State anim)
{ {
if (fromToe) switch(anim)
{
return 2f - (1f - highKickSwing);
}
else
{ {
case State.Dispensing:
return 2f;
case State.Kicked:
return 1f;
case State.HighKicked:
return 2f - highKickSwing; return 2f - highKickSwing;
} case State.Toe:
return 2f - (1f - highKickSwing);
default:
Debug.LogError("Ball has invalid state. State number: " + (int)anim);
return 0f;
} }
} }
} }

View file

@ -13,7 +13,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
public bool canHighKick; public bool canHighKick;
private bool kickPrepare = false; private bool kickPrepare = false;
public bool kickLeft; public bool kickLeft;
public float dispenserBeat; public float dispenserBeat; //unused
public int kickTimes = 0; public int kickTimes = 0;
public bool player; public bool player;
@ -40,7 +40,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
public override void OnAce() public override void OnAce()
{ {
if (ball.highKicked.enabled) if (ball.state == Ball.State.HighKicked)
{ {
if (!kickPrepare) if (!kickPrepare)
{ {
@ -83,7 +83,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
anim.Play("HighKickRight_0", 0, 0); anim.Play("HighKickRight_0", 0, 0);
} }
} }
else if (!highKick) else
{ {
if (kickLeft) if (kickLeft)
{ {
@ -214,9 +214,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
if (ball) if (ball)
{ {
if (ball.dispensing) switch (ball.state)
{ {
float normalizedBeat = Conductor.instance.GetPositionFromBeat(ball.dispensedBeat, 2f); case Ball.State.Dispensing:
{
float normalizedBeat = Conductor.instance.GetPositionFromBeat(ball.startBeat, ball.GetAnimLength(Ball.State.Dispensing));
StateCheck(normalizedBeat, !player); StateCheck(normalizedBeat, !player);
CheckIfFall(normalizedBeat); CheckIfFall(normalizedBeat);
@ -234,10 +236,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
} }
break;
} }
else if (ball.kicked.enabled) case Ball.State.Kicked:
{ {
float normalizedBeat = Conductor.instance.GetPositionFromBeat(ball.kicked.startBeat, 1f); float normalizedBeat = Conductor.instance.GetPositionFromBeat(ball.startBeat, ball.GetAnimLength(Ball.State.Kicked));
StateCheck(normalizedBeat, !player); StateCheck(normalizedBeat, !player);
CheckIfFall(normalizedBeat); CheckIfFall(normalizedBeat);
@ -255,13 +258,14 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
} }
break;
} }
else if (ball.highKicked.enabled) case Ball.State.HighKicked:
{ {
float normalizedBeat = Conductor.instance.GetPositionFromMargin(ball.highKicked.startBeat + ball.GetHighKickLength(false), 1f); float normalizedBeat = Conductor.instance.GetPositionFromMargin(ball.startBeat + ball.GetAnimLength(Ball.State.HighKicked), 1f);
if (!kickPrepare) if (!kickPrepare)
{ {
float normalizedBeatPrepare = Conductor.instance.GetPositionFromBeat(ball.highKicked.startBeat, 1f); float normalizedBeatPrepare = Conductor.instance.GetPositionFromBeat(ball.startBeat, 1f);
StateCheck(normalizedBeatPrepare, !player); StateCheck(normalizedBeatPrepare, !player);
CheckIfFall(normalizedBeat); CheckIfFall(normalizedBeat);
@ -293,10 +297,11 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
} }
break;
} }
else if (ball.toe.enabled) case Ball.State.Toe:
{ {
float normalizedBeat = Conductor.instance.GetPositionFromMargin(ball.toe.startBeat + ball.GetHighKickLength(true), 1f); float normalizedBeat = Conductor.instance.GetPositionFromMargin(ball.startBeat + ball.GetAnimLength(Ball.State.Toe), 1f);
StateCheck(normalizedBeat, !player); StateCheck(normalizedBeat, !player);
CheckIfFall(normalizedBeat); CheckIfFall(normalizedBeat);
@ -314,6 +319,8 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
} }
break;
}
} }
} }
else else
@ -326,6 +333,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
} }
} }
} }
private void KickCheck(bool hit, bool overrideState = false) private void KickCheck(bool hit, bool overrideState = false)

View file

@ -15,7 +15,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
[SerializeField] private Sprite[] backgroundSprite; [SerializeField] private Sprite[] backgroundSprite;
[Header("Properties")] [Header("Properties")]
[SerializeField] private bool ballDispensed; [SerializeField] private bool ballDispensed; //unused
public static SpaceSoccer instance { get; private set; } public static SpaceSoccer instance { get; private set; }
@ -42,9 +42,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
private void Update() private void Update()
{ {
if (ballDispensed)
{
}
} }
public void Dispense(float beat) public void Dispense(float beat)
@ -58,27 +56,10 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
ballDispensed = true; ballDispensed = true;
GameObject ball = Instantiate(ballRef, transform); GameObject ball = Instantiate(ballRef, transform);
ball.SetActive(true);
Ball ball_ = ball.GetComponent<Ball>(); Ball ball_ = ball.GetComponent<Ball>();
ball_.kicker = kicker; ball_.Init(kicker, beat);
ball_.dispensedBeat = beat;
ball_.dispensing = true;
kicker.ball = ball_;
kicker.dispenserBeat = beat;
kicker.kickTimes = 0;
} }
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("spaceSoccer/dispenseNoise", beat),
new MultiSound.Sound("spaceSoccer/dispenseTumble1", beat + 0.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2", beat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2B",beat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble3", beat + 0.75f),
new MultiSound.Sound("spaceSoccer/dispenseTumble4", beat + 1f),
new MultiSound.Sound("spaceSoccer/dispenseTumble5", beat + 1.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6", beat + 1.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6B",beat + 1.75f),
});
} }
} }

View file

@ -257,7 +257,7 @@ namespace RhythmHeavenMania
new GameAction("keep-up", delegate { }, 4f, true), new GameAction("keep-up", delegate { }, 4f, true),
new GameAction("high kick-toe!", delegate { }, 3f, false, new List<Param>() new GameAction("high kick-toe!", delegate { }, 3f, false, new List<Param>()
{ {
new Param("swing", new EntityTypes.Float(0, 1), "Swing") new Param("swing", new EntityTypes.Float(0, 1, 0.5f), "Swing")
}), }),
}), }),
new Minigame("djSchool", "DJ School", "008c97", false, false, new List<GameAction>() new Minigame("djSchool", "DJ School", "008c97", false, false, new List<GameAction>()