Game actions that take multiple frames to complete
- by CantTetris
I've never really done much game programming before, pretty straightforward question.
Imagine I'm building a Tetris game, with the main loop looking something like this.
for every frame
handle input
if it's time to make the current block move down a row
if we can move the block
move the block
else
remove all complete rows
move rows down so there are no gaps
if we can spawn a new block
spawn a new current block
else
game over
Everything in the game so far happens instantly - things are spawned instantly, rows are removed instantly etc. But what if I don't want things to happen instantly (i.e animate things)?
for every frame
handle input
if it's time to make the current block move down a row
if we can move the block
move the block
else
?? animate complete rows disappearing (somehow, wait over multiple frames until the animation is done)
?? animate rows moving downwards (and again, wait over multiple frames)
if we can spawn a new block
spawn a new current block
else
game over
In my Pong clone this wasn't an issue, as every frame I was just moving the ball and checking for collisions.
How can I wrap my head around this issue? Surely most games involves some action that takes more than a frame, and other things halt until the action is done.