I'm trying to create a turn-based game in pyGame but hit a wall when trying to properly handle the main game loop. So I have something like this:
def loop(self): while self.stategame==1: for event in pygame.event.get(): if event.type == QUIT \ or (event.type == KEYDOWN and event.key == K_ESCAPE): self.stategame = 0 if self.isPlayerTurn: self.events() else: self.enemyTurn() self.draw_map() pygame.display.flip()
The enemyTurn() function here is called multiple times after each player's move causing the enemies to move multiple tiles before the player does anything again. I'm a beginner in gamedev do I don't know how to overcome this and, in the first place, why does it hapen. Isn't the code supposed to be analyzed from top to bottom like in regular Python so that the enemyTurn() is called just once and then the game goes back to waiting for user input? How can I solve this problem and call the enemyTurn() just once each time the player makes a move?