When I play test on linux, everything is fine, but on my windows machine, I can’t go diagonally down and to the left (but can go the other three diagonals).
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
self.running = False
if event.type == KEYDOWN:
if event.key == K_SPACE:
self.player.shooting = True
if event.key == K_UP:
self.player.moving.add("forward")
if event.key == K_DOWN:
self.player.moving.add("back")
if event.key == K_RIGHT:
self.player.moving.add("right")
if event.key == K_LEFT:
self.player.moving.add("left")
if event.type == KEYUP:
if event.key == K_SPACE:
self.player.shooting = False
if event.key == K_UP:
self.player.moving.remove("forward")
if event.key == K_DOWN:
self.player.moving.remove("back")
if event.key == K_RIGHT:
self.player.moving.remove("right")
if event.key == K_LEFT:
self.player.moving.remove("left")
Here’s the update method that does the moving:
def update (self, time_passed):
tp = time_passed # From clock.tick(60)
if self.moving:
if "forward" in self.moving and (self.rect.top > 0):
self.rect.move_ip(0, -self.speed*tp)
if "back" in self.moving and (self.rect.bottom < self.screen_ref[1]):
self.rect.move_ip(0, self.speed*tp)
if "left" in self.moving and (self.rect.left > 0):
self.rect.move_ip(-self.speed*tp, 0)
if "right" in self.moving and (self.rect.right < self.screen_ref[0]):
self.rect.move_ip(self.speed*tp, 0)
I checked just now to double check I didn’t break anything confirmed. Diagonally down and to the left doesn’t work. I either start going down and then change to moving left, are start off going left and change to moving down. Anyone have any ideas why?
If this code works on Linux I’d expect it to work exactly the same in Windows. Problems like this are often related to hardware limitations of the keyboard.
Did you use exactly the same setup for both tests, specifically the keyboard? If you used the same keyboard for both tests, I’d be inclined to blame the Windows drivers.
Before you blame the code, make sure that you can press those two keys at once and get the expected result. Fire up a flash game or something for a quick test.