Reputation: 441
I am making a pacman style game in pygame using python and i am trying to make it so that when the player
collides with an enemy sprite (monster
) the score gets reduced by 1. The code for the monster and player are below and also the code i have tried to minus the score. Any help would be appreciated. I can post the whole game code if this will help.
The code i have tried to minus the player lives when colliding with a monster is below.
for monster in group:
if player.rect.colliderect(monster.rect):
player.lives -= 1
Upvotes: 2
Views: 233
Reputation: 7026
I suspect the problem is that you only create livestext
at the beginning. The should be re-created each time you print it on the screen.
You seem to be drawing the text right at the end, after the game (why then?). So move the livestext=...
line to before the blit
. The lives may well be doing what you want, but perhaps you can't see it?
Also, I'd recommend making lives
an instance member:
Do self.lives=5
in the __init__
and use self.lives
instead of lives
every time it occurs.
Upvotes: 1