-
Notifications
You must be signed in to change notification settings - Fork 0
/
HUD.py
52 lines (42 loc) · 1.97 KB
/
HUD.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pygame
class Text():
def __init__(self, pos, text = "", textSize = 12, textColor=(25,55,5), font = None):
self.text = text
self.textColor = textColor
self.font = pygame.font.Font(font, textSize)
self.image = self.font.render(self.text, 1, textColor)
self.rect = self.image.get_rect()
self.place(pos)
def place(self, pos):
self.rect.center = pos
def setText(self, text):
self.text = text
self.image = self.font.render(text, 1, textColor)
self.rect = self.image.get_rect(center = self.rect.center)
def update(self, width, height):
pass
class Score(Text):
def __init__(self, pos, baseText = "Score: ", textSize = 12, textColor=(255,255,255), font = None):
self.score = 0
self.baseText = baseText
self.text = self.baseText + str(self.score)
Text.__init__(self, pos, self.text, textSize, textColor, font)
self.change = False
def setText(self, text):
self.baseText = text
self.change = True
def update(self):
if self.change:
self.text = self.baseText + str(self.score)
self.image = self.font.render(self.text, 1, self.textColor)
self.rect = self.image.get_rect(center = self.rect.center)
self.change = False
def setScore(self, score):
self.score = score
self.change = True
def increaseScore(self, amount = 1):
self.score += amount
self.change = True
def resetScore(self):
self.score = 0
self.change = True