1- #
2- # Arcade Platformer
3- #
4- # Demonstrating the capbilities of arcade in a platformer game
5- # Supporting the Arcade Platformer article on https://realpython.com
6- #
7- # All game artwork and sounds, except the tile map and victory sound,
8- # from www.kenney.nl
1+ """
2+ Arcade Platformer
93
4+ Demonstrating the capbilities of arcade in a platformer game
5+ Supporting the Arcade Platformer article on https://realpython.com
6+
7+ All game artwork from www.kenney.nl
8+ Game sounds and tile maps by author
9+ """
1010
11- # Import libraries
1211import arcade
1312import pathlib
1413
3029ASSETS_PATH = pathlib .Path (__file__ ).resolve ().parent .parent / "assets"
3130
3231
33- # Classes
3432class Platformer (arcade .Window ):
35- """Platformer class. Derived from arcade.Window,
36- manages different aspects of the game.
37- """
38-
3933 def __init__ (self ) -> None :
40- """Create the game view"""
41- # First initialize the parent
4234 super ().__init__ (SCREEN_WIDTH , SCREEN_HEIGHT , SCREEN_TITLE )
4335
4436 # These lists will hold different sets of sprites
45- self .coins_list = None
46- self .background_list = None
47- self .walls_list = None
48- self .ladders_list = None
49- self .goals_list = None
50- self .enemies_list = None
37+ self .coins = None
38+ self .background = None
39+ self .walls = None
40+ self .ladders = None
41+ self .goals = None
42+ self .enemies = None
5143
5244 # One sprite for the player, no more is needed
5345 self .player = None
@@ -87,29 +79,29 @@ def setup(self) -> None:
8779 ladders_layer = "ladders"
8880
8981 # Load the current map
90- map = arcade .tilemap .read_tmx (str (map_path ))
82+ game_map = arcade .tilemap .read_tmx (str (map_path ))
9183
9284 # Load the layers
93- self .background_list = arcade .tilemap .process_layer (
94- map , layer_name = background_layer , scaling = MAP_SCALING
85+ self .background = arcade .tilemap .process_layer (
86+ game_map , layer_name = background_layer , scaling = MAP_SCALING
9587 )
96- self .goals_list = arcade .tilemap .process_layer (
97- map , layer_name = goal_layer , scaling = MAP_SCALING
88+ self .goals = arcade .tilemap .process_layer (
89+ game_map , layer_name = goal_layer , scaling = MAP_SCALING
9890 )
99- self .walls_list = arcade .tilemap .process_layer (
100- map , layer_name = wall_layer , scaling = MAP_SCALING
91+ self .walls = arcade .tilemap .process_layer (
92+ game_map , layer_name = wall_layer , scaling = MAP_SCALING
10193 )
102- self .ladders_list = arcade .tilemap .process_layer (
103- map , layer_name = ladders_layer , scaling = MAP_SCALING
94+ self .ladders = arcade .tilemap .process_layer (
95+ game_map , layer_name = ladders_layer , scaling = MAP_SCALING
10496 )
105- self .coins_list = arcade .tilemap .process_layer (
106- map , layer_name = coin_layer , scaling = MAP_SCALING
97+ self .coins = arcade .tilemap .process_layer (
98+ game_map , layer_name = coin_layer , scaling = MAP_SCALING
10799 )
108100
109101 # Set the background color
110102 background_color = arcade .color .FRESH_AIR
111- if map .background_color :
112- background_color = map .background_color
103+ if game_map .background_color :
104+ background_color = game_map .background_color
113105 arcade .set_background_color (background_color )
114106
115107 # Create the player sprite, if they're not already setup
@@ -125,42 +117,35 @@ def setup(self) -> None:
125117 # Load the physics engine for this map
126118 self .physics_engine = arcade .PhysicsEnginePlatformer (
127119 player_sprite = self .player ,
128- platforms = self .walls_list ,
120+ platforms = self .walls ,
129121 gravity_constant = GRAVITY ,
130- ladders = self .ladders_list ,
122+ ladders = self .ladders ,
131123 )
132124
133125 def on_key_press (self , key : int , modifiers : int ):
134- """Processes key presses
135-
136- Arguments:
137- key {int} -- Which key was pressed
138- modifiers {int} -- Which modifiers were down at the time
126+ """Arguments:
127+ key {int} -- Which key was pressed
128+ modifiers {int} -- Which modifiers were down at the time
139129 """
140130
141131 def on_key_release (self , key : int , modifiers : int ):
142- """Processes key releases
143-
144- Arguments:
145- key {int} -- Which key was released
146- modifiers {int} -- Which modifiers were down at the time
132+ """Arguments:
133+ key {int} -- Which key was released
134+ modifiers {int} -- Which modifiers were down at the time
147135 """
148136
149137 def on_update (self , delta_time : float ):
150- """Updates the position of all screen objects
138+ """Updates the position of all game objects
151139
152140 Arguments:
153141 delta_time {float} -- How much time since the last call
154142 """
155143 pass
156144
157145 def on_draw (self ):
158- """Draws everything"""
159146 pass
160147
161148
162- # Main
163- # Main
164149if __name__ == "__main__" :
165150 window = Platformer ()
166151 window .setup ()
0 commit comments