Question: Make a python code for Main topics: keyboard input, Pygame library, coordinate transformations In an Asteroids arcade game you are the commander of a spaceship
Make a python code for Main topics: keyboard input, Pygame library, coordinate transformations
In an Asteroids arcade game you are the commander of a spaceship which got caught in
an asteroid cloud. Luckily your spaceship is equipped with lasers so you can pulverize
the asteroids before they hit you. For the Asteroids game see the Wikipedia entry on the
original Asteroids game of Atari. For more information on real asteroid clouds see the
NASA article on the Kuiper belt
Task description of the project:
Figure : Screenshot asteroids game example
Draw some images to use for your ship and asteroids
During the game the spaceship is in the center of the screen
The spaceship can rotate itself to shoot asteroids with a laser
Asteroids fly in random directions potentially harming the ship Not all asteroids
will hit the ship.
To obtain a graphical window, and facilitate keyboard interactions, you will use Pygame,
a Python package dedicated to making games in Python, see the Pygame website.
A few more hints to get you started:
To start off with your project have a look at the Pygame documentation: start with
the example at the beginning and then add the functionality for your game.
Loading an image asteroid image, spaceship, etc. and scaling it to the right size
to use inside the game can be done using:
Rotation of images can be done using:
imshiprot pygame.transform.rotate surfaceimship, angleangle
The yaxis of the screen is pointing down, you can create functions to convert
between screen coordinates and the game coordinates where the ship is in the
origin
To put an image on the screen you use realize that the destination parameter uses
the location of the upperleft corner of the image, you need to correct for this for
the image of ship or asteroid to be in the middle
screen.blittheimage, dest
A rotated image is larger than the original, so the center point is different, so every
time you rotate your ship you need to recalculate its center point.
Check for collisions between ship and asteroids at each time point. Calculate the
distance between the spaceship and the asteroids and verify whether this distance
is large enough.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
