-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
153 lines (104 loc) · 6.25 KB
/
main.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from sys import exit
import pygame
from ui_elements import *
from parameters import *
import beginning
pygame.init()
# Define cursors
arrow_cursor = pygame.SYSTEM_CURSOR_ARROW
hand_cursor = pygame.SYSTEM_CURSOR_HAND
# ═══════════════════════════════════════════════════════════════════════════ #
# ═══ IMAGES ════════════════════════════════════════════════════════════════ #
background = pygame.image.load("assets/main_menu/background.png")
background = pygame.transform.scale(background, (WIDTH, HEIGHT))
main_title_image = pygame.image.load("assets/main_menu/main_title_image.png")
title_rect = main_title_image.get_rect(center=(WIDTH // 2, HEIGHT // 5))
new_game_image = pygame.image.load("assets/main_menu/new_game_image.png")
new_game_rect = new_game_image.get_rect(center=(WIDTH // 2, HEIGHT // 1.5))
load_game_image = pygame.image.load("assets/main_menu/load_game_image.png")
load_game_rect = load_game_image.get_rect(center=(WIDTH // 2, HEIGHT // 1.3))
exit_game_image = pygame.image.load("assets/main_menu/exit_game_image.png")
exit_game_rect = exit_game_image.get_rect(center=(WIDTH // 2, HEIGHT // 1.15))
# ═══════════════════════════════════════════════════════════════════════════ #
# ═══ SHIMMER FUNCTION ══════════════════════════════════════════════════════ #
""" Initialize shimmer progress """
shimmer_progress_new = 0
shimmer_progress_load = 0
shimmer_progress_exit = 0
# Check if cursor is over images (used to reset hover shimmer effect)
hovered_new = False
hovered_load = False
hovered_exit = False
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ GAME LOOP ═════════════════════════════════════════════════════════════════════════════════════════════════════════ #
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
exit()
# Continue arrow button
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
if is_hovered(new_game_rect):
beginning.start_beginning(screen)
elif is_hovered(load_game_rect):
pass
elif is_hovered(exit_game_rect):
running = False
screen.blit(background, (0, 0)) # Display background image
screen.blit(main_title_image, title_rect) # Display Title text image
screen.blit(new_game_image, new_game_rect) # Display New Game text image
screen.blit(load_game_image, load_game_rect) # Display Load Game text image
screen.blit(exit_game_image, exit_game_rect) # Display Exit Game text image
cursor_changed = False # Set default state of system cursor
# ═══ ↓↓↓ Main Menu buttons with shimmer effects ↓↓↓ ══════════════════════════════════════ #
# ─── ▼ 'New Game' button shimmer effect ▼ ──────────────────────────────────── #
if is_hovered(new_game_rect):
if not hovered_new:
shimmer_progress_new = 0
hovered_new = True
if shimmer_progress_new < 1:
shimmer_progress_new += 0.01
draw_shimmer(screen, new_game_rect, shimmer_progress_new)
""" Change to 'hand' cursor when hovering over a selectable item """
pygame.mouse.set_cursor(hand_cursor)
cursor_changed = True
else:
hovered_new = False
# ─── ▲ 'New Game' button shimmer effect ▲ ──────────────────────────────────── #
# ─── ▼ 'Load Game' button shimmer effect ▼ ─────────────────────────────────── #
if is_hovered(load_game_rect):
if not hovered_load:
shimmer_progress_load = 0
hovered_load = True
if shimmer_progress_load < 1:
shimmer_progress_load += 0.01
draw_shimmer(screen, load_game_rect, shimmer_progress_load)
""" Change to 'hand' cursor when hovering over a selectable item """
pygame.mouse.set_cursor(hand_cursor)
cursor_changed = True
else:
hovered_load = False
# ─── ▲ 'Load Game' button shimmer effect ▲ ─────────────────────────────────── #
# ─── ▼ 'Exit Game' button shimmer effect ▼ ─────────────────────────────────── #
if is_hovered(exit_game_rect):
if not hovered_exit:
shimmer_progress_exit = 0
hovered_exit = True
if shimmer_progress_exit < 1:
shimmer_progress_exit += 0.01
draw_shimmer(screen, exit_game_rect, shimmer_progress_exit)
""" Change to 'hand' cursor when hovering over a selectable item """
pygame.mouse.set_cursor(hand_cursor)
cursor_changed = True
else:
hovered_exit = False
if not cursor_changed:
""" Change to 'arrow' cursor when not hovering over a selectable item """
pygame.mouse.set_cursor(arrow_cursor)
# ─── ▲ 'Exit Game' button shimmer effect ▲ ─────────────────────────────────── #
# ═══ ↑↑↑ Main Menu buttons with shimmer effects ↑↑↑ ══════════════════════════════════════ #
pygame.display.flip()
pygame.quit()