-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
39 lines (32 loc) · 1.63 KB
/
Copy pathmenu.py
File metadata and controls
39 lines (32 loc) · 1.63 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
import sys
import pygame
from constants import SCREEN_HEIGHT, SCREEN_WIDTH
def menu(screen, clock, game_over=False, score=0):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if pygame.key.get_pressed()[pygame.K_RETURN]:
return
if pygame.key.get_pressed()[pygame.K_q]:
sys.exit()
screen.fill("black")
title_font = pygame.font.Font(None, 74)
font = pygame.font.Font(None, 50)
if game_over:
title_text = title_font.render("Game Over", True, (255, 255, 255))
title_text_location = title_text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4))
score_text = font.render(f"Score: {score}", True, (255, 255, 255))
score_text_location = score_text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3))
screen.blit(score_text, score_text_location)
text = font.render("press enter to play again or q to quit", True, (255, 255, 255))
text_location = text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
else:
title_text = title_font.render("Start Menu", True, (255, 255, 255))
title_text_location = title_text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4))
text = font.render("press enter to start or q to quit", True, (255, 255, 255))
text_location = text.get_rect(center=(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
screen.blit(title_text, title_text_location)
screen.blit(text, text_location)
pygame.display.flip()
clock.tick(20)