-
Notifications
You must be signed in to change notification settings - Fork 0
/
pause.py
105 lines (96 loc) · 3.63 KB
/
pause.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
# Scripts:
from base_state import BaseState
from submenus import Options, Controls, audio
from sound import menu_bg, menu_selection, menu_back
from bg_creator import *
# Modules:
import pygame
from text_creator import TextCreator
class Pause(BaseState):
def __init__(self):
super().__init__()
# Screen Text and Options:
self.screen = "PAUSE"
self.options_qty = 2
self.text = ["RESUME", "OPTIONS", "BACK TO MENU"]
self.pause = []
for index, text in enumerate(self.text):
self.pause.append(
TextCreator(index, text, self.font_type, 48, 52, self.base_color, self.hover_color, self.pos,
self.text[0], 70))
# Initialize Objects:
self.background = BGCreator(*BACKGROUNDS['level_1'])
self.options = Options()
self.controls = Controls()
def handle_action(self):
if self.screen == "PAUSE":
if self.index == 0:
self.next_state = "LEVEL_1"
self.screen_done = True
pygame.mixer.music.unpause()
elif self.index == 1:
self.screen = "OPTIONS"
self.index = 0
menu_selection.play_sound()
elif self.index == 2:
self.next_state = "MENU"
self.screen_done = True
self.index = 0
menu_selection.play_sound()
pygame.mixer.music.stop()
menu_bg.play_bg_music(-1)
elif self.screen == "OPTIONS":
if self.index == 0:
self.screen = "AUDIO"
self.index = 0
self.options_qty = 2
menu_selection.play_sound()
elif self.index == 1:
self.screen = "CONTROLS"
self.index = 0
self.options_qty = 0
menu_selection.play_sound()
elif self.index == 2:
self.screen = "PAUSE"
self.index = 1
menu_back.play_sound()
elif self.screen == "AUDIO":
self.screen = "OPTIONS"
self.index = 0
self.options_qty = 2
menu_back.play_sound()
elif self.screen == "CONTROLS":
self.screen = "OPTIONS"
self.index = 1
self.options_qty = 2
menu_back.play_sound()
def get_event(self, event):
# Pause Menu Movement:
if event.type == pygame.KEYDOWN:
if event.key in [pygame.K_DOWN, pygame.K_s]:
self.handle_movement(1)
elif event.key in [pygame.K_UP, pygame.K_w]:
self.handle_movement(-1)
elif event.key == pygame.K_RETURN:
self.handle_action()
elif event.key in [pygame.K_LEFT, pygame.K_a] and self.screen == "AUDIO":
self.handle_left_audio(audio)
elif event.key in [pygame.K_RIGHT, pygame.K_d] and self.screen == "AUDIO":
self.handle_right_audio(audio)
# Pointer Movement Boundaries:
if self.index > self.options_qty:
self.index = 0
elif self.index < 0:
self.index = self.options_qty
def draw(self, surface):
# Draw Background
self.background.draw()
# Render Pause Menu:
if self.screen == "PAUSE":
self.render_options(self.pause)
elif self.screen == "OPTIONS":
self.render_options(self.options.options)
elif self.screen == "AUDIO":
self.render_options(audio.audio)
elif self.screen == "CONTROLS":
self.render_options(self.controls.controls)