I'm trying to build a "simple" Tetris game, but I want to have enough flexibility to add a few things:
The game can be played by a human, or (if the human presses a certain key) an AI is swapped in.
The rendering code should be "configurable". That is, the user may enable or disable animations, or speed them up.
MVC initially looks like a good fit: the game itself is encapsulated in a Game
object, providing some methods to interact with it (moveLeft
, rotate
). The Controller
would handle user input or AI. The View just renders the game, and gets notified of updates by the Game itself whenever something interesting happens (PieceMoved
, LineDestroyed
and so on).
However, my problem mostly lies in "What if I want a blocking animation?"
When lines are destroyed, I want to do a "falling" animation where the top lines crush the bottom lines (or whatever), but since this animation may take some time, I want to avoid updating the game (that is, piece gravity) until the animation is completed.
Does it make sense to have the Controller do something like...
void update() {
input.process()
render.update()
if (!render.blocked()) {
game.update();
}
}
Is MVC a bad fit for this? What's a good way to separate concerns in games?
(I am using libGDX, but my question isn't limited to it.)