So im making a small game where you have to jump from platform to platform and i wanted to make a power up that gives you an extra jump. However when I pick up my power up it doesn't give an extra jump. I tried a bunch of things. I messed with the variables a lot and went over my code 100 times and I can't find the problem. Keep in mind im still very inexperienced and this basically my first project. Everything else is working fine I just don't understand why im not getting the extra jump.
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.surf = pygame.Surface((40, 60))
self.surf.fill((128, 255, 40))
self.rect = self.surf.get_rect()
self.pos = vec((200, 420))
self.vel = vec(0, 0)
self.acc = vec(0, 0)
self.score = 0
djenabled = False #this is the variable im using for my double jump#
.
.
.
.
#from my understanding it should be that if the variable is true and im in the air i should be able to jump again#
def djump(self):
hits = pygame.sprite.spritecollide(self, platforms, False)
if hits and djenabled == True:
self.djumping = True
self.vel.y = -15
.
.
.
.
#this is the code for the power up and when i pick it up my djenabled variable should be set to True#
class Djump_power(pygame.sprite.Sprite):
def __init__(self, pos):
super().__init__()
self.image = pygame.image.load('pfeil.png')
self.rect = self.image.get_rect()
self.rect.topleft = pos
def update(self):
if self.rect.colliderect(P.rect):
djenabled = True
self.kill()
I even tried using something like this. Basically the same thing but with self.dj I also tried combining the 2 of those and nothing seems to have worked. I really don't see the problem here if anyone could help me I would appreciate it.
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.surf = pygame.Surface((40, 60))
self.surf.fill((128, 255, 40))
self.rect = self.surf.get_rect()
self.pos = vec((200, 420))
self.vel = vec(0, 0)
self.acc = vec(0, 0)
self.score = 0
self.dj = 1
.
.
.
.
def djump(self):
hits = pygame.sprite.spritecollide(self, platforms, False)
if hits and self.dj == 0:
self.djumping = True
self.vel.y = -15
.
.
.
.
class Djump_power(pygame.sprite.Sprite):
def __init__(self, pos):
super().__init__()
self.image = pygame.image.load('pfeil.png')
self.rect = self.image.get_rect()
self.rect.topleft = pos
def update(self):
if self.rect.colliderect(P.rect):
self.dj = 0
self.kill()