-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadScreen.py
117 lines (100 loc) · 4.13 KB
/
loadScreen.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
# Importing modules
import pygame
from sys import exit
import random
# Initialize the clock for controlling the frame rate
clock = pygame.time.Clock()
# List of loader values
loader = [1, 9, 27, 5, 0] # Bar speed controller
def load_screen(screen, scaling):
"""
Displays a series of loading screens before the game starts.
Args:
screen (pygame.Surface): The screen to display the loading screens on.
scaling (int): The scaling factor for adjusting image sizes.
Returns:
bool: True if the loading screens should continue, False if they should stop.
"""
# Load the background image for the loading screen
load_bg = pygame.image.load(f"graphics/{scaling}/load/loadBG_{screen.screen_mode}.png").convert()
# Fill the screen with black for 1 sec
screen.screen.fill("Black")
clock.tick(1)
# Blit the loading screen background onto the screen
screen.screen.blit(load_bg, (0,0))
pygame.display.update()
clock.tick(5)
# Check for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_f:
# Switch screen mode (fullscreen or windowed) when "f" key is pressed
if screen.screen_mode == 1:
screen.screen_mode = 2
else:
screen.screen_mode = 1
screen.display_init()
load_bg = pygame.image.load(f"graphics/{scaling}/load/loadBG_{screen.screen_mode}.png").convert()
return False
# Global variable for tracking the position of the loading bar
x = 0
def loading(screen, scaling):
"""
Displays a loading animation on the screen.
Args:
screen (pygame.Surface): The screen to display the loading animation on.
scaling (int): The scaling factor for adjusting image sizes.
Returns:
bool: True if the loading animation should continue, False if it should stop.
"""
global x
global loader
# Load the images for the loading animation
load_bg = pygame.image.load(f"graphics/{scaling}/load/loadBG_{screen.screen_mode}.png").convert()
loadbar = pygame.image.load(f"graphics/{scaling}/load/loadbar_{screen.screen_mode}.png").convert_alpha()
barRect = loadbar.get_rect(topright=(x, 0))
loadScreen = pygame.image.load(f"graphics/{scaling}/load/load_{screen.screen_mode}.png").convert_alpha()
# Update the loader value based on the position of the loading bar
if barRect.right > 1133:
loader[4] = loader[3]
elif barRect.right > 378:
loader[4] = loader[2]
elif barRect.right > 315:
loader[4] = loader[1]
elif barRect.right > 126:
loader[4] = loader[0]
else:
loader[4] = 100
# Move the loading bar to the right
if barRect.right <= screen.screen.get_width():
barRect.right += loader[4]
x = barRect.right
else:
return False
# Check for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_f:
# Switch screen mode (fullscreen or windowed) when "f" key is pressed
# All the assets are reloaded if the screen switches mode
if screen.screen_mode == 1:
screen.screen_mode = 2
else:
screen.screen_mode = 1
screen.display_init()
loadbar = pygame.image.load(f"graphics/{scaling}/load/loadbar_{screen.screen_mode}.png").convert_alpha()
loadScreen = pygame.image.load(f"graphics/{scaling}/load/load_{screen.screen_mode}.png").convert_alpha()
load_bg = pygame.image.load(f"graphics/{scaling}/load/loadBG_{screen.screen_mode}.png").convert()
screen.screen.blit(load_bg, (0, 0))
# Blit the loading bar and screen onto the screen
screen.screen.blit(loadbar, barRect.topleft)
screen.screen.blit(loadScreen, (0, 0))
pygame.display.update()
clock.tick(100)
return True