-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
317 lines (253 loc) · 10.2 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import arcade
import random
import time
class Game(arcade.Window):
"""
Main application class.
NOTE: Go ahead and delete the methods you don't need.
If you do need a method, delete the 'pass' and replace it
with your own code. Don't leave 'pass' in this program.
"""
def __init__(self, width, height, game_title):
super().__init__(width, height, game_title)
arcade.set_background_color(arcade.color.SKY_BLUE)
# If you have sprite lists, you should create them here,
# and set them to None
self.player_list = None
self.enten_list = None
self.time = 0.0
def setup(self):
self.SCREEN_WIDTH = self.width
self.SCREEN_HEIGHT = self.height
self.SCREEN_BOTTOM = 0
self.NAME_OF_THE_GAME = "Mallard Pursuit"
self.background = None
self.time = 0.0
self.menu = True # Variable die Bestimmt, ob das Menü angezeigt wird
# Don't show the mouse cursor
self.set_mouse_visible(False)
# Create your sprites and sprite lists here
# Sprite lists
self.player_list = arcade.SpriteList()
self.enten_list = arcade.SpriteList(use_spatial_hash=True)
# Score
#Bulletcount
self.bullets_in_magazine = 3
self.bullets_shot = 0
self.bullts_hit = 0
self.bullets_missed = 0
# Set up the player
self.player_sprite = arcade.Sprite("images/sprites/Absehen.png", 0.25)
self.player_list.append(self.player_sprite)
# Set up the Duck
#Todo: Der Sprite ist zu animieren.
self.enten_sprite =[]
self.enten_sprite = arcade.AnimatedTimeBasedSprite("images/sprites/Ente1/e0.png", 0.3)
for i in range(1, 4):
self.enten_sprite.append_texture(arcade.load_texture(f"images/sprites/Ente1/e{i}.png"))
self.enten_sprite.append_texture(arcade.load_texture(f"images/sprites/Ente1/e2.png"))
self.enten_sprite.append_texture(arcade.load_texture(f"images/sprites/Ente1/e1.png"))
self.enten_sprite_zaehler = 0
self.enten_sprite.center_x = 64
self.enten_sprite.center_y = 120
self.enten_list.append(self.enten_sprite)
self.enten_geschwindigkeit_x = 300
self.enten_geschwindigkeit_y = 150
self.entenanimationszeitkonstante = time.monotonic_ns()
#load sounds
self.mossberg = arcade.load_sound("sounds/Mossberg500.ogg")
self.walther = arcade.load_sound("sounds/Mein_Gott_Watlher.ogg")
self.mossberg_happy = arcade.load_sound("sounds/Mossberg500-happy.ogg")
self.Teckel = arcade.load_sound("sounds/Teckel.ogg")
self.nachladen = arcade.load_sound("sounds/reload.ogg")
#initialize stuff to reload
self.nachladezeitzeitkonstante = str
self.einmalschalter = True
#background music
self.music = arcade.load_sound("sounds/hintergrundgerausche.ogg")
arcade.play_sound(self.music, 0.25, 0.0, True)
#load background
self.background = arcade.load_texture("images/scenery/layer0.png")
self.layers = []
for i in range(0, 4):
self.layers.append(arcade.load_texture(f"images/scenery/layer{i}.png"))
#load Ammo
self.shotgunshells = arcade.load_texture("images/ammunition/shell.png")
def timerstand_bestimmen(self):
# Calculate minutes
minutes = int(self.time) // 60
# Calculate seconds by using a modulus (remainder)
seconds = int(self.time) % 60
# Figure out our output
self.timer = f"Time: {minutes:02d}:{seconds:02d}"
def on_draw(self):
"""
Render the screen.
"""
# This command should happen before we start drawing. It will clear
# the screen to the background color, and erase what we drew last frame.
arcade.start_render()
arcade.draw_texture_rectangle(
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2,
self.SCREEN_WIDTH,
self.SCREEN_HEIGHT,
self.background
)
## TODO: Wieso erscheint die Ente trotzdem vor den Layern?
self.enten_list.draw()
for i in range(1, len(self.layers)):
arcade.draw_texture_rectangle(
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2,
self.SCREEN_WIDTH,
self.SCREEN_HEIGHT,
self.layers[i])
for i in range(self.bullets_in_magazine):
arcade.draw_scaled_texture_rectangle(self.SCREEN_WIDTH - 30*i-20, 30, self.shotgunshells, 0.1)
###Hier wird der Timerstand bestimmt
self.timerstand_bestimmen()
# Output the timer text.
arcade.draw_text(
self.timer,
15,
self.SCREEN_HEIGHT - 50,
arcade.color.BURGUNDY,
font_size=30,
font_name=("OpenBars", 'calibri', "arial")
)
if self.menu:
arcade.draw_text(
self.NAME_OF_THE_GAME,
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2 + self.SCREEN_HEIGHT / 3,
(0, 0, 0,),
anchor_x="center",
font_size=100,
font_name=("OpenBars", 'calibri', "arial")
)
arcade.draw_text(
"Start Game",
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2 + self.SCREEN_HEIGHT / 3 - 240,
(0, 0, 0,),
anchor_x="center",
font_size=40,
font_name=("OpenBars", 'calibri', "arial")
)
arcade.draw_text(
"Credits",
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2 + self.SCREEN_HEIGHT / 3 - 340,
(0, 0, 0,),
anchor_x="center",
font_size=40,
font_name=("OpenBars", 'calibri', "arial")
)
arcade.draw_text(
"Exit",
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2 + self.SCREEN_HEIGHT / 3 - 440,
(0, 0, 0,),
anchor_x="center",
font_size=40,
font_name=("OpenBars", 'calibri', "arial")
)
arcade.draw_text(
"© C. Driebe & C. Macht 2021",
self.SCREEN_WIDTH / 2,
self.SCREEN_HEIGHT / 2 + self.SCREEN_HEIGHT / 3 - 740,
(255, 255, 255,),
anchor_x="center",
font_size=14,
font_name=('calibri', "arial")
)
self.enten_list.draw()
self.player_list.draw()
#### TODO: Zufällig Enten generieren uns spawnen lassen
#def entewuerfeln(self):
# zufall = random.randint(1, 6)
# if zufall == 6:
# self.enten_list.append(self.enten_sprite)
def on_update(self, delta_time):
"""
All the logic to move, and the game logic goes here.
Normally, you'll call update() on the sprite lists that
need it.
"""
self.time += delta_time
self.enten_sprite.center_x += self.enten_geschwindigkeit_x * delta_time
self.enten_sprite.center_y += self.enten_geschwindigkeit_y * delta_time
if self.enten_sprite.center_x + 1 > self.SCREEN_WIDTH:
self.enten_geschwindigkeit_x *= -1
elif self.enten_sprite.center_x + 1 <= 0:
self.enten_geschwindigkeit_x *= -1
if self.enten_sprite.center_y + 1 > self.SCREEN_HEIGHT:
self.enten_geschwindigkeit_y *= -1
elif self.enten_sprite.center_y + 1 <= 0:
self.enten_geschwindigkeit_y *= -1
if self.entenanimationszeitkonstante+75000000 <= time.monotonic_ns():
self.entenanimationszeitkonstante = time.monotonic_ns()
if self.enten_sprite_zaehler < 5:
self.enten_sprite_zaehler = self.enten_sprite_zaehler + 1
else:
self.enten_sprite_zaehler = 0
self.enten_sprite.set_texture(self.enten_sprite_zaehler)
def on_key_press(self, key, key_modifiers):
"""
Called whenever a key on the keyboard is pressed.
For a full list of keys, see:
http://arcade.academy/arcade.key.html
"""
if key == arcade.key.H:
arcade.play_sound(self.Teckel)
def on_key_release(self, key, key_modifiers):
"""
Called whenever the user lets off a previously pressed key.
"""
pass
def on_mouse_motion(self, x , y, delta_x, delta_y):
"""
Called whenever the mouse moves.
"""
self.player_sprite.center_x = x
self.player_sprite.center_y = y
def on_mouse_press(self, x, y, button, key_modifiers):
"""
Called when the user presses a mouse button.
"""
#TODO: Kadenz zwischen Schüssen
if button == arcade.MOUSE_BUTTON_LEFT:
position_letzter_linksklick = [x, y]
print("Letzter Linksklick: ", position_letzter_linksklick)
if self.bullets_in_magazine:
arcade.play_sound(self.mossberg_happy)
self.bullets_in_magazine = self.bullets_in_magazine -1
else:
#TODO: Klicksound muss her
#arcade.play_sound()
print("leer")
elif button == arcade.MOUSE_BUTTON_RIGHT:
if self.einmalschalter == True:
self.nachladezeitzeitkonstante = time.strftime("%S")
self.einmalschalter = False
#TODO: Kadenz zwischen Nachladern
#TODO: Interessante Spielvariante: Versagerpatronen
if self.bullets_in_magazine < 3:
print("Nachladen")
arcade.play_sound(self.nachladen)
while self.bullets_in_magazine < 3:
self.bullets_in_magazine = self.bullets_in_magazine + 1
def on_mouse_release(self, x, y, button, key_modifiers):
"""
Called when a user releases a mouse button.
"""
pass
def main():
""" Main method """
game_title = "Mallard Pursuit" # Denkbare Alternative: Hunt for Cocks # FederWild
game = Game(1920, 1000, game_title)
game.setup()
arcade.run()
if __name__ == "__main__":
main()