0

I am trying to create Space Invaders using sprites as each of the aliens in the game. Instead of defining them all manually I decided to use a for-loop. The problem is since all of the turtles have the same name so I can only interact with the newest one. Is there any way to fix this? Just for clarification I am looking for ways to define turtles in a for-loop while giving them different names.

image_one = "invade_one.gif"
image_two = "invader_two.gif"

screen.register_shape("invade_one.gif")
screen.register_shape("invader_two.gif")

mod = 0
for x in range(0, 11):
    mod += 15
    invader_one = Turtle()
    invader_one.penup()
    invader_one.shape(image_one)
    invader_one.speed(0)
    invader_one.color("#eeeeee")
    invader_one.shapesize(5, 5, 12)
    invader_one.goto(mod, 0)

while True:
    invader_one.shape(image_one)
    screen.update()
    sleep(0.5)
    invader_one.shape(image_two)
    screen.update()
    sleep(0.5)

screen.mainloop()

0 Answers0