-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySprites.py
84 lines (73 loc) · 2.8 KB
/
mySprites.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
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
class white_key(pygame.sprite.Sprite):
"""
Class for all the white keys on the screen
determines the colour of the keys and where
they should be
"""
def __init__(self,x,screen):
self.screen = screen
self.x = x
pygame.sprite.Sprite.__init__(self)
def draw(self,boolean):
if boolean: self.key = pygame.draw.rect(self.screen, (255,0,0), pygame.Rect(self.x,686,70,214))
else: self.key = pygame.draw.rect(self.screen, (255,255,255), pygame.Rect(self.x,686,70,214))
class bar_notes(pygame.sprite.Sprite):
"""
Controls the speed of the barnotes and the display of them
"""
def __init__(self,coloumn,row,size,screen):
self.size = size
self.screen = screen
self.location = [coloumn,row]
pygame.sprite.Sprite.__init__(self)
def draw(self,speed):
self.location[1] += speed
pygame.draw.rect(self.screen,(0,0,0),pygame.Rect(self.location[0],self.location[1], self.size[0], self.size[1] ) )
class black_key(pygame.sprite.Sprite):
"""
Class for all the black keys on the screen
determines the colour of the keys and where
they should be
"""
def __init__(self,x,screen):
self.screen = screen
self.x = x
pygame.sprite.Sprite.__init__(self)
def draw(self,boolean):
if boolean: self.key = pygame.draw.rect(self.screen, (255,0,0), pygame.Rect(self.x,686,40,107))
else: self.key = pygame.draw.rect(self.screen, (0,0,0), pygame.Rect(self.x,686,40,107))
class score_board(pygame.sprite.Sprite):
"""
Calculates the score board of the current playing
and controls the highscore
"""
def __init__(self):
self.score = 0
def add_score(self,score=10):
self.score += score
def display(self,screen):
font = pygame.font.Font('freesansbold.ttf',20)
current_score = font.render(str(self.score), True,[255,0,0])
screen.blit(current_score, [450,850])
def end_screen(self,screen):
"""
When the game has ended this
plays (highscore is changed, score is displayed)
"""
file = open('highscore.txt','r')
high_score = int(file.read())
file.close()
print(high_score)
font = pygame.font.Font('freesansbold.ttf',20)
if high_score < self.score:
file = open('highscore.txt','w')
file.write(str(self.score))
file.close()
high_score = 'HIGHSCORE: {}'.format(high_score)
high_score = font.render(high_score, True,[255,0,0])
self.score = 'YOUR FINAL SCORE IS '+str(self.score)
self.score = font.render(self.score, True,[255,0,0])
screen.blit(self.score, [100,400])
screen.blit(high_score, [100,450])
pygame.display.flip()