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