-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.py
34 lines (24 loc) · 867 Bytes
/
score.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pygame
from locals import *
import util
class Score(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.score = 0
self.target_score = 0
self.font = util.load_font("Cosmetica", 14)
self.image = self.font.render("Score: 0", True, (10,10,10))
self.rect = self.image.get_rect()
self.rect.left = 100
self.rect.top = 5
def update(self):
if self.target_score > self.score:
self.score += 1
self.image = self.font.render("Score: " + str(self.score), True, (10,10,10))
self.rect.width = self.image.get_width()
self.rect.height = self.image.get_height()
def add(self, points):
self.target_score += points
self.update()
def get_score(self):
return self.target_score