Hi I am new to python and new to stack exchange. I am trying to create a space invaders game using turtle, but I am having an issue in which my gun cannot shoot until all the aliens have finished invading. I think I'm having this problem because either the invasion function and shoot function are not running simultaneously, or because turtle does not allow more than one turtle to move at once.
I attempted to use threading to run both functions in parallel, but it did not solve the issue, the gun could not fire until the invasion was complete. Any help would be greatly appreciated! (I am very new to python, so I apoligize for the messiness of my code)
import turtle
import random
import threading
from threading import Thread
screen = turtle.Screen()
screen.setup(400, 500)
screen.bgpic("/Users/benmartinez/Desktop/Space_Invaders_BG.gif")
turtle.right(90)
turtle.pu()
turtle.forward(200)
turtle.pd()
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(200)
turtle.right(180)
turtle.forward(20)
turtle.left(90)
turtle.circle(20, 180)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
homex = turtle.xcor()
homey = turtle.ycor()
def shoot():
turtle.color('red')
turtle.showturtle()
turtle.pu()
turtle.onscreenclick(turtle.goto)
turtle.goto(homex, homey)
turtle.onclick(shoot())
def invaders():
invader_initial_position = random.randint(-200, 200)
i = turtle.Turtle()
i.shape('triangle')
i.color('green')
i.pu()
i.hideturtle()
i.goto(invader_initial_position, 300)
i.showturtle()
i.right(90)
i.speed(1)
i.forward(500)
def invasion():
x = 0
while x < 10:
invaders()
x += 1
#if __name__ == '__main__':
Thread(target = invasion()).start()
Thread(target = shoot()).start()