samedi 1 août 2020

Python space invaders game trying to compare the x-coordinates of all enemies to wall's

I am making a space invaders clone, and I am trying to implement enemy wall collision, but I cant seem to compare all the x coordinates to the wall(I drew all the enemies using turtle and put them in a list) I am getting the error (if enemies_coordinates[i] > -280:IndexError: list index out of range) which confuses me because I am appending the enemies coordinates to the enemies_coordinates list yet it only outputs one. I am probably doing something weird, any help is appreciated.

#FIXME Check the cordainates of all enemies for wall collison
def enemy_coor():
    i = 0
    for alien in enemies:
        global enemies_coordinates
        enemies_coordinates = []
        enemies_coordinates.append(enemies[i].xcor())
        print(enemies_coordinates)
        i += 1

#FIXME Wall collioson
def alien_wall_collison():
    i = 0
    for alien in enemies:
        print(i)
        if enemies_coordinates[i] > -280:
            print("turn Right")
        i += 1

Aucun commentaire:

Enregistrer un commentaire