0
def player_bullet():
barrel = -300
bullet = turtle.Turtle()
bullet.penup()
bullet.setposition(starting_x, barrel)
bullet.color("red")
bullet.shape("triangle")
bullet.setheading(90)

bullet.shapesize(0.5, 0.5)
while True:
    if barrel > 300:
        bullet.ht()
        break
    barrel += 10
    bullet.sety(barrel)
    turtle.update()

while True:
    turtle.onkeypress(move_left, key="Left")
    turtle.onkeypress(move_right, key="Right")
    turtle.onkeypress(player_bullet, key="space")
    turtle.listen()
    turtle.update()

the bullet shoots and stops once another bullet is created and shot...I want the first bullet to finish it's run while being able to create new bullets. This is for a space invaders game with turtle graphics.

  • The pasted code probably does not have the indentation of your actual code. – gspr Mar 15 '22 at 13:58
  • aside from indentation, there are undefined variables: `starting_x`, `move_left`, `move_right`... so where are those comming from please ? – D.L Mar 15 '22 at 14:39
  • Sorry about the indentation...the first while loop should be indented. The undefined variables are there I just didn't add them to the code pasted. – Jerrell-Abrahams Mar 15 '22 at 19:46
  • You can [edit] your post to fix the problems. – ggorlen Mar 24 '22 at 02:43
  • You'll probably want a list to keep track of the bullets. See [this code example](https://github.com/HaimingXu679/Asteroids/blob/master/bullet.py). – ggorlen Mar 24 '22 at 20:55

0 Answers0