i hope this is the right forum for my problem.
My problem is that i wrote a little "game" to get used to the SenseHat but the joystick and its functions aren't working as i thought they would do.
The Problem seems to be in this little function:
Code: Select all
def players_turn(array): win = True step = 1 while win == True and step <= level: direction = 0 step_taken = False while step_taken == False: for event in sense.stick.get_events(): if event.direction == "up": direction = 1 step_taken = True sense.load_image("up.png", redraw = True) sleep(1) sense.clear() elif event.direction == "down": direction = 2 step_taken = True sense.load_image("down.png", redraw = True) sleep(1) sense.clear() elif event.direction == "left": direction = 3 step_taken = True sense.load_image("left.png", redraw = True) sleep (1) sense.clear() elif event.direction == "right": direction = 4 step_taken = True sense.load_image("right.png", redraw = True) sleep(1) sense.clear() if direction == array[step-1]: step = step + 1 else: win = False return win
the function itself seems to work until it gets called the second time (in the second level). Then it seems to "save" the pressed direction from the first call and the player is not able to input something before the function stops.
my guess is that the get_events() function has some stored events that it gives out instead of getting new ones.
my guess of solution would be to clear that store events out of some kind of puffer where they got saved, but i found no way to do that.
I am not a pro at python so i would appreciate any suggestions to solve the problem and i would appreciate even more if you could explain what you do
thanks in advance