How to add five rows of invaders in space invader game

From what it seems, you would just need to make a nested loop

for b in range(5):
   XPos = #insert original starting value
   for i in range(11):
       invader = Invader.Invader()
       invader.setPosX(xPos)
       invader.setPosY(20 * b) #adjust y values to your preference
       self.invaders.append(invader)            
       xPos += 32

This will create five rows of 11. Make sure you change the values to your preference and set the starting x Position where i commented.

Leave a Comment