Alien fleet falls diagonally


On page 266 of "Python Crash Course" when you’re supposed to make the fleet fall one then change direction, my alien fleet falls diagonally. After using print statements I can see that the variable fleetDirection changes from 1 to -1 to 1 and so on. The problem is that it is constantly changing directions so it just falls. What should I do to fix this?

def check_edges(self):
    screenRect = self.screen.get_rect()

    if self.rect.right >= screenRect.right or self.rect.left <= 0:
        return True

def update(self):
    self.x += (self.settings.alienSpeed * self.settings.fleetDirection)
    self.rect.x = self.x

def check_fleet_edges(self):
    for alien in self.aliens.sprites():
        if alien.check_edges():
def change_fleet_direction(self):
    for alien in self.aliens.sprites():
        alien.rect.y += self.settings.fleetDropSpeed
    self.settings.fleetDirection *= -1


The solution to this was to add UpdateAliends() in the run game method.

Answered By – Jack_AKA_Oscar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published