Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If statments effect classes, not just objects

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading