Can someone tell me how to create a wall that stops light in this function

55 Views Asked by At

With this code it creates a small amount of light that surrounds the sprite but I want it to stop at certain tiles.

The tiles that I want it to light up are represented by a 0 in a 2d list but tiles represented as 1 in the list I want the light to stop passing through it, almost as if it acts like a wall. How can I do this?

def calculate_visible_tiles(character_x, character_y, light_radius, game_map, tile_size):
    visible_tiles = set()
    for dx in range(-light_radius, light_radius + 1):
        for dy in range(-light_radius, light_radius + 1):
            distance = (dx ** 2 + dy ** 2) ** 0.5
            if distance <= light_radius:
                tile_x, tile_y = round((character_x + dx) / tile_size), round((character_y + dy) / tile_size)
                if 0 <= tile_x < len(game_map[0]) and 0 <= tile_y < len(game_map):
                    visible_tiles.add((tile_x, tile_y))

I've tried to set it so light stops when the expected tile reaches a tile coded with "1" but that just turns the whole screen black

0

There are 0 best solutions below