I'm writing a top down game and I'm trying to figure out how to make certain types of terrains impassable.
I have a dictionary of sprites:
terrains = [{"sprite": black}, {"sprite": dirt}, {"sprite": grass}, {"sprite": water}, {"sprite": mountian}]
And here's my movement code:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
right = True
"""I want to check around here
pseudo-code:
If next terrain has the passable option set to false then dont move if its
set to true then move."""
if event.key == pygame.K_LEFT:
left = True
if event.key == pygame.K_UP:
up = True
if event.key == pygame.K_DOWN:
down = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
right = False
if event.key == pygame.K_LEFT:
left = False
if event.key == pygame.K_UP:
up = False
if event.key == pygame.K_DOWN:
down = False
if right == True:
lnkx = lnkx + 16
if left == True:
lnkx = lnkx - 16
if up == True:
lnky = lnky - 16
if down == True:
lnky = lnky + 16
So I would have to add a passable option to the "terrains" dictionary and check if the next terrain is passable in the movement code.