-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay_functions.py
110 lines (99 loc) · 3.1 KB
/
display_functions.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pygame
import config as cfg
def display_text(screen, text, font, color, x, y):
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.center = (x, y)
screen.blit(text_surface, text_rect)
def draw_screen(screen, win_counts, screen_color=cfg.black, outline_color=cfg.white):
screen.fill(screen_color) # Fill the screen with black color
pygame.draw.rect(
screen,
cfg.white,
(0, 0, cfg.screen_width - cfg.score_section_width, cfg.screen_height),
5,
)
pygame.display.set_caption("Curve Fever")
# Draw the score section
pygame.draw.rect(
screen,
cfg.black,
(
cfg.screen_width - cfg.score_section_width,
0,
cfg.score_section_width,
cfg.screen_height,
),
)
pygame.draw.rect(
screen,
cfg.white,
(0, 0, cfg.screen_width - cfg.score_section_width, cfg.screen_height),
5,
)
pygame.draw.rect(
screen, outline_color, (0, 0, cfg.screen_width, cfg.screen_height), 5
)
# Display win counts
for player_id, win_count in win_counts.items():
player_text = f"Player {player_id}: {win_count} wins"
display_text(
screen,
player_text,
font=cfg.font,
color=cfg.white,
x=cfg.screen_width - cfg.score_section_width + 90,
y=20 + player_id * 20,
)
return screen
def draw_players(players, screen):
for player in players:
pygame.draw.circle(screen, player["color"], player["pos"], cfg.player_size // 2)
if player["gap"]:
pygame.draw.circle(
screen, cfg.black, player["pos_history"][1], cfg.player_size // 2
)
prev_pos = None
for pos, gap in zip(player["pos_history"], player["gap_history"]):
if gap:
prev_pos = None
continue
if prev_pos is not None:
pygame.draw.line(
screen,
player["color"],
prev_pos,
pos,
cfg.player_size,
)
prev_pos = pos
def display_winner(screen, win_counts):
# Clear the score section
pygame.draw.rect(
screen,
cfg.black,
(
cfg.screen_width - cfg.score_section_width,
0,
cfg.score_section_width,
cfg.screen_height,
),
)
pygame.draw.rect(screen, cfg.white, (0, 0, cfg.screen_width, cfg.screen_height), 5)
pygame.draw.rect(
screen,
cfg.white,
(0, 0, cfg.screen_width - cfg.score_section_width, cfg.screen_height),
5,
)
# Display win counts
for player_id, win_count in win_counts.items():
player_text = f"Player {player_id}: {win_count} wins"
display_text(
screen,
player_text,
font=cfg.font,
color=cfg.white,
x=cfg.screen_width - cfg.score_section_width + 90,
y=20 + player_id * 20,
)