python - Random sprite movement, logic issue -


i trying have sprite (enemy) move in random directions around screen. enemy move x,y 500 frames move random direction.

my problem trying object hold direction each frame until counter reaches 500. instead, object changes direction every frame.

        if e_move_count <= 500:             e_xmove = random.randint(-1,1)             e_ymove = random.randint(-1,1)             self.enemy.move(e_xmove, e_ymove)             e_move_count += 1          if e_move_count >= 500:             e_xmove = random.randint(-1,1)             e_ymove = random.randint(-1,1)             self.enemy.move(e_xmove, e_ymove)             e_move_count = 0 

i know problem is, can't think of workaround. how stay in 1 direction without redefining x,y on each frame? open using timers if that's possible in python?

try changing this:

    if e_move_count <= 500:         self.enemy.move(e_xmove, e_ymove)         e_move_count += 1      if e_move_count >= 500:         e_xmove = random.randint(-1,1)         e_ymove = random.randint(-1,1)         self.enemy.move(e_xmove, e_ymove)         e_move_count = 0 

this way, direction change when e_move_count >= 500


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -