I am making walls in Pygame, I plan on making a lot of walls in the game but making individual if statements for each block of wall doesn’t sound that efficient.
Is there a way I could make an if statement that just effects the whole class of wall? Right now it looks like this (wall is a class and player is an object)
if wall.x == player.x and wall.y == player.y
player.y -= 64
>Solution :
You can not. You can however keep a list of walls, and perform the check in a loop on all of them:
walls = [wall_1, wall_2, ...]
for wall in walls:
if wall.x == player.x and wall.y == player.y
player.y -= 64