pymunk_demo_platformer_02.py Full Listing#

pymunk_demo_platformer_02.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    def setup(self):
39        """ Set up everything with the game """
40        pass
41
42    def on_key_press(self, key, modifiers):
43        """Called whenever a key is pressed. """
44        pass
45
46    def on_key_release(self, key, modifiers):
47        """Called when the user releases a key. """
48        pass
49
50    def on_update(self, delta_time):
51        """ Movement and game logic """
52        pass
53
54    def on_draw(self):
55        """ Draw everything """
56        self.clear()
57
58
59def main():
60    """ Main function """
61    window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
62    window.setup()
63    arcade.run()
64
65
66if __name__ == "__main__":
67    main()