I am making a game with pygame, and i ran into a issue with a function to remove apples from trees. this function does not deal with creating apples, only removing them, but apples only appear if i have a print statement in the function to remove apples.
I tried replacing the print statement with other simple ststements, like creating a variable, but it only works with print.
here is the code:
def damage(self):
# damaging the tree
self.health -= 1
print('- hp')
# remove an apple
if len(self.apple_sprites.sprites()) > 0:
print('apple')
random_apple = choice(self.apple_sprites.sprites())
random_apple.kill()
here is the function to create apples:
def create_fruit(self):
for pos in self.apple_pos:
if randint(0, 10) < 2:
x = pos[0] + self.rect.left
y = pos[1] + self.rect.top
Generic((x, y), self.apple_surf, [self.apple_sprites, self.groups()[0]], z=LAYERS['fruit'])
Abigail FS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.