Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.43 KB

step_05.rst

File metadata and controls

44 lines (31 loc) · 1.43 KB

Step 5 - Add Gravity

The previous example great for top-down, but what if it is a side view with jumping like our platformer? We need to add gravity. First, let's define a constant to represent the acceleration for gravity, and one for a jump speed.

../../../arcade/examples/platform_tutorial/05_add_gravity.py

At the end of the setup method, change the physics engine to PhysicsEnginePlatformer and include gravity as a parameter.

../../../arcade/examples/platform_tutorial/05_add_gravity.py

Then, modify the key down and key up event handlers. We'll remove the up/down statements we had before, and make 'UP' jump when pressed.

../../../arcade/examples/platform_tutorial/05_add_gravity.py

Note

You can change how the user jumps by changing the gravity and jump constants. Lower values for both will make for a more "floaty" character. Higher values make for a faster-paced game.

Source Code

../../../arcade/examples/platform_tutorial/05_add_gravity.py