my Wall Collision code doesnt work. I dont get any error message, the player just goes through the walls. This is my code:
def drawRect(x, y):
pygame.draw.rect(screen, BLUE, [pxl(x), pxl(y), pxl(1), pxl(1)])
def drawLevel(level):
global gameDrawn, wallsCoord
x = y = 0
wallsCoord = []
walls = []
ends = []
if gameDrawn == False:
screen.fill(WOODY)
drawRect(1, 8)
showTimer()
for row in levels[level]:
for col in row:
if col == "W":
wall = Wall((x, y))
walls.append(wall)
wallsCoord.append((x, y))
if col == "E":
end = End((x, y))
ends.append(end)
if col == "P":
drawRect(1, 9)
x += 80
y += 80
x = 0
for wall in walls:
pygame.draw.rect(screen, BLACK, wall.rect)
for end in ends:
pygame.draw.rect(screen, RED, end.rect)
gameDrawn = True
return walls, ends
def drawPlayerPath(players):
global wallsCoord
for x, y in players:
if (x, y) in wallsCoord:
state = "gameover"
init_state = True
else:
drawRect(x, y)
def getPlayerPath(players):
global move_list, player_x, player_y
player_x, player_y = players[0]
for i in move_list:
if i == 1:
player_y -= 1
elif i == 2:
player_y += 1
elif i == 3:
player_x += 1
elif i == 4:
player_x -= 1
players.append((player_x, player_y))
I dont really get, why it doesnt work since I already iterated the x and y values of the players list over the coordinates list of the walls.