This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/Rendering/MapTiles.gd

44 lines
1.1 KiB
GDScript3
Raw Permalink Normal View History

2020-07-06 12:38:05 +00:00
extends TileMap
class_name MapTiles
2020-09-15 23:24:08 +00:00
var transparentImage := preload("res://Graphics/transparent.png")
2020-07-12 15:26:40 +00:00
2020-07-06 12:38:05 +00:00
export(NodePath) var extended_tilemap_node
2020-07-08 12:30:46 +00:00
2020-09-15 23:24:08 +00:00
export var occluders := ["Wall"]
2020-07-06 12:38:05 +00:00
2020-09-15 23:24:08 +00:00
export var shadow_intensity := 0.2
2020-07-06 12:38:05 +00:00
func run_conversions():
2020-07-08 12:30:46 +00:00
# Make occluders
2020-07-06 12:38:05 +00:00
make_occluders()
2020-07-08 12:30:46 +00:00
2020-07-06 12:38:05 +00:00
func make_occluders():
2020-09-15 23:24:08 +00:00
var occluder_ids := []
2020-07-06 12:38:05 +00:00
for occluder_name in occluders:
2020-09-15 23:24:08 +00:00
var id := tile_set.find_tile_by_name(occluder_name)
2020-07-08 12:30:46 +00:00
if id >= 0:
occluder_ids.push_back(id)
2020-07-06 12:38:05 +00:00
for id in tile_set.get_tiles_ids():
if occluder_ids.find(id) < 0:
# Not an occluder, skip it
continue
# Find all uses of this tile
for cell in get_used_cells_by_id(id):
# Check sides
2020-09-15 23:24:08 +00:00
var occluder := Occluder.new()
2020-07-06 12:38:05 +00:00
occluder.ignore_sides = [
occluder_ids.find(get_cell(cell.x, cell.y-1)) >= 0, # Top
occluder_ids.find(get_cell(cell.x+1, cell.y)) >= 0, # Right
occluder_ids.find(get_cell(cell.x, cell.y+1)) >= 0, # Bottom
occluder_ids.find(get_cell(cell.x-1, cell.y)) >= 0 # Left
]
occluder.transform.origin = map_to_world(cell)
add_child(occluder)
func set_occluder_origin(origin):
for child in get_children():
if child is Occluder:
child.origin = origin