Im trying to set a score in a game Im programming in python/pygame.
My score works when I have something like:
global score
score = 0
Pseudo:
if player_rect.coliderect(baddie_rect):
score +=1
Then I display the score to the screen.
But I want to use this score in a function of another class. Where that function is called in the main class.
so
in collision function I would like to increment the score, which is in a player class. but I would like to print the score in the main class. I have something like this using shortened code:
class player:
.
.
.
global score
score = 0
def __init(self):
self.score=0
def get_score(self):
return self.score
def set_score(self, score):
self.score = score
def collision():
.
.
if player_rect.coliderect(baddie_rect):
self.score +=1
When I try to get the score when a collision occurs:
class main():
player = player()
player.colision()
print player.get_score()
Nothing happens, the score doesnt increment!
Any suggestions?