Today in class, I finished my spacewar game. I added a background image, and explosions.

This is the code for the background image.
turtle.bgpic("starfield.gif")
This is the code that makes the player smaller.
self.shapesize(stretch_wid=0.6, stretch_len=1.1, outline=None)
This is the code for the explosion particles.
class Particle(Sprite):
def __init__(self, spriteshape, color, startx, starty):
Sprite.__init__(self, spriteshape, color, startx, starty)
self.shapesize(stretch_wid=0.1, stretch_len=0.1, outline=None)
self.goto(-1000,-1000)
self.frame = 0
def explode(self, startx, starty):
self.goto(startx,starty)
self.setheading(random.randint(0,360))
self.frame = 1
def move(self):
if self.frame > 0:
self.fd(10)
self.frame += 1
if self.frame > 15:
self.frame = 0
self.goto(-1000, -1000)
This is the code for the particles.
particles = []
for i in range(20):
particles.append(Particle("circle", "orange", 0, 0))
This is the code that does the explosion.
for particle in particles:
particle.explode(missile.xcor(), missile.ycor())
No Responses