-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpygameEndScreen.py
More file actions
79 lines (55 loc) · 2.44 KB
/
pygameEndScreen.py
File metadata and controls
79 lines (55 loc) · 2.44 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
import pygame
import pygame_gui
import highScores
def rotate(surface, angle):
rotated_surface = pygame.transform.rotozoom(surface, angle, 1)
rotated_rect = rotated_surface.get_rect(center = (400, 300))
return rotated_surface, rotated_rect
def youMatch(screen, final_time):
#Background code (might be temporary)
bg_img = pygame.image.load('otherbackground.jpg')
bg = pygame.transform.scale(bg_img, (800, 600))
# font needed to render the highscore text
font = pygame.font.SysFont('microsoftjhengheimicrosoftjhengheiuibold', 30)
endManager = pygame_gui.UIManager((800, 600))
back_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((50, 545), (150, 50)),
text='Back',
manager=endManager)
clock = pygame.time.Clock()
#Win message dimensions
size = 100
angle = 0
#Win message
phrase = pygame.font.SysFont('microsoftjhengheimicrosoftjhengheiuibold', size).render("Good Job!", False, (0,0,0))
while True:
time_delta = clock.tick(40)
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
# Handle the back button
if event.type == pygame.USEREVENT:
# If button is pressed
if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
# If start button, start
if event.ui_element == back_button:
return
endManager.process_events(event)
#Create rect for win message
phrase_rect = phrase.get_rect(center = (400, 300))
#Show background
screen.blit(bg, (0,0))
#Show user's time (rounded to 3 places)
screen.blit(font.render("Your Time: {:0.3f}".format(final_time), False, (0,0,0)), (270, 500))
#Display what position they ranked (if any)
topScore = font.render(highScores.displayTopScore, False, (0,0,0))
screen.blit(topScore,(220, 10))
#Rotate win message
angle += 1
phrase_rotated, phrase_rotated_rect = rotate(phrase, angle)
#Show the spinning win message
screen.blit(phrase_rotated, phrase_rotated_rect)
#Update manager (for the buttons)
endManager.update(time_delta)
#Display buttons
endManager.draw_ui(screen)
pygame.display.update()