@@ -25,6 +25,26 @@
SCREEN_WIDTH = SPRITE_SIZE * SCREEN_GRID_WIDTH
SCREEN_HEIGHT = SPRITE_SIZE * SCREEN_GRID_HEIGHT
+# --- Physics forces. Higher number, faster accelerating.
+GRAVITY = 1500
+# Damping - Amount of speed lost per second
+DEFAULT_DAMPING = 1.0
+PLAYER_DAMPING = 0.4
+# Friction between objects
+PLAYER_FRICTION = 1.0
+WALL_FRICTION = 0.7
+DYNAMIC_ITEM_FRICTION = 0.6
+# Mass (defaults to 1)
+PLAYER_MASS = 2.0
+# Keep player from going too fast
+PLAYER_MAX_HORIZONTAL_SPEED = 450
+PLAYER_MAX_VERTICAL_SPEED = 1600
""" Main Window """
@@ -47,6 +67,9 @@
# Track the current state of what key is pressed
self.left_pressed: bool = False
self.right_pressed: bool = False
+ # Physics engine
+ self.physics_engine = Optional[arcade.PymunkPhysicsEngine]
# Set background color
@@ -77,6 +100,58 @@
# Add to player sprite list
+ # --- Pymunk Physics Engine Setup ---
+ # The default damping for every object controls the percent of velocity
+ # the object will keep each second. A value of 1.0 is no speed loss,
+ # 0.9 is 10% per second, 0.1 is 90% per second.
+ # For top-down games, this is basically the friction for moving objects.
+ # For platformers with gravity, this should probably be set to 1.0.
+ # Default value is 1.0 if not specified.
+ damping = DEFAULT_DAMPING
+ # Set the gravity. (0, 0) is good for outer space and top-down.
+ gravity = (0, -GRAVITY)
+ # Create the physics engine
+ self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping,
+ # Add the player.
+ # For the player, we set the damping to a lower value, which increases
+ # the damping rate. This prevents the character from traveling too far
+ # after the player lets off the movement keys.
+ # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from
+ # rotating.
+ # Friction normally goes between 0 (no friction) and 1.0 (high friction)
+ # Friction is between two objects in contact. It is important to remember
+ # in top-down games that friction moving along the 'floor' is controlled
+ # by damping.
+ # Create the walls.
+ # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't
+ # move.
+ # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC
+ # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be
+ # repositioned by code and don't respond to physics forces.
+ # Dynamic is default.
+ # Create the items
def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """
@@ -87,7 +162,7 @@
def on_update(self, delta_time):
""" Movement and game logic """
""" Draw everything """