I’m writing skeeball controller software for my SkeeBall Model H (game thread here: http://forum.arcadecontrols.com/index.php/topic,156300.0.html).
I’m trying to figure out the best way to develop something like a queue of game actions that i want to happen one after the other, but I’m having some issues figuring out the best way to signal “completeness”.
A simple example is something like this:
public class SomeSkeeballGame {
private int _ballsLeft = 1
private BonusWheel _wheel;
...
private void Initialize()
{
_wheel = new BonusWheel(...);
_wheel.SpinCompleted += SpinCompleted;
Components.Add(_wheel);
}
private void SpinCompleted(object sender, SpinCompletedEventArgs e)
{
if(e.IsBomb)
{
PlayBombSoundEffect();
GameState.Score = 0;
}
else
{
GameState.Score += e.BonusPoints;
}
}
protected override void Update(GameTime gameTime)
{
switch(GameState.Status)
{
if(_ballsLeft == 0 || GameStatus.TimeLeft == 0)
{
CheckHighScore();
EndGame();
}
case GameStatus.InProgress:
{
if(CheckKey(Keys.Hole40))
{
SpinBonusWheel();
_ballsLeft--;
}
}
}
}
If the user throws a skeeball and hits the 40 pocket, spin a bonus wheel and apply the score. Problem is, they way it’s written, the ball count will be deducted when the pocket is scored, and the bonus wheel will spin, but on the very next update cycle the high score screen will be displayed before the bonus wheel has spun and was scored.
Sure, I can think of hacks like set a flag and check it in the bonus wheel “spin completed” event, but that’s very non-generic.
There are other games where I want things to happen first. LIke:
If the user hits a pocket
Play an animation… WHEN THIS IS COMPLETELY DONE
Play a sound … and light up an indicator … WHEN THE SOUND IS COMPLETELY DONE
Either end the game or subtract a ball depending on the status.
So I want some kind of queued game action system when I can queue up events and have them play through until no more are left. I’ve designed soemthing like this, but I’m having trouble figuring out how to signal that an event has finished, when an event might be made up of multiple asynchronous calls that all need to finish before the next action in the queue is processing.
Any suggestions along these lines?