Python and Turtle python Asteroids Tutorial- Explosions

Asteroids Tutorial- Explosions

The Explosions Class

Each explosion should have its own x and y location, future locations, moving directions, and a set of random speeds. A loop (of 12 iterations) adds the initial x and y location as a pair to a list, a random number between 0 and 2*π to another list, and a random number between 300 and 500 (these numbers can be adjusted to preference) to the speeds list. The speeds will decrease by a percentage per iteration of the explosion.

A screenshot of a cell phone

Description automatically generated

Moving the Explosion

For each of the copies of the initial x and y location (in the above screenshot, self.p), edit the x location by the speed multiplied by the time multiplied by the cosine of the corresponding direction and edit the y location by the speed multiplied by the time multiplied by the sine of the corresponding direction. Then, decrease the speed of the explosion by 10%. 

A screenshot of a cell phone

Description automatically generated

Drawing the Explosion

First, clear the screen of any residual marks. Then, go through the list of locations and draw a dot for each one.

A close up of text on a black background

Description automatically generated

Animation

The exploding animation is standard and self explanatory.

View this page for full code: https://github.com/HaimingXu679/Asteroids/blob/master/explosion.py

Related Post