OnSpawnBall reimplemented

This commit is contained in:
Rapandrasmus 2023-06-13 13:52:15 +02:00
parent a14aacc181
commit 0a92b7bd69

View file

@ -26,6 +26,7 @@ namespace HeavenStudio.Games.Loaders
defaultLength = 0.5f, defaultLength = 0.5f,
priority = 1, priority = 1,
inactiveFunction = delegate { var e = eventCaller.currentEntity; WorkingDough.OnSpawnBallInactive(e.beat, false); }, inactiveFunction = delegate { var e = eventCaller.currentEntity; WorkingDough.OnSpawnBallInactive(e.beat, false); },
function = delegate { var e = eventCaller.currentEntity; WorkingDough.instance.OnSpawnBall(e.beat, false); }
}, },
new GameAction("big ball", "Big Ball") new GameAction("big ball", "Big Ball")
{ {
@ -33,10 +34,12 @@ namespace HeavenStudio.Games.Loaders
defaultLength = 0.5f, defaultLength = 0.5f,
priority = 1, priority = 1,
inactiveFunction = delegate { var e = eventCaller.currentEntity; WorkingDough.OnSpawnBallInactive(e.beat, true); }, inactiveFunction = delegate { var e = eventCaller.currentEntity; WorkingDough.OnSpawnBallInactive(e.beat, true); },
function = delegate { var e = eventCaller.currentEntity; WorkingDough.instance.OnSpawnBall(e.beat, true); }
}, },
new GameAction("passTurn", "Pass Turn") new GameAction("passTurn", "Pass Turn")
{ {
function = delegate { WorkingDough.instance.PassTurn(eventCaller.currentEntity.beat); } preFunction = delegate { WorkingDough.PrePassTurn(eventCaller.currentEntity.beat); },
preFunctionLength = 1
}, },
new GameAction("launch spaceship", "Launch Spaceship") new GameAction("launch spaceship", "Launch Spaceship")
{ {
@ -151,6 +154,7 @@ namespace HeavenStudio.Games
public bool bigMode; public bool bigMode;
public bool bigModePlayer; public bool bigModePlayer;
static List<QueuedBall> queuedBalls = new List<QueuedBall>(); static List<QueuedBall> queuedBalls = new List<QueuedBall>();
static List<double> passedTurns = new List<double>();
struct QueuedBall struct QueuedBall
{ {
public double beat; public double beat;
@ -264,7 +268,19 @@ namespace HeavenStudio.Games
crHandlerInstance.StartInterval(beat, interval); crHandlerInstance.StartInterval(beat, interval);
} }
public void PassTurn(double beat) public static void PrePassTurn(double beat)
{
if (GameManager.instance.currentGame == "workingDough")
{
instance.PassTurn(beat);
}
else
{
passedTurns.Add(beat);
}
}
private void PassTurn(double beat)
{ {
if (crHandlerInstance.queuedEvents.Count > 0) if (crHandlerInstance.queuedEvents.Count > 0)
{ {
@ -272,29 +288,29 @@ namespace HeavenStudio.Games
ballTransporterLeftPlayer.GetComponent<Animator>().Play("BallTransporterLeftOpen", 0, 0); ballTransporterLeftPlayer.GetComponent<Animator>().Play("BallTransporterLeftOpen", 0, 0);
foreach (var ball in crHandlerInstance.queuedEvents) foreach (var ball in crHandlerInstance.queuedEvents)
{ {
SpawnPlayerBall(beat + ball.relativeBeat, ball.tag == "big"); SpawnPlayerBall(beat + ball.relativeBeat - 1, ball.tag == "big");
} }
crHandlerInstance.queuedEvents.Clear(); crHandlerInstance.queuedEvents.Clear();
BeatAction.New(instance.gameObject, new List<BeatAction.Action>() BeatAction.New(instance.gameObject, new List<BeatAction.Action>()
{ {
new BeatAction.Action(beat + 1, delegate new BeatAction.Action(beat, delegate
{ {
if (crHandlerInstance.queuedEvents.Count > 0) if (crHandlerInstance.queuedEvents.Count > 0)
{ {
foreach (var ball in crHandlerInstance.queuedEvents) foreach (var ball in crHandlerInstance.queuedEvents)
{ {
SpawnPlayerBall(beat + ball.relativeBeat, ball.tag == "big"); SpawnPlayerBall(beat + ball.relativeBeat - 1, ball.tag == "big");
} }
crHandlerInstance.queuedEvents.Clear(); crHandlerInstance.queuedEvents.Clear();
} }
}), }),
new BeatAction.Action(beat + crHandlerInstance.intervalLength + 2, delegate { if (!crHandlerInstance.IntervalIsActive()) ballTransporterLeftNPC.GetComponent<Animator>().Play("BallTransporterLeftClose", 0, 0); }), new BeatAction.Action(beat + crHandlerInstance.intervalLength + 1, delegate { if (!crHandlerInstance.IntervalIsActive()) ballTransporterLeftNPC.GetComponent<Animator>().Play("BallTransporterLeftClose", 0, 0); }),
new BeatAction.Action(beat + crHandlerInstance.intervalLength + 2, delegate { if (!crHandlerInstance.IntervalIsActive()) ballTransporterRightNPC.GetComponent<Animator>().Play("BallTransporterRightClose", 0, 0); }), new BeatAction.Action(beat + crHandlerInstance.intervalLength + 1, delegate { if (!crHandlerInstance.IntervalIsActive()) ballTransporterRightNPC.GetComponent<Animator>().Play("BallTransporterRightClose", 0, 0); }),
new BeatAction.Action(beat + crHandlerInstance.intervalLength + 2, delegate { if (gandwHasEntered) gandwAnim.Play("MrGameAndWatchLeverDown", 0, 0); }), new BeatAction.Action(beat + crHandlerInstance.intervalLength + 1, delegate { if (gandwHasEntered) gandwAnim.Play("MrGameAndWatchLeverDown", 0, 0); }),
//Close player transporters //Close player transporters
new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 2, delegate { ballTransporterLeftPlayer.GetComponent<Animator>().Play("BallTransporterLeftClose", 0, 0); }), new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 1, delegate { ballTransporterLeftPlayer.GetComponent<Animator>().Play("BallTransporterLeftClose", 0, 0); }),
new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 2, delegate { ballTransporterRightPlayer.GetComponent<Animator>().Play("BallTransporterRightClose", 0, 0); }), new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 1, delegate { ballTransporterRightPlayer.GetComponent<Animator>().Play("BallTransporterRightClose", 0, 0); }),
new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 2, delegate { new BeatAction.Action(beat + crHandlerInstance.intervalLength * 2 + 1, delegate {
if (bigModePlayer) if (bigModePlayer)
{ {
PlayerBallTransporters.GetComponent<Animator>().Play("PlayerExitBigMode", 0, 0); PlayerBallTransporters.GetComponent<Animator>().Play("PlayerExitBigMode", 0, 0);
@ -307,7 +323,6 @@ namespace HeavenStudio.Games
public void SpawnBall(double beat, bool isBig) public void SpawnBall(double beat, bool isBig)
{ {
crHandlerInstance.AddEvent(beat, 0, isBig ? "big" : "small");
var objectToSpawn = isBig ? bigBallNPC : smallBallNPC; var objectToSpawn = isBig ? bigBallNPC : smallBallNPC;
var spawnedBall = GameObject.Instantiate(objectToSpawn, ballHolder); var spawnedBall = GameObject.Instantiate(objectToSpawn, ballHolder);
@ -340,11 +355,6 @@ namespace HeavenStudio.Games
}); });
} }
public void OnSpawnBall(double beat, bool isBig)
{
}
public static void PreSpawnBall(double beat, bool isBig) public static void PreSpawnBall(double beat, bool isBig)
{ {
double spawnBeat = beat - 1f; double spawnBeat = beat - 1f;
@ -385,6 +395,11 @@ namespace HeavenStudio.Games
crHandlerInstance.AddEvent(beat, 0, isBig ? "big" : "small"); crHandlerInstance.AddEvent(beat, 0, isBig ? "big" : "small");
} }
public void OnSpawnBall(double beat, bool isBig)
{
crHandlerInstance.AddEvent(beat, 0, isBig ? "big" : "small");
}
public static void InactiveInterval(double beat, float interval) public static void InactiveInterval(double beat, float interval)
{ {
if (crHandlerInstance == null) if (crHandlerInstance == null)
@ -470,6 +485,14 @@ namespace HeavenStudio.Games
} }
queuedBalls.Clear(); queuedBalls.Clear();
} }
if (passedTurns.Count > 0)
{
foreach (var passTurn in passedTurns)
{
PassTurn(passTurn);
}
passedTurns.Clear();
}
if (PlayerInput.Pressed() && !IsExpectingInputNow(InputType.STANDARD_DOWN)) if (PlayerInput.Pressed() && !IsExpectingInputNow(InputType.STANDARD_DOWN))
{ {
doughDudesPlayer.GetComponent<Animator>().Play("SmallDoughJump", 0, 0); doughDudesPlayer.GetComponent<Animator>().Play("SmallDoughJump", 0, 0);