-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncher.py
More file actions
209 lines (169 loc) · 8.76 KB
/
Launcher.py
File metadata and controls
209 lines (169 loc) · 8.76 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
### ====================================================================================================
### IMPORTS
### ====================================================================================================
import arcade
from process import Process
import os
### ====================================================================================================
### CONSTANTS
### ====================================================================================================
TITLE = "Arcade Mini-Game !"
### ====================================================================================================
### GAME CLASS
### ====================================================================================================
class MyGame(arcade.Window):
BUTTON_NAMES = ["A",
"B",
"X",
"Y",
"LB",
"RB",
"VIEW",
"MENU",
"LSTICK",
"RSTICK",
None,
None,
None,
None,
None,
None,
]
# ----------------------------------
# PRIVATE METHODS FOR INPUT MANAGEMENT
# ----------------------------------
def __onButtonPressed(self, _gamepad, button):
idx = self.gamepads[_gamepad]
self.onButtonPressed(idx, MyGame.BUTTON_NAMES[button])
def __onButtonReleased(self, _gamepad, button):
idx = self.gamepads[_gamepad]
self.onButtonReleased(idx, MyGame.BUTTON_NAMES[button])
def __onCrossMove(self, _gamepad, x, y):
idx = self.gamepads[_gamepad]
self.onCrossMove(idx, x, -y)
def __onAxisMove(self, _gamepad, axis, value):
idx = self.gamepads[_gamepad]
self.onAxisMove(idx, axis, value)
# ----------------------------------
# CONSTRUCTOR
# ----------------------------------
def __init__(self, width, height, title):
#init application window
super().__init__(width, height, title)
# init process object
self.process = Process()
# set application window background color
arcade.set_background_color(arcade.color.BOTTLE_GREEN)
# Store gamepad list
self.gamepads = arcade.get_joysticks()
# check every connected gamepad
if self.gamepads:
for g in self.gamepads:
#link all gamepad callbacks to the current class methods
g.open()
g.on_joybutton_press = self.__onButtonPressed
g.on_joybutton_release = self.__onButtonReleased
g.on_joyhat_motion = self.__onCrossMove
g.on_joyaxis_motion = self.__onAxisMove
# transform list into a dictionary to get its index faster
self.gamepads = { self.gamepads[idx]:idx for idx in range(len(self.gamepads)) }
else:
print("There are no Gamepad connected !")
self.gamepads = None
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# SETUP your game here
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def setup(self):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.setup()
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# DRAW your game elements here
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_draw(self):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
arcade.start_render()
self.process.draw()
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# UPDATE your game model here
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def update(self, delta_time):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.update(delta_time)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# KEY PRESSED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_key_press(self, key, modifiers):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# Close application if ESCAPE key is hit
if key == arcade.key.ESCAPE:
self.close()
self.process.onKeyEvent(key,True)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# KEY RELEASED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_key_release(self, key, modifiers):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.onKeyEvent(key,False)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# GAMEPAD BUTTON PRESSED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def onButtonPressed(self, gamepadNum, buttonNum):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.onButtonEvent(gamepadNum,buttonNum,True)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# GAMEPAD BUTTON RELEASED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def onButtonReleased(self, gamepadNum, buttonNum):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.onButtonEvent(gamepadNum,buttonNum,False)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# GAMEPAD CROSSPAD events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def onCrossMove(self, gamepadNum, xValue, yValue):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
self.process.onAxisEvent(gamepadNum, "x", xValue)
self.process.onAxisEvent(gamepadNum, "y", yValue)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# GAMEPAD AXIS events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def onAxisMove(self, gamepadNum, axisName, analogValue):
#- - - - - - - - - - - - - - - - - - - - - - - - -#
if axisName == "z":
analogValue = -analogValue
self.process.onAxisEvent(gamepadNum,axisName.upper(),analogValue)
#- - - - - - - - - - - - - - - - - - - - - - - - -#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# MOUSE MOTION events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_mouse_motion(self, x, y, dx, dy):
self.process.onMouseMotionEvent(x,y,dx,dy)
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# MOUSE BUTTON PRESSED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_mouse_press(self, x, y, button, modifiers):
self.process.onMouseButtonEvent(x,y,button,True)
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# MOUSE BUTTON RELEASED events
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
def on_mouse_release(self, x, y, button, modifiers):
self.process.onMouseButtonEvent(x,y,button,False)
### ====================================================================================================
### MAIN PROCESS
### ====================================================================================================
def main():
# add current file path
file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_path)
game = MyGame(Process.SCREEN_WIDTH, Process.SCREEN_HEIGHT, TITLE)
game.setup()
arcade.run()
if __name__ == "__main__":
main()