-2
class Player():
    def __init__(self, x, y):
        self.reset(x,y)

    def update(self, game_over):
        
        dx = 0
        dy = 0
        
        walk_cooldown = 4

        if game_over == 0:
            key = pygame.key.get_pressed()
            if key[pygame.K_SPACE] and self.jumped == False and level != 3:
                self.vel_y = -15
                self.jumped = True
                self.counter += 1
Tom Karzes
  • 22,815
  • 2
  • 22
  • 41

1 Answers1

-1

Your code should look like this

class Player(): 
   def __init__(self, x, y): 
      self.reset(x,y)

   def update(self, game_over):
    
      dx = 0
      dy = 0
    
      walk_cooldown = 4

      if game_over == 0:
          key = pygame.key.get_pressed()
          if key[pygame.K_SPACE]:
              if self.jumped == False and level != 3:
                  self.vel_y = -15
                  self.jumped = True
                  self.counter += 1
              elif self.jumped == True and self.counter == 1 and level != 3:
                  self.vel_y = -15
                  self.jumped = True
                  self.counter += 1

          if self.y = 0:
              self.counter = 0
              self.vel_y = 0
          # this is to reset the self.counter so you can jump and double jump again when you hit the ground, self.y = 0 might be wrong so you might need to change that
        self.x += self.vel_x
        self.y += self.vel_y


tygzy
  • 698
  • 1
  • 6
  • 23
  • This is all assuming you actually initiated your class variables and didn't just not include them for some reason. – tygzy Jun 27 '23 at 22:06