proper spawn
This commit is contained in:
parent
33086b860a
commit
8bd2a93750
|
@ -22,7 +22,6 @@ namespace HeavenStudio.Games.Loaders
|
|||
{
|
||||
new GameAction("ball", "Ball")
|
||||
{
|
||||
function = delegate { var e = eventCaller.currentEntity; BouncyRoad.instance.SpawnBall(e.beat, e.length, e["goal"], e["color"]); },
|
||||
defaultLength = 1f,
|
||||
resizable = true,
|
||||
parameters = new List<Param>()
|
||||
|
@ -57,6 +56,17 @@ namespace HeavenStudio.Games
|
|||
|
||||
[SerializeField] float fallY;
|
||||
|
||||
const double BALL_SEEK_TIME = 1.0;
|
||||
private struct ScheduledBall
|
||||
{
|
||||
public double beat;
|
||||
public double length;
|
||||
public bool goal;
|
||||
public Color color;
|
||||
}
|
||||
List<ScheduledBall> scheduledBalls = new();
|
||||
int ballIndex;
|
||||
|
||||
public static BouncyRoad instance;
|
||||
|
||||
const int IALeft = 0;
|
||||
|
@ -143,6 +153,35 @@ namespace HeavenStudio.Games
|
|||
CurveCache.Add(1, newCurves);
|
||||
}
|
||||
|
||||
public override void OnGameSwitch(double beat)
|
||||
{
|
||||
double gameStartBeat = beat, gameEndBeat = double.MaxValue;
|
||||
var firstEnd = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame", "end" }).Find(x => x.beat > gameStartBeat);
|
||||
gameEndBeat = firstEnd?.beat ?? gameEndBeat;
|
||||
|
||||
|
||||
scheduledBalls.Clear();
|
||||
ballIndex = 0;
|
||||
var events = EventCaller.GetAllInGameManagerList("bouncyRoad", new string[] { "ball" }).FindAll(x => x.beat >= gameStartBeat && x.beat < gameEndBeat);
|
||||
foreach (var e in events)
|
||||
{
|
||||
if (e.length == 0) continue;
|
||||
var ball = new ScheduledBall
|
||||
{
|
||||
beat = e.beat,
|
||||
length = e.length,
|
||||
goal = e["goal"],
|
||||
color = e["color"],
|
||||
};
|
||||
scheduledBalls.Add(ball);
|
||||
}
|
||||
scheduledBalls.Sort((x, y) => x.beat.CompareTo(y.beat));
|
||||
}
|
||||
public override void OnPlay(double beat)
|
||||
{
|
||||
OnGameSwitch(beat);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var cond = Conductor.instance;
|
||||
|
@ -156,6 +195,26 @@ namespace HeavenStudio.Games
|
|||
{
|
||||
ThingsAnim[13].Play("podium", 0, 0);
|
||||
}
|
||||
|
||||
UpdateBalls();
|
||||
}
|
||||
|
||||
void UpdateBalls()
|
||||
{
|
||||
double beat = conductor.songPositionInBeatsAsDouble;
|
||||
while(ballIndex < scheduledBalls.Count)
|
||||
{
|
||||
var ball = scheduledBalls[ballIndex];
|
||||
if (ball.beat - ball.length < beat + BALL_SEEK_TIME)
|
||||
{
|
||||
SpawnBall(ball.beat, ball.length, ball.goal, ball.color);
|
||||
ballIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnBall(double beat, double length, bool goal, Color color)
|
||||
|
|
Loading…
Reference in a new issue