0
  • I'm creating a pygame that involves 2 tanks shooting at each other and a bullet. I've managed to create the bullet and get it to move, but I'm not sure how to create a new instance of a bullet everytime I press the keybutton. Currently, the bullet is just resetting every time I press the key, but I want it to shoot a new bullet instead. Currently, I've set SHOO and shoot as False, and the x and y coordinates are for the bullet.


if keys[pygame.K_RSHIFT]:
    SHOO = True
    x2 = x1 + 30
    y2 = y1 + 39
if SHOO and x1 >= -1000: 
    x2 -= 7


if keys[pygame.K_e]:
    x3 = x + 30
    y3 = y + 39
    shoot = True
if shoot and x3 <= 1000:
    x3 += 7
opthukral
  • 1
  • 1
  • Rather than creating new variables, you should keep bullet instances in a list. These bullet instances could be just another list like `[x, y]`. And draw them on the screen using the list. Don't forget to remove them when they are out of the screen. – Rockybilly May 18 '22 at 15:39
  • How would we call this list if we created a list for it? Do I still use my conditions to call the list if so? – opthukral May 19 '22 at 12:54

0 Answers0