Today in class, I added a missile.

This is the code for the missile.
class Missile(Sprite):
def __init__(self, spriteshape, color, startx, starty):
Sprite.__init__(self, spriteshape, color, startx, starty)
self.shapesize(stretch_wid=0.3, stretch_len=0.4, outline=None)
self.speed = 20
self.status = "ready"
self.goto(-1000, 1000)
This is the code for firing the missile.
def fire(self):
if self.status == "ready":
self.goto(player.xcor(), player.ycor())
self.setheading(player.heading())
self.status = "firing"
This is the code for the missile to move.
def move(self):
if self.status == "ready":
self.goto(-1000, 1000)
if self.status == "firing":
self.fd(self.speed)
This is the missile code.
missile = Missile("triangle", "yellow", 0, 0)
This is the key for the missile.
turtle.onkey(missile.fire, "space")
This is the code to check for a collision between the missile and the enemy.
if missile.is_collision(enemy):
x = random.randint(-250, 250)
y = random.randint(-250, 250)
enemy.goto(x, y)
missile.status = "ready"
No Responses