-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscore.py
More file actions
86 lines (67 loc) · 2.37 KB
/
score.py
File metadata and controls
86 lines (67 loc) · 2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pygame, spritesheet
from itertools import cycle
from config import *
class Text(object):
def __init__(self, textFont, size, message, color, xpos, ypos):
self.font = pygame.font.Font(textFont, size)
self.surface = self.font.render(message, True, color)
self.rect = self.surface.get_rect(topleft=(xpos, ypos))
self.width = self.surface.get_width()
self.height = self.surface.get_height()
def draw(self, surface):
surface.blit(self.surface, self.rect)
pass
class Score(pygame.sprite.Sprite):
score = 0
bonuslife = True
@staticmethod
def addpoints(points):
Score.score += points
if Score.score >= BONUS_LIFE_SCORE and Score.bonuslife:
event = pygame.event.Event(BONUS_LIFE)
pygame.event.post(event)
Score.bonuslife = False
def __init__(self,color):
super(Score,self).__init__()
self.scorecolor = color
def update(self):
tmp = '{:>7}'.format(Score.score)
# FIX THIS SHOULD BE BASED ON FONT SIZE
text = Text(FONT, 20, tmp, self.scorecolor, 60, SCREEN_HEIGHT - BORDERTHICKNESS - WALLTHICKNESS )
self.image = text.surface
self.rect = text.rect
def draw(self):
pass
class Bonus(pygame.sprite.Sprite):
def __init__(self, color, bonus):
super(Bonus,self).__init__()
Score.addpoints(bonus)
bonus = 'BONUS {:3d}'.format(bonus)
text = Text(FONT, 20, bonus, color, (SCREEN_WIDTH/5)*2, SCREEN_HEIGHT - BORDERTHICKNESS - WALLTHICKNESS)
self.image = text.surface
self.rect = text.rect
def update(self):
pass
def draw(self):
pass
class gameFPS(pygame.sprite.Sprite):
clock = 0
color = BLACK
displayIterator = cycle(range(2))
display = displayIterator.next()
@staticmethod
def toggleDisplay():
gameFPS.display = gameFPS.displayIterator.next()
def __init__(self,color=BLACK):
super(gameFPS,self).__init__()
gameFPS.color = color
def update(self):
color = BLACK
if gameFPS.display == True:
color = gameFPS.color
fps = "FPS: {:.2f}".format(gameFPS.clock)
text = Text(FONT,12,fps,color,SCREEN_WIDTH - 90, SCREEN_HEIGHT - BORDERTHICKNESS)
self.image = text.surface
self.rect = text.rect
def draw(self):
pass