-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_over.py
51 lines (37 loc) · 1.62 KB
/
game_over.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
import pygame as pg
from button import Button
from constants import consts as c
from text import Text
def game_over(screen, score):
title = Text(c.screen_width // 2, c.screen_height // 2 - 100, "Cascade of Words", screen)
title.set_font(c.style_font)
score_text = Text(c.screen_width // 2, c.screen_height // 2, f"Your score: {score}", screen)
score_text.set_font(c.word_font)
restart_button = Button(c.screen_width // 2 - 100, c.screen_height // 2 + 100, 100, 50, screen, "Restart")
quit_button = Button(c.screen_width // 2 + 100, c.screen_height // 2 + 100, 100, 50, screen, "Quit")
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
return "exit"
if event.type == pg.KEYDOWN:
if event.key == pg.K_ESCAPE:
return "exit"
if event.type == pg.MOUSEMOTION:
mouse_pos = pg.mouse.get_pos()
restart_button.update(mouse_pos)
quit_button.update(mouse_pos)
if event.type == pg.MOUSEBUTTONDOWN:
mouse_pos = pg.mouse.get_pos()
click = event.button
restart_button.check_clicked(mouse_pos, click)
quit_button.check_clicked(mouse_pos, click)
if restart_button.left_clicked:
return "restart"
if quit_button.left_clicked:
return "exit"
screen.fill(c.bg_color)
title.render()
score_text.render()
restart_button.render()
quit_button.render()
pg.display.flip()