« The new look of RogueRunner | Main | Input and User Commands »
Tuesday, September 29, 2009
Timing, Turns, and Speed
My first thoughts on turns and game timing were directed towards a priority queue of events. A creature takes a turn, then adds itself back on the queue for a later time. I thought about leveraging the queue for other things, like when hunger starts to take a toll, poisons that wear off over time, etc. But the more I go into coding it, I started to realize that efficiently managing that queue was going to be hard. So I decided to save myself the days and days of coding and testing and opted for a simpler solution.
Like many others I'm using an energy system, where the game has an internal loop, each loop being a sort of 'game turn'. Any object that takes actual turns will have an amount of energy added to it, and when a certain amount of energy is reached, that object takes an actual turn and loses some energy. What's nice is you can adjust how fast a creature gets to take a turn by adjusting the amount of energy they gain each 'game turn'.
My system uses a linear approach to speed. Currently, objects get 30 energy multiplied or divided by a speed factor each game turn, and they get a turn once they have at least 600 energy. The speed factor is 1.0 if the objects speed is 0. For speeds greater than zero, the 30 is multiply by 1.0 + 0.1 * speed. So +10 speed means you get 2X turns, +20 speed means you get 3X turns. For speeds less than zero, the factor is calculated the same, but the 30 is divided by it instead. So -10 speed means you get 1/2X turns and -20 means you get 1/3X turns.
|