-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
85 lines (66 loc) · 2.73 KB
/
Copy pathsettings.py
File metadata and controls
85 lines (66 loc) · 2.73 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
80
81
82
83
84
85
DIFFICULTIES = ["Easy", "Medium", "Hard"]
import pygame
class SettingsScreen:
def __init__(self, width, height):
self.width = width
self.height = height
self.bg_color = (0, 0, 0)
self.text_color = (255, 255, 255)
self.font_title = pygame.font.SysFont("arial", 32, bold=True)
self.font_hint = pygame.font.SysFont("arial", 18)
# Difficulty
self.selected_difficulty = "Easy" #default
self.diff_buttons = {}
start_y = 180
for i, diff in enumerate(DIFFICULTIES):
self.diff_buttons[diff] = pygame.Rect(
self.width // 2 - 90,
start_y + i * 60,
180,
40
)
# Back button
self.back_rect = pygame.Rect(30, 30, 80, 35)
def draw(self, screen):
screen.fill(self.bg_color)
# Title
title = self.font_title.render("Settings", True, self.text_color)
screen.blit(
title,
title.get_rect(center=(self.width // 2, 80))
)
# Difficulty ui
label = self.font_hint.render("Select Difficulty", True, (200, 200, 200))
screen.blit(label, label.get_rect(center=(self.width // 2, 140)))
for diff, rect in self.diff_buttons.items():
if diff == self.selected_difficulty:
color = (80, 160, 220) # active
else:
color = (60, 60, 60) # inactive
pygame.draw.rect(screen, color, rect, border_radius=8)
text = self.font_hint.render(diff, True, (255, 255, 255))
screen.blit(text, text.get_rect(center=rect.center))
# Back button
pygame.draw.rect(screen, (60, 60, 60), self.back_rect, border_radius=6)
back_text = self.font_hint.render("Back", True, self.text_color)
screen.blit(
back_text,
back_text.get_rect(center=self.back_rect.center)
)
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
if self.back_rect.collidepoint(event.pos):
return ("back", self.selected_difficulty)
for diff, rect in self.diff_buttons.items():
if rect.collidepoint(event.pos):
self.selected_difficulty = diff
return ("difficulty", diff)
return (None, None)
def resize(self, width, height):
self.width = width
self.height = height
# Recalculate difficulty buttons
start_y = self.height // 2 - 60
for i, diff in enumerate(self.diff_buttons):
self.diff_buttons[diff].x = self.width // 2 - 90
self.diff_buttons[diff].y = start_y + i * 60