1
\$\begingroup\$

I have a turn based combat system where all monsters act one turn, then all players, etc. The combat mechanics are completely deterministic - I can pre-calculate the outcome of a turn.

I'm interested if I should do all calculations ahead of time (monster A will be at X, monster B will be at Y), and then just play a bunch of animations based on these calculations:

  1. (Calculate for A)
  2. (Calculate for B)
  3. (Animate A move to X)
  4. (Animate B move to Y)

OR do one animation per calculation?

  1. (Calculate for A)
  2. (Animate A move to X)
  3. (Calculate for B)
  4. (Animate B move to Y)
\$\endgroup\$
4
\$\begingroup\$

This is primarily just a design decision. Consider that you can actually do these things at the same time. If you look at the situation in terms of your update loop:

 Update 1: 
   Calculate outcome for entity: n
   Play animation: n (frame 1)
 Update 2:
   Calculate outcome for entity: n+1
   Play animation: n (frame 2) and n+1 (frame 1)
 Update 3:
   Calculate outcome for entity: n+2
   Play animation: n (frame 3) and n+1 (frame 2) and n+2 (frame 1)
 Update 4:
   Calculate outcome for entity: none left
   Play animation: n (frame 4) and n+1 (frame 3) and n+2 (frame 2) 

Alternatively, if you can calculate the outcome very quickly, you can do all the entities in the first update, then spend the rest of your updates playing animations.

The reason I say it's mostly a design decision is because the only reasons to do it one way or the other is the requirements of your project or your design preference. In these situations it's usually best to just pick a method you think will work and go with it. Trying something out will help you learn if it was a good choice and give you much more information about the situation. It also often opens up alternatives that you didn't know existed until you tried implementing something.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.