0
votes

I'm trying to make a space invaders like game where you can move a spaceship left and right and shoot bullets.

But whenever I animate the bullet, the spaceship can't move and i can't shoot another bullet either.

I'm using something called pygame_functions and this is what I've been trying:

while True:
    if keyPressed("space"):
        ###shoots fireball###
        while i >= 100:
            moveSprite(fireball, x,y)
            y=y-3

    elif KeyPressed ("a"):
        ###moves right###

    elif KeyPressed ("d"):
        ###moves left###

Is there a way to continue my inner loop while my outer loop still applies?

1
You may need to use multiple threads so the animation occurs concurrently with other activity. - Barmar
ok thankyou! i will look into that - Annie Sun
Or, you can use one big (complicated) loop that checks on moving everything around. The main problem you have in this version is that the inner loop is "nested" in the outer loop. The outer loop stops and waits for the inner loop to complete. One way of explaining is like a delivery driver that has a truck full of packages. Each stop is an inner loop, the driver gets out, rings the door, leaves package, gets in truck, etc. Then the outer loop is the truck moving from stop-to-stop. - benc

1 Answers

0
votes

I think the inner loop should change. Whenever you press space you should add bullet into a list and in each(or every several) iteration of main loop move points in the list.