Skip to main content
Fixed the code.
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

ifIf you remove the part bellow, maybe it can work. I do this in the javascriptJavaScript game and worked, try it:

if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.left_is_down = False if self.right_is_down: self.speed_x = self.velocity else: self.speed_x = 0 if event.key == pygame.K_RIGHT: self.right_is_down = False if self.left_is_down: self.speed_x = -self.velocity else: self.speed_x = 0 if event.key == pygame.K_UP: self.up_is_down = False if self.down_is_down: self.speed_y = self.velocity else: self.speed_y = 0 if event.key == pygame.K_DOWN: self.down_is_down = False if self.up_is_down: self.speed_y = -self.velocity else: self.speed_y = 0

if event.type == pygame.KEYUP:
    if event.key == pygame.K_LEFT:
        self.left_is_down = False
        if self.right_is_down:
            self.speed_x = self.velocity
        else:
            self.speed_x = 0
    if event.key == pygame.K_RIGHT:
        self.right_is_down = False
        if self.left_is_down:
            self.speed_x = -self.velocity
        else:
            self.speed_x = 0
    if event.key == pygame.K_UP:
        self.up_is_down = False
        if self.down_is_down:
            self.speed_y = self.velocity
        else:
            self.speed_y = 0
    if event.key == pygame.K_DOWN:
        self.down_is_down = False
        if self.up_is_down:
            self.speed_y = -self.velocity
        else:
            self.speed_y = 0

if you remove the part bellow, maybe can work. I do this in the javascript game and worked, try it

if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.left_is_down = False if self.right_is_down: self.speed_x = self.velocity else: self.speed_x = 0 if event.key == pygame.K_RIGHT: self.right_is_down = False if self.left_is_down: self.speed_x = -self.velocity else: self.speed_x = 0 if event.key == pygame.K_UP: self.up_is_down = False if self.down_is_down: self.speed_y = self.velocity else: self.speed_y = 0 if event.key == pygame.K_DOWN: self.down_is_down = False if self.up_is_down: self.speed_y = -self.velocity else: self.speed_y = 0

If you remove the part bellow, maybe it can work. I do this in the JavaScript game and worked, try it:

if event.type == pygame.KEYUP:
    if event.key == pygame.K_LEFT:
        self.left_is_down = False
        if self.right_is_down:
            self.speed_x = self.velocity
        else:
            self.speed_x = 0
    if event.key == pygame.K_RIGHT:
        self.right_is_down = False
        if self.left_is_down:
            self.speed_x = -self.velocity
        else:
            self.speed_x = 0
    if event.key == pygame.K_UP:
        self.up_is_down = False
        if self.down_is_down:
            self.speed_y = self.velocity
        else:
            self.speed_y = 0
    if event.key == pygame.K_DOWN:
        self.down_is_down = False
        if self.up_is_down:
            self.speed_y = -self.velocity
        else:
            self.speed_y = 0
Source Link

if you remove the part bellow, maybe can work. I do this in the javascript game and worked, try it

if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.left_is_down = False if self.right_is_down: self.speed_x = self.velocity else: self.speed_x = 0 if event.key == pygame.K_RIGHT: self.right_is_down = False if self.left_is_down: self.speed_x = -self.velocity else: self.speed_x = 0 if event.key == pygame.K_UP: self.up_is_down = False if self.down_is_down: self.speed_y = self.velocity else: self.speed_y = 0 if event.key == pygame.K_DOWN: self.down_is_down = False if self.up_is_down: self.speed_y = -self.velocity else: self.speed_y = 0