Space invaders Pygame remake part 2

The secondo part… here comes the aliens. Github repository with code and assets.

First part

What if… Space invaders was made with pygame?

What if… Space invaders was made with pygame?

Part 2: the aliens squad

We make the aliens thanks to this class and the following list

class Alien(pygame.sprite.Sprite):
    def __init__(self, file, x, y):

        super(Alien, self).__init__()
        self.x = x
        self.y = y
        self.image = load("imgs\\" + file)
        self.w, self.h = self.image.get_size()
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)
        #self.rect.center = self.x, self.y
      
        g.add(self)
        aliens.add(self)

We will create an alien for each item in the list in different rows. We added the aliens in their own group: aliens.

squad = [
    [1,1,1,1,1,1,1,1], # line 1... [item, item]
    [1,1,1,1,1,1,1,1],
    [1,1,1,1,1,1,1,1],
    [1,1,1,1,1,1,1,1]
    ]
    

for y, line in enumerate(squad):
    for x, item in enumerate(line):
        if item == 1:
            alien = Alien("alien1", 70 + 50 * x, 30 + 50 * y)

 

Go to the next part

Part III

Space invaders tutorial part 3: aliens are moving


Subscribe to the newsletter for updates
Tkinter templates

Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Claude's Games

Arkanoid
Platform 2d

1. Memory game

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Advertisement