my first question here and begginer in python
i want to make simple shooter game(Chicken Invaders type). List of rectangles(enemies) and smaller rectangles(ammo) who should 'kill' enemies on collision. I created list of rectangles on random positions on screen.
enemies = []
for i in range(ENEMYCOUNT):
enemySize = random.randint(ENEMYMINSIZE, ENEMYMAXSIZE)
newEnemy = pygame.Rect(random.randint(0, WINDOWWIDTH - enemySize),
random.randint(0, WINDOWWIDTH-200), enemySize, enemySize)
enemies.append(newEnemy)
My 'ammo' are list of invisible rectangles who appear on mouse click and then they move up
ammo = []
for i in range(1, 5):
ammo.append(pygame.Rect(0, 0, 0, 0))
I did for single enemy and single ammo and it is working as intended. Now i want to make for more enemies and check if any of enemy is hit by ammo
for e in enemies:
for a in ammo:
if e.colliderect(a):
enemies.remove(e)
But i keep getting
if e.colliderect(a): AttributeError: 'NoneType' object has no attribute 'colliderect'
I am studying from 'inventwithpython' book and copying parts of code that i need but i could not solve this. I cant see the problem since both of my lists are made of Rect objects. Any help would be appreciated