-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreboard.py
More file actions
42 lines (34 loc) · 1.37 KB
/
Copy pathScoreboard.py
File metadata and controls
42 lines (34 loc) · 1.37 KB
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
import pygame.sprite
import pygame
import Hardcodes
class Scoreboard(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
pygame.sprite.Sprite.__init__(self)
# Init lives and score
self.Lives = Hardcodes.startLives
self.Score = 0
# Import the font and make it UI
self.font = pygame.font.Font("Singkong.ttf", 40)
self.layer = 1
self.image = pygame.Surface((0, 0), pygame.SRCALPHA)
self.image.fill(pygame.Color(0, 0, 0, 0))
self.rect = self.image.get_rect()
def update(self, dt):
# A very long program to put together two images
image1 = self.font.render(f"Lives: {self.Lives}", True, (255, 0, 0))
image2 = self.font.render(f"Score: {self.Score}", True, (0, 0, 255))
height = image1.get_height() + image2.get_height()
width = max(image1.get_width(), image2.get_width())
self.image = pygame.Surface((width, height), pygame.SRCALPHA)
self.image.fill(pygame.Color(0, 0, 0, 0))
self.rect = self.image.get_rect()
self.rect.x = 0
self.rect.y = 0
self.image.blit(image1, (0, 0))
self.image.blit(image2, (0, image1.get_height()))
def addScore(self, t, num): # Useless, but I still use it :)
if t == "Score":
self.Score += num
elif t == "Lives":
self.Lives += num