How do you handle the separation of animation from the world state within a turn based game? I'm working on a 2D grid based game currently. The below code is simplified to better explain.
When an actor moves, I want to pause the flow of turns while the creature animates and moves to the new position. Otherwise, the screen could lag significantly behind the world state, which would cause weird visual appearance. I also want to have animations that don't block the flow of the game - a particle effect could unfold over multiple turns without affecting gameplay.
What I've done is introduce two types of animations, which I call blocking animations and non-blocking animations. When the player wants to move, the code that gets executed is
class Actor {
void move(PositionInfo oldPosition, PositionInfo newPosition) {
if(isValidMove(oldPosition, newPosition) {
getGame().pushBlockingAnimation(new MoveAnimation(this, oldPosition, newPosition, ....));
player.setPosition(newPosition);
}
}
}
Then the main update loop does:
class Game {
void update(float dt) {
updateNonBlockingAnimations(dt); //Effects like particle explosions, damage numbers, etc. Things that don't block the flow of turns.
if(!mBlockingAnimations.empty()) {
mBlockingAnimations.get(0).update(dt);
} else {
//.. handle the next turn. This is where new animations will be enqueued..//
}
cleanUpAnimations(); // remove finished animations
}
}
...where the animation updates the screen position of the Actor.
One other idea I am implementing is to have a concurrent blocking animation, where multiple blocking animations would be updated simultaneously, but the next turn wouldn't happen until all of them were done.
Does this seem like a sane way to do things? Does anyone have any suggestions, or even references to how other similar games do such a thing.