forked from kvyns/Float-Fall-Bouncing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathend.py
More file actions
60 lines (46 loc) · 1.97 KB
/
end.py
File metadata and controls
60 lines (46 loc) · 1.97 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
import pygame
import buttons
from sys import exit
def exit_screen(screen):
"""
Displays the exit screen and handles user interaction.
Args:
screen (Window): The Window object representing the game screen.
Returns:
bool: True if the user selects to exit, False if the user cancels the exit.
"""
# Initialize clock to control frame rate
clock = pygame.time.Clock()
# Calculate scaling factor based on desktop size
scaling = int((1920 / pygame.display.get_desktop_sizes()[0][0]) * 100)
# Get the size of the screen
size = screen.screen.get_size()
# Calculate scaling factor for adjusting positions and sizes
scale_2 = size[0] / 1920
# Load exit screen images
exit_screen = pygame.image.load(f"graphics/{scaling}/exit/exit_display_{screen.screen_mode}.png").convert_alpha()
cross = pygame.image.load(f"graphics/{scaling}/exit/cross_{screen.screen_mode}.png").convert_alpha()
yes = pygame.image.load(f"graphics/{scaling}/exit/yes_{screen.screen_mode}.png").convert_alpha()
# Create buttons
cross_button = buttons.Button(1208 * scale_2, 235 * scale_2, cross, 0)
yes_button = buttons.Button(847 * scale_2, 742 * scale_2, yes, 0)
# Blit exit screen image to the screen
screen.screen.blit(exit_screen, (632 * scale_2, 222 * scale_2))
# Main loop for handling user interaction
while True:
# Check if the "Yes" button is clicked
if yes_button.draw(screen.screen):
return False
# Check if the "Cross" button is clicked
if cross_button.draw(screen.screen):
return True
# Handle events
for event in pygame.event.get():
# If the user closes the window, quit the game
if event.type == pygame.QUIT:
pygame.quit()
exit()
# Update the display
pygame.display.update()
# Control the frame rate
clock.tick(30)