forked from oahassan/way-of-the-stick
/
main.py
executable file
·194 lines (157 loc) · 7.52 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import sys
import os
import multiprocessing
# sys.stderr = open("logfile.txt","w")
# sys.stdout = open("logfile_out.txt","w")
import pygame
from pygame.locals import *
pygame.mixer.pre_init(frequency=44100, size=-16, channels=3, buffer=4096)
pygame.init()
pygame.font.init()
import wotsrendering
import wotsuievents
import animationexplorer
import actionwizard
import movebuilder
import frameeditor
import menupage
import versusmode
import keybinding
import movesetbuilder
import movesetselect
import versusmovesetselect
import onlineversusmode
import onlineversusmovesetselect
import onlineversusmovesetselectloader
import onlinemenupage
import onlinematchloader
import controlspage
import chat
import splash
import volume
import music
import versusclient
import versusserver
import stageselect
import credits
import serverselect
import gamestate
import serializability
if __name__ == "__main__":
multiprocessing.freeze_support()
gamestate.init_pygame_vars()
screen = gamestate.screen
pygame.display.set_caption("Way of the Stick")
music.init()
if len(sys.argv) >= 2 and sys.argv[1] == "dev":
gamestate.devmode = True
while 1:
try:
if gamestate.drawing_mode == gamestate.DrawingModes.UPDATE_ALL:
screen.fill((0,0,0))
gamestate.update_time()
wotsuievents.get_events()
events = wotsuievents.events
event_types = wotsuievents.event_types
mousePos = wotsuievents.mouse_pos
mouseButtonsPressed = wotsuievents.mouse_buttons_pressed
music.update()
if pygame.QUIT in event_types:
if (versusmode.local_state != None and
versusmode.local_state.simulation_process != None):
if versusmode.local_state.simulation_process.is_alive():
print("terminating!")
if versusmode.local_state.simulation_connection != None:
versusmode.local_state.simulation_connection.send('STOP')
else:
versusmode.local_state.simulation_process.terminate()
versusmode.local_state.simulation_process.join()
sys.exit()
elif pygame.K_ESCAPE in wotsuievents.keys_pressed:
if (versusmode.local_state != None and
versusmode.local_state.simulation_process != None):
if versusmode.local_state.simulation_process.is_alive():
print("terminating!")
if versusmode.local_state.simulation_connection != None:
versusmode.local_state.simulation_connection.send('STOP')
else:
versusmode.local_state.simulation_process.terminate()
versusmode.local_state.simulation_process.join()
sys.exit()
elif gamestate.mode == gamestate.Modes.FRAMEEDITOR:
frameeditor.handle_events(screen, \
mousePos, \
mouseButtonsPressed, \
events)
elif gamestate.mode == gamestate.Modes.ANIMATIONEXPLORER:
animationexplorer.handle_events(screen, \
mousePos, \
mouseButtonsPressed, \
events)
elif gamestate.mode == gamestate.Modes.MAINMENU:
menupage.handle_events()
elif gamestate.mode == gamestate.Modes.VERSUSMODE:
if versusmode.initialized() == False:
versusmode.init()
versusmode.handle_events()
elif gamestate.mode == gamestate.Modes.SETTINGSMODE:
volume.handle_events()
elif gamestate.mode == gamestate.Modes.MOVEBUILDER:
movebuilder.handle_events()
elif gamestate.mode == gamestate.Modes.MOVESETBUILDER:
movesetbuilder.handle_events()
elif gamestate.mode == gamestate.Modes.KEYBINDING:
keybinding.handle_events()
elif gamestate.mode == gamestate.Modes.MOVESETSELECT:
movesetselect.handle_events()
elif gamestate.mode == gamestate.Modes.VERSUSMOVESETSELECT:
versusmovesetselect.handle_events()
elif gamestate.mode == gamestate.Modes.ONLINEVERSUSMODE:
onlineversusmode.handle_events()
chat.handle_events()
elif gamestate.mode == gamestate.Modes.ONLINEVERSUSMOVESETSELECT:
onlineversusmovesetselect.handle_events()
chat.handle_events()
elif gamestate.mode == gamestate.Modes.ONLINEVERSUSMOVESETSELECTLOADER:
onlineversusmovesetselectloader.handle_events()
elif gamestate.mode == gamestate.Modes.ONLINEMATCHLOADER:
onlinematchloader.handle_events()
chat.handle_events()
elif gamestate.mode == gamestate.Modes.ONLINEMENUPAGE:
onlinemenupage.handle_events()
elif gamestate.mode == gamestate.Modes.SERVERSELECT:
serverselect.handle_events()
elif gamestate.mode == gamestate.Modes.CONTROLSPAGE:
controlspage.handle_events()
elif gamestate.mode == gamestate.Modes.SPLASH:
splash.handle_events()
elif gamestate.mode == gamestate.Modes.STAGESELECT:
stageselect.handle_events()
elif gamestate.mode == gamestate.Modes.CREDITS:
credits.handle_events()
if gamestate.drawing_mode == gamestate.DrawingModes.UPDATE_ALL:
pygame.display.flip()
elif gamestate.drawing_mode == gamestate.DrawingModes.DIRTY_RECTS:
wotsrendering.flush()
gamestate.update_screen()
if gamestate.hosting:
versusserver.pump()
gamestate.clock.tick(gamestate.frame_rate)
except Exception as err:
print("Unexpected error:", str(err))
if (versusmode.local_state != None and
versusmode.local_state.simulation_process != None):
if versusmode.local_state.simulation_process.is_alive():
print("terminating!")
if versusmode.local_state.simulation_connection != None:
versusmode.local_state.simulation_connection.send('STOP')
else:
versusmode.local_state.simulation_process.terminate()
versusmode.local_state.simulation_process.join()
elif (onlineversusmode.local_state != None and
onlineversusmode.local_state.simulation_process != None):
if onlineversusmode.local_state.simulation_process.is_alive():
print("terminating!")
onlineversusmode.local_state.simulation_process.terminate()
#onlineversusmode.local_state.simulation_process.join()
raise