-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.py
More file actions
66 lines (49 loc) · 1.79 KB
/
ui.py
File metadata and controls
66 lines (49 loc) · 1.79 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
"""UI module"""
import os
import pygame
from decorators import log_decorator
from enums import GameType
@log_decorator
def show_menu(screen):
"""Main game menu"""
font = pygame.font.Font(None, 36)
menu_options = ["1: Single player game",
"2: Cooperative game",
"ESC: Ukončení"]
screen.fill((43, 28, 88))
for i, option in enumerate(menu_options):
text = font.render(option, True, (255, 255, 255))
screen.blit(text, (270, 320 + i * 40))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return "quit"
if event.type == pygame.KEYDOWN:
if event.key == 49:
return GameType.SINGLE
if event.key == 50:
return GameType.COOP
if event.key == pygame.K_ESCAPE:
return "quit"
def show_splash(screen):
"""Init splash screen"""
bg_path = os.path.join("assets", "sprites", "background", "intro.png")
background = pygame.image.load(bg_path).convert()
background = pygame.transform.scale(background, screen.get_size())
screen.blit(background, (0, 0))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
return
def show_end_message(screen, message):
font = pygame.font.SysFont(None, 60)
text = font.render(message, True, (255, 255, 255))
rect = text.get_rect(center=(screen.get_width() // 2, screen.get_height() // 2))
screen.fill((0, 0, 0))
screen.blit(text, rect)
pygame.display.flip()
pygame.time.wait(3000)