-
Notifications
You must be signed in to change notification settings - Fork 0
/
beginning_wheel_changing.py
124 lines (84 loc) · 7.36 KB
/
beginning_wheel_changing.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
import os
from sys import exit
import pygame
from ui_elements import *
from parameters import *
import beginning_night_cruising
# Define cursors
arrow_cursor = pygame.SYSTEM_CURSOR_ARROW
hand_cursor = pygame.SYSTEM_CURSOR_HAND
# ═══════════════════════════════════════════════════════════════════════════ #
# ═══ GIF ANIMATION FUNCTION ════════════════════════════════════════════════ #
def load_frames(folder, prefix):
frames = []
for filename in sorted(os.listdir(folder)):
if filename.startswith(prefix):
img = pygame.image.load(os.path.join(folder, filename))
frames.append(img)
return frames
# ═══════════════════════════════════════════════════════════════════════════ #
# ═══ LEVEL IMAGES, DIALOGUE TEXT, AND GAME LOOP ════════════════════════════ #
def changing_wheel(screen):
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ SHIMMER FUNCTION ══════════════════════════════════════════════════════════════════════════════════════════════ #
shimmer_progress_continue = 0
hovered_continue = False
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ DIALOGUE TEXT ═════════════════════════════════════════════════════════════════════════════════════════════════ #
font = pygame.font.Font("assets/arial.ttf", 20)
wheel_change_text = "So, your initial cruise towards your dream hit a snag as you ran across something in the road which blew your tire. Fortunately, you had a spare for such an eventuality and quickly break out some basic tools to change out your wheel."
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ ANIMATION ═════════════════════════════════════════════════════════════════════════════════════════════════════ #
""" Define image frames for animation """
frames = load_frames("assets/wheel_change/", "frame_")
frame_count = len(frames)
current_frame = 0
""" Timing for frame updates """
frame_delay = 100 # milliseconds before displaying next frame in sequence
last_update = pygame.time.get_ticks()
""" Get rect from first image frame to position animation """
wheel_change_rect = frames[0].get_rect(center=(screen.get_width() // 2, screen.get_height() // 1.5))
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ 'CONTINUE' ARROW ══════════════════════════════════════════════════════════════════════════════════════════════ #
continue_arrow = pygame.image.load("assets/continue_arrow.png")
continue_arrow_rect = continue_arrow.get_rect(bottomright=(screen.get_width() // 1.005, screen.get_height() // 1.01))
# ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════ #
# ═══ GAME LOOP ═════════════════════════════════════════════════════════════════════════════════════════════════════ #
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
if is_hovered(continue_arrow_rect):
beginning_night_cruising.night_cruising(screen)
# ─── ▼ Display all necessary images and text ▼ ───────────────────────────── #
screen.fill((0, 0, 0))
now = pygame.time.get_ticks()
if now - last_update > frame_delay:
current_frame = (current_frame + 1) % frame_count
last_update = now
screen.blit(frames[current_frame], wheel_change_rect.topleft)
screen.blit(continue_arrow, continue_arrow_rect.topleft)
text_wrap(screen, wheel_change_text, (screen.get_width() // 10, screen.get_height() // 5), font, WHITE, screen.get_width() - screen.get_width() // 5)
# ─── ▲ Display all necessary images and text ▲ ───────────────────────────── #
# ─── ▼ 'Continue' arrow shimmer effect ▼ ─────────────────────────────────── #
cursor_changed = False
if is_hovered(continue_arrow_rect):
if not hovered_continue:
shimmer_progress_continue = 0
hovered_continue = True
if shimmer_progress_continue < 1:
shimmer_progress_continue += 0.007
draw_shimmer(screen, continue_arrow_rect, shimmer_progress_continue)
pygame.mouse.set_cursor(hand_cursor)
cursor_changed = True
else:
hovered_continue = False
if not cursor_changed:
pygame.mouse.set_cursor(arrow_cursor)
# ─── ▲ 'Continue' arrow shimmer effect ▲ ─────────────────────────────────── #
pygame.display.flip()
pygame.quit()