Making an object jump with gravity using arcade module in Python3
The Arcade library is a modern Python Module used widely for developing 2D video games with compelling graphics and sound. Arcade is an object-oriented library. It can be installed like any other Python Package. Now, it’s up to the necessity of the developer, what type of game, graphics, and sound he/she wants to use using this toolkit. So, in this article, we will learn how to make an object jump with gravity using the Arcade library in Python. And for understanding that concept, let’s take an example of a robust ball.
Following are the steps:
Step 1: Import arcade module .
Step 2: Define parameters of the output screen.
# Size of the screen WIDTH = 600 HEIGHT = 600 TITLE = "Robust Ball "
Step 3: Define the radius of the ball.
# Size of the ball. BALL_RADIUS = 50
Step 4: Define the value of gravitational constant.
# gravity GRAVITATIONAL_CONSTANT = 0.3
Step 5: Define a bouncing velocity for the ball.
# Percent of velocity maintained on a bounce. BOUNCE = 0.9
Step 6: Define a function to draw a ball using arcade.draw_circle_filled() .
Step 7: Define function to Figure out if we hit the left or right edge so that we can reverse.
Step 8: Also, Define function to Figure out if we hit the bottom so that we can reverse.
Step 9: Use the above defined function and provide input to them.
Step 10: Last and foremost step is to define the main function that contains arcade function to assign output window a proper width, height and title.
Complete Code for better Understanding:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course