Search code examples
pythonpython-3.xpygamegame-loop

How to implement turns while still executing the main loop?


I am creating a trading game in Python, and want to know how to implement turns without pausing the gameloop. I know that I will have to change the way movement is implemented, but how would I do that?

Note: code can be reached here (May be old): http://pastebin.com/rZbCXk5i


Solution

  • This is usually done with something called a game state machine

    What that is, is extremely simple. I can show you with an example.

    def main_game_loop():
        if state == "player_turn":
            # logic for player's turn
        elif state == "enemy_turn":
            # logic for enemy's turn
        # they can also be used for other things, such as where you are in the game
        elif state == "paused":
            # pause logic etc etc