forked from richstokes/cheekymonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheekymonkey.py
executable file
·621 lines (523 loc) · 26.6 KB
/
cheekymonkey.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
#!/usr/bin/env python3
import timeit
import os
import arcade
# from arcade.examples.frametime_plotter import FrametimePlotter
# from arcade import FrametimePlotter
from pyglet.gl import GL_NEAREST, GL_LINEAR
import pymunk
import logging
import math
import time
import threading
import argparse
from signal import signal, SIGINT
from create_level import create_level_1
from physics_utility import (
PymunkSprite,
check_grounding,
resync_physics_sprites,
)
from player_utility import Player
from constants import *
import constants
from k8s_kill_pod import *
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
def exit_handler(signal_received, frame):
# TODO: Handle cleanup here
logging.info('SIGINT or CTRL-C caught. Exiting game.')
exit(0)
class PhysicsSprite(arcade.Sprite):
def __init__(self, pymunk_shape, filename):
super().__init__(filename, center_x=pymunk_shape.body.position.x, center_y=pymunk_shape.body.position.y)
self.pymunk_shape = pymunk_shape
self.HITCOUNT = 0
class CircleSprite(PhysicsSprite):
def __init__(self, pymunk_shape, filename):
super().__init__(pymunk_shape, filename)
self.width = pymunk_shape.radius * 2
self.height = pymunk_shape.radius * 2
class MyGame(arcade.Window):
""" Main application class. """
def __init__(self, width, height, title):
super().__init__(width, height, title)
# arcade.set_background_color((0, 196, 231)) # lighter background
arcade.set_background_color((0, 101, 186)) # darker background
# Used for dragging shapes around with the mouse
self.shape_being_dragged = None
self.last_mouse_position = 0, 0
# Draw and processing timings
self.draw_time = 0
self.processing_time = 0
# FPS Counter
self.last_time = None
self.frame_count = 0
self.fps_message = None
# Holds the status message for pods killed
self.LAST_POD_KILLED = None
def on_close(self):
exit_handler(SIGINT, 0)
def setup(self):
""" Set up the game and initialize the variables. """
# -- Pymunk
self.space = pymunk.Space()
self.space.gravity = GRAVITY
# Physics joint used for grabbing items
self.grab_joint = None
# Lists of sprites
# self.dynamic_sprite_list = arcade.SpriteList[PymunkSprite]()
self.dynamic_sprite_list = arcade.SpriteList() # I dont know why, but this had to change from the above line
self.static_sprite_list = arcade.SpriteList()
self.static_sprite_list.is_static = True
self.bg_sprite_list = arcade.SpriteList()
self.bg_sprite_list.is_static = True
self.fg_sprite_list = arcade.SpriteList()
self.fg_sprite_list.is_static = True
self.ball_sprite_list: arcade.SpriteList[PhysicsSprite] = arcade.SpriteList()
# Current force applied to the player for movement by keyboard
self.force = (0, 0)
# Set the viewport boundaries
# These numbers set where we have 'scrolled' to.
self.view_left = 0
self.view_bottom = 0
# Track the current state of what key is pressed
self.left_pressed = False
self.right_pressed = False
self.up_pressed = False
self.down_pressed = False
self.is_jumping = False
# Holds game state
self.game_over = False
# Array for storing emitters
self.emitters = []
# self.frametime_plotter = FrametimePlotter()
# pyglet.clock.schedule_once(self.emitter, 1)
# Build the level
create_level_1(self.space, self.static_sprite_list, self.dynamic_sprite_list, self.bg_sprite_list, self.fg_sprite_list)
# Set up the player
x = 50
y = int((SCREEN_HEIGHT / 2))
# self.player = Player("./images/tiles/grassMid.png", x, y, scale=0.5, moment=pymunk.inf, mass=1)
self.player = Player("./images/Char_Monkey_Free_Images/Animations/monkey_idle.png", x, y, scale=0.5, moment=pymunk.inf, mass=1)
# self.player.center_x = SCREEN_WIDTH / 2
# self.player.center_y = SCREEN_HEIGHT / 2
self.dynamic_sprite_list.append(self.player)
self.space.add(self.player.body, self.player.shape)
# logging.info("Number of dynamic sprites created: %s", len(self.dynamic_sprite_list))
# Load sounds
self.jump_sound = arcade.load_sound("./sounds/jump3.wav")
self.punch_sound = arcade.load_sound("./sounds/woodhit.wav")
self.explode_sound = arcade.load_sound("./sounds/432668__dxeyes__crate-break-4.wav")
self.ball_sound = arcade.load_sound("./sounds/laser4.wav")
self.game_over_sound = arcade.load_sound("./sounds/277441__xtrgamr__tones-of-victory.wav")
self.game_over_sound_did_play = False
# self.intro_sound = arcade.load_sound("./sounds/277441__xtrgamr__tones-of-victory.wav")
# self.intro_sound_did_play = False
def on_draw(self):
""" Render the screen. """
self.frame_count += 1
# This command has to happen before we start drawing
arcade.start_render()
# for sprite in self.dynamic_sprite_list: # Draw hitboxes for debugging
# sprite.draw_hit_box(arcade.color.RED, 3)
# for sprite in self.static_sprite_list:
# sprite.draw_hit_box(arcade.color.BLUE, 3)
# print("Number of dynamic sprites present:", len(self.dynamic_sprite_list))
# Start timing how long rendering takes
draw_start_time = timeit.default_timer()
# Draw all the sprites
self.bg_sprite_list.draw(filter=GL_NEAREST)
self.static_sprite_list.draw(filter=GL_NEAREST)
self.dynamic_sprite_list.draw(filter=GL_NEAREST)
self.ball_sprite_list.draw()
self.fg_sprite_list.draw(filter=GL_NEAREST)
# Testing shapes
# arcade.draw_polygon_filled(( (80, 60), (80, 0), (20, 0)), arcade.color.RED)
# arcade.draw_polygon_filled(( (20, 120), (20, 60), (80, 60)), arcade.color.RED)
# Draw emitters
for e in self.emitters:
e.draw()
# print(e.get_count())
# Display game over screen when needed
if self.game_over:
arcade.draw_text("Game Over", self.view_left + SCREEN_WIDTH / 4, self.view_bottom + SCREEN_HEIGHT / 2, arcade.color.BLACK, 100, font_name = ["Impact", "Courier", "Helvetica"])
# Once per split second
if self.frame_count % 20 == 0:
self.player.punching = False # Unset the punching animation
# Display FPS
if self.last_time and self.frame_count % 60 == 0:
fps = 1.0 / (time.time() - self.last_time) * 60
self.fps_message = f"FPS: {fps:5.0f}"
if self.fps_message:
arcade.draw_text(self.fps_message, self.view_left + 10, self.view_bottom + 60, arcade.color.BLACK, 14)
if self.frame_count % 60 == 0:
self.last_time = time.time()
# Display timings
# output = f"Processing time: {self.processing_time:.3f}"
# arcade.draw_text(output, 20 + self.view_left, SCREEN_HEIGHT - 60 + self.view_bottom, arcade.color.WHITE, 12)
# output = f"Drawing time: {self.draw_time:.3f}"
# arcade.draw_text(output, 20 + self.view_left, SCREEN_HEIGHT - 80 + self.view_bottom, arcade.color.WHITE, 12)
# Display instructions
# output = "Use the mouse to move boxes, space to punch, hold G to grab an item to the right."
# arcade.draw_text(output, 20 + self.view_left, SCREEN_HEIGHT - 40 + self.view_bottom, arcade.color.WHITE, 12)
# Display last pod killed
if self.LAST_POD_KILLED:
output = f"Last pod killed: {self.LAST_POD_KILLED}"
arcade.draw_text(output, 20 + self.view_left, SCREEN_HEIGHT - 20 + self.view_bottom, arcade.color.WHITE, 12, font_name = ["Helvetica"])
self.draw_time = timeit.default_timer() - draw_start_time
def on_mouse_press(self, x, y, button, modifiers):
""" Handle mouse down events """
if button == arcade.MOUSE_BUTTON_LEFT:
# Store where the mouse is clicked. Adjust accordingly if we've
# scrolled the viewport.
self.last_mouse_position = (x + self.view_left, y + self.view_bottom)
# See if we clicked on any physics object
shape_list = self.space.point_query(self.last_mouse_position, 1, pymunk.ShapeFilter())
# If we did, remember what we clicked on
if len(shape_list) > 0:
self.shape_being_dragged = shape_list[0]
elif button == arcade.MOUSE_BUTTON_RIGHT:
# With right mouse button, shoot a heavy coin fast.
mass = 30
radius = 10
inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
body = pymunk.Body(mass, inertia)
body.position = (x + self.view_left, y + self.view_bottom)
body.velocity = 2000, 0
shape = pymunk.Circle(body, radius, pymunk.Vec2d(0, 0))
shape.friction = 0.3
arcade.play_sound(self.ball_sound)
self.space.add(body, shape)
sprite = CircleSprite(shape, "./images/items/coinGold.png")
self.ball_sprite_list.append(sprite)
def on_mouse_release(self, x, y, button, modifiers):
""" Handle mouse up events """
if button == arcade.MOUSE_BUTTON_LEFT:
# Release the item we are holding (if any)
self.shape_being_dragged = None
def on_mouse_motion(self, x, y, dx, dy):
""" Handle mouse motion events """
if self.shape_being_dragged is not None:
# If we are holding an object, move it with the mouse
self.last_mouse_position = (x + self.view_left, y + self.view_bottom)
self.shape_being_dragged.shape.body.position = self.last_mouse_position
self.shape_being_dragged.shape.body.velocity = dx * 20, dy * 20
def scroll_viewport(self):
""" Manage scrolling of the viewport. """
# Flipped to true if we need to scroll
changed = False
# Scroll left
# if self.player.position[0] > -constants.WORLD_SIZE + VIEWPORT_MARGIN: # Only scroll left if not near edge of world
left_bndry = self.view_left + VIEWPORT_MARGIN
if self.player.left < left_bndry:
self.view_left -= left_bndry - self.player.left
changed = True
# Scroll right
# if self.player.position[0] < constants.WORLD_SIZE - VIEWPORT_MARGIN: # Only scroll right if not near edge of world
right_bndry = self.view_left + SCREEN_WIDTH - VIEWPORT_MARGIN
if self.player.right > right_bndry:
self.view_left += self.player.right - right_bndry
changed = True
# Scroll up
top_bndry = self.view_bottom + SCREEN_HEIGHT - VIEWPORT_MARGIN
if self.player.top > top_bndry:
self.view_bottom += self.player.top - top_bndry
changed = True
# Scroll down
bottom_bndry = self.view_bottom + VIEWPORT_MARGIN
if self.player.bottom < bottom_bndry:
self.view_bottom -= bottom_bndry - self.player.bottom
changed = True
if changed:
arcade.set_viewport(int(self.view_left),
int(SCREEN_WIDTH + self.view_left),
int(self.view_bottom),
int(SCREEN_HEIGHT + self.view_bottom))
# print(arcade.get_viewport())
def on_update(self, delta_time):
""" Update the sprites """
# Keep track of how long this function takes.
start_time = timeit.default_timer()
# print(math.fmod(self.frame_count, delta_time))
# print(self.frame_count)
# See if all crates have been destroyed, if so that's game over
if len(self.dynamic_sprite_list) - 1 <= 0:
# logging.info("Game Over!")
self.game_over = True
if self.game_over_sound_did_play:
self.player.texture = self.player.textures[TEXTURE_IDLE_2]
return
else:
arcade.play_sound(self.game_over_sound)
self.game_over_sound_did_play = True # Only play sound once
return # Exit early / stop updating physics after game over
# print(self.player.body.position)
# # Print key states for debugging
# logging.info("Left: %s", self.left_pressed)
# logging.info("Right: %s", self.right_pressed)
# logging.info("Up: %s", self.up_pressed)
# print(self.force, self.player.shape.friction)
# print(self.player.body.velocity[0])
# # Debug grounding
# grounding = check_grounding(self.player) # find out if player is standing on ground
# if grounding['body'] is not None:
# logging.info("Grounding: %s", grounding['normal'].x / grounding['normal'].y)
# logging.info("Player friction: %s", self.player.shape.friction)
# See if the player is standing on an item.
# If she is, apply opposite force to the item below her.
# So if she moves left, the box below her will have
# a force to move to the right.
grounding = check_grounding(self.player)
if self.force[0] and grounding and grounding['body']:
grounding['body'].apply_force_at_world_point((-self.force[0], 0), grounding['position'])
# Apply force to monkey if direction keys pressed
if self.up_pressed:
grounding = check_grounding(self.player) # find out if player is standing on ground
if grounding['body'] is not None and abs(
grounding['normal'].x / grounding['normal'].y) <= self.player.shape.friction and self.player.body.velocity[1] < 1:
# She is! Go ahead and jump
self.player.body.apply_impulse_at_local_point((0, PLAYER_JUMP_IMPULSE))
arcade.play_sound(self.jump_sound)
# else:
# # print("Not on ground, cant jump")
# pass
elif self.down_pressed and not self.up_pressed:
# logging.info("Pressed down, not currently doing anything")
pass
if self.left_pressed and not self.right_pressed:
if self.player.body.velocity[0] >= 100: # If player already running right, apply the brakes so we can switch directions faster
self.force = (-4500, 0)
self.player.shape.friction = PLAYER_FRICTION * 15
else: # Add force to the player, and set the player friction to zero
self.force = (-PLAYER_MOVE_FORCE, 0)
self.player.shape.friction = 0
elif self.right_pressed and not self.left_pressed:
if self.player.body.velocity[0] <= -100: # If player already running left, apply the brakes so we can switch directions faster
self.force = (4500, 0)
self.player.shape.friction = PLAYER_FRICTION * 15
else: # Add force to the player, and set the player friction to zero
self.force = (PLAYER_MOVE_FORCE, 0)
self.player.shape.friction = 0
if not self.right_pressed and not self.left_pressed and not self.up_pressed:
#If no directions pressed, stop player
self.force = (0, 0)
self.player.shape.friction = PLAYER_FRICTION * 15 # Greatly increase friction so player stops instead of sliding
# Enforce player speed limit
if self.player.body.velocity[0] >= PLAYER_SPEED_LIMIT:
self.force = (-500, 0)
if self.player.body.velocity[0] <= -PLAYER_SPEED_LIMIT:
self.force = (500, 0)
# If we have force to apply to the player (from hitting the arrow
# keys), apply it.
self.player.body.apply_force_at_local_point(self.force, (0, 0))
# Update player sprites
self.player.update(self.frame_count) # Pass in frame_count so we can decide which frame of animation to use
# Check sprites
for sprite in self.dynamic_sprite_list:
if sprite.shape.body.position.y < 0: # Check for sprites that fall off the screen.
# Remove sprites from physics space
self.space.remove(sprite.shape, sprite.shape.body)
# Remove sprites from physics list
sprite.remove_from_sprite_lists()
if sprite.shape.name == "Pymunk" and sprite.shape.HITCOUNT >= CONTAINER_HEALTH / 2: # Change texture of crate if 50% damaged
broken_texture = arcade.load_texture("./images/tiles/boxCrate_single.png")
sprite.texture = broken_texture
# print("Damanged crate")
# if sprite.shape.name:
# print(sprite.shape.name)
if sprite.shape.name == "Pymunk" and sprite.shape.HITCOUNT >= CONTAINER_HEALTH: # Destroy container if hit CONTAINER_HEALTH times
# logging.info("Destroying shape %s", sprite.shape)
self.emitters.append(explosion(sprite.shape.body.position[0], sprite.shape.body.position[1])) # Make an explosion
self.space.remove(sprite.body, sprite.shape)
sprite.remove_from_sprite_lists()
# print(len(self.space.shapes))
arcade.play_sound(self.explode_sound)
# Kill random pod!
delete_thread = threading.Thread(target=self.kill_pod)
delete_thread.start()
# Check if we need to teleport
self.check_teleport()
# Update emitters
emitters_to_update = self.emitters.copy()
for e in emitters_to_update:
e.update()
# remove emitters that can be reaped
to_del = [e for e in emitters_to_update if e.can_reap()]
for e in to_del:
self.emitters.remove(e)
# Check for balls that fall off the screen
for sprite in self.ball_sprite_list:
if sprite.pymunk_shape.body.position.y < 0:
# Remove balls from physics space
self.space.remove(sprite.pymunk_shape, sprite.pymunk_shape.body)
# Remove balls from physics list
sprite.remove_from_sprite_lists()
# Move ball sprites to where physics objects are
for sprite in self.ball_sprite_list:
sprite.center_x = sprite.pymunk_shape.body.position.x
sprite.center_y = sprite.pymunk_shape.body.position.y
sprite.angle = math.degrees(sprite.pymunk_shape.body.angle)
# Update physics
# Use a constant time step, don't use delta_time
# http://www.pymunk.org/en/latest/overview.html#game-loop-moving-time-forward
self.space.step(1 / 60.0)
# If we are dragging an object, make sure it stays with the mouse. Otherwise
# gravity will drag it down.
if self.shape_being_dragged is not None:
self.shape_being_dragged.shape.body.position = self.last_mouse_position
self.shape_being_dragged.shape.body.velocity = 0, 0
# Resync the sprites to the physics objects that shadow them
resync_physics_sprites(self.dynamic_sprite_list)
# Scroll the viewport if needed
self.scroll_viewport()
# Save the time it took to do this.
self.processing_time = timeit.default_timer() - start_time
def check_teleport(self):
''' See if we need to warp back to start of level '''
# print(self.player.position)
if self.player.position[0] > constants.WORLD_SIZE: # Need to teleport player
self.player.body.position = pymunk.Vec2d(-constants.WORLD_SIZE, self.player.body.position[1])
if self.player.position[0] < -constants.WORLD_SIZE: # Need to teleport player
self.player.body.position = pymunk.Vec2d(constants.WORLD_SIZE, self.player.body.position[1])
# Check if crates need warping
for sprite in self.dynamic_sprite_list:
if sprite.shape.name == "Pymunk" and sprite.body.position[0] > constants.WORLD_SIZE:
sprite.body.position = pymunk.Vec2d(-constants.WORLD_SIZE, self.player.body.position[1])
# print("Sprite out of bounds")
if sprite.shape.name == "Pymunk" and sprite.body.position[0] < -constants.WORLD_SIZE:
sprite.body.position = pymunk.Vec2d(constants.WORLD_SIZE, self.player.body.position[1])
# print("Sprite out of bounds")
if sprite.shape.name == "Pymunk" and sprite.body.position[1] < 0:
# print("sprite fell off world, removing")
self.space.remove(sprite.body, sprite.shape)
sprite.remove_from_sprite_lists()
def kill_pod(self):
''' Deletes pod on kubernetes, then removes crate sprite from game '''
if constants.OFFLINE_MODE == False:
P1, P2 = list_pods()
self.LAST_POD_KILLED = delete_pod(P1, P2)
def punch(self):
''' Punch a crate '''
# --- Punch left
# See if we have a physics object to our left
self.player.punching = True
check_point = (self.player.right + 40, self.player.center_y)
shape_list = self.space.point_query(check_point, 1, pymunk.ShapeFilter())
# Apply force to any object to our left
for shape in shape_list:
# print(shape.shape.name)
arcade.play_sound(self.punch_sound)
shape.shape.body.apply_impulse_at_world_point((constants.PLAYER_PUNCH_IMPULSE, constants.PLAYER_PUNCH_IMPULSE),
check_point)
# Hit counter
shape.shape.HITCOUNT += 1
# logging.info("Punched shape R%s x %s", shape.shape, shape.shape.HITCOUNT)
# --- Punch right
# See if we have a physics object to our left
check_point = (self.player.left - 40, self.player.center_y)
shape_list = self.space.point_query(check_point, 1, pymunk.ShapeFilter())
# Apply force to any object to our right
for shape in shape_list:
arcade.play_sound(self.punch_sound)
shape.shape.body.apply_impulse_at_world_point((-constants.PLAYER_PUNCH_IMPULSE, constants.PLAYER_PUNCH_IMPULSE),
check_point)
# Hit counter
shape.shape.HITCOUNT += 1
# logging.info("Punched shape L%s x %s", shape.shape, shape.shape.HITCOUNT)
def grab(self):
""" Grab something """
# See if we have a physics object to our right
check_point = (self.player.right + 40, self.player.center_y)
shape_list = self.space.point_query(check_point, 1, pymunk.ShapeFilter())
# Create a joint for an item to our right
for shape in shape_list:
self.grab_joint = pymunk.PinJoint(self.player.shape.body, shape.shape.body)
self.space.add(self.grab_joint)
def let_go(self):
""" Let go of whatever we are holding """
if self.grab_joint:
self.space.remove(self.grab_joint)
self.grab_joint = None
def on_key_press(self, symbol: int, modifiers: int):
""" Handle keyboard presses. """
if symbol == arcade.key.UP:
self.up_pressed = True
elif symbol == arcade.key.DOWN:
self.down_pressed = True
elif symbol == arcade.key.LEFT:
self.left_pressed = True
elif symbol == arcade.key.RIGHT:
self.right_pressed = True
elif symbol == arcade.key.SPACE:
self.punch()
elif symbol == arcade.key.G:
self.grab()
elif symbol == arcade.key.R:
logging.info("Resetting game")
self.setup()
elif symbol == arcade.key.ESCAPE:
logging.info("Closing game")
self.close()
elif symbol == arcade.key.PLUS or symbol == arcade.key.EQUAL:
constants.PLAYER_PUNCH_IMPULSE = constants.PLAYER_PUNCH_IMPULSE * 1.1
logging.info("Increased punch force: %s", constants.PLAYER_PUNCH_IMPULSE)
elif symbol == arcade.key.MINUS:
constants.PLAYER_PUNCH_IMPULSE = constants.PLAYER_PUNCH_IMPULSE / 1.1
logging.info("Decreasing punch force: %s", constants.PLAYER_PUNCH_IMPULSE)
def on_key_release(self, symbol: int, modifiers: int):
""" Handle keyboard releases. """
if symbol == arcade.key.UP:
self.up_pressed = False
elif symbol == arcade.key.DOWN:
self.down_pressed = False
elif symbol == arcade.key.LEFT:
self.left_pressed = False
elif symbol == arcade.key.RIGHT:
self.right_pressed = False
# if symbol == arcade.key.RIGHT:
# # Remove force from the player, and set the player friction to a high number so she stops
# self.force = (0, 0)
# self.player.shape.friction = 15
# elif symbol == arcade.key.LEFT:
# # Remove force from the player, and set the player friction to a high number so she stops
# self.force = (0, 0)
# self.player.shape.friction = 15
elif symbol == arcade.key.G:
self.let_go()
def explosion(x, y):
""" Create an explosion when crate destroyed """
e = arcade.Emitter(
center_xy=(x, y),
emit_controller=arcade.EmitterIntervalWithTime(constants.DEFAULT_EMIT_INTERVAL * 1.25, constants.DEFAULT_EMIT_DURATION / 6),
particle_factory=lambda emitter: arcade.LifetimeParticle(
filename_or_texture=constants.E_TEXTURE,
change_xy=arcade.rand_in_circle((0.0, 0.0), constants.PARTICLE_SPEED_FAST * 6),
lifetime=random.uniform(0.05, 1),
scale=random.uniform(0.05, 0.3),
alpha=random.uniform(64, 250),
change_angle=random.uniform(-30, 30),
angle=random.uniform(0, 360)
)
)
return e
def main():
# Process arguments
parser = argparse.ArgumentParser(description='A Chaos Monkey for your Kubernetes cluster!')
parser.add_argument("--offline", default="no", help="Set to yes to enable offline mode")
parser.add_argument('-e','--exclude', nargs='*', default="", help='<Optional> Space-separated list of namespaces to NOT target')
args = parser.parse_args()
offline = args.offline
if offline != "no":
logging.info("Starting in offline mode")
constants.OFFLINE_MODE = True
else:
logging.info("Starting in online mode")
constants.OFFLINE_MODE = False
constants.EXCLUDES_LIST = args.exclude
logging.info("Excluding namespaces: %s", constants.EXCLUDES_LIST)
window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
window.setup()
arcade.run()
if __name__ == "__main__":
signal(SIGINT, exit_handler)
main()