pymunk_demo_platformer_03.py Full Listing
pymunk_demo_platformer_03.py
1"""
2Example of Pymunk Physics Engine Platformer
3"""
4
5import math
6from typing import Optional
7import arcade
8
9SCREEN_TITLE = "PyMunk Platformer"
10
11# How big are our image tiles?
12SPRITE_IMAGE_SIZE = 128
13
14# Scale sprites up or down
15SPRITE_SCALING_PLAYER = 0.5
16SPRITE_SCALING_TILES = 0.5
17
18# Scaled sprite size for tiles
19SPRITE_SIZE = int(SPRITE_IMAGE_SIZE * SPRITE_SCALING_PLAYER)
20
21# Size of grid to show on screen, in number of tiles
22SCREEN_GRID_WIDTH = 25
23SCREEN_GRID_HEIGHT = 15
24
25# Size of screen to show, in pixels
26SCREEN_WIDTH = SPRITE_SIZE * SCREEN_GRID_WIDTH
27SCREEN_HEIGHT = SPRITE_SIZE * SCREEN_GRID_HEIGHT
28
29
30class GameWindow(arcade.Window):
31 """Main Window"""
32
33 def __init__(self, width, height, title):
34 """Create the variables"""
35
36 # Init the parent class
37 super().__init__(width, height, title)
38
39 # Player sprite
40 self.player_sprite: arcade.Sprite | None = None
41
42 # Sprite lists we need
43 self.player_list: arcade.SpriteList | None = None
44 self.wall_list: arcade.SpriteList | None = None
45 self.bullet_list: arcade.SpriteList | None = None
46 self.item_list: arcade.SpriteList | None = None
47
48 # Track the current state of what key is pressed
49 self.left_pressed: bool = False
50 self.right_pressed: bool = False
51
52 # Set background color
53 self.background_color = arcade.color.AMAZON
54
55 def setup(self):
56 """Set up everything with the game"""
57 pass
58
59 def on_key_press(self, key, modifiers):
60 """Called whenever a key is pressed."""
61 pass
62
63 def on_key_release(self, key, modifiers):
64 """Called when the user releases a key."""
65 pass
66
67 def on_update(self, delta_time):
68 """Movement and game logic"""
69 pass
70
71 def on_draw(self):
72 """Draw everything"""
73 self.clear()
74
75
76def main():
77 """Main function"""
78 window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
79 window.setup()
80 arcade.run()
81
82
83if __name__ == "__main__":
84 main()