Added automated mushroom glowing

This commit is contained in:
Dan 2024-06-02 17:28:38 +01:00
parent 9f224b3d69
commit cf3c8d82f1
6 changed files with 223 additions and 31 deletions

View file

@ -3,10 +3,14 @@ class_name CustomTileMap
var astar : AStarGrid2D = AStarGrid2D.new()
@onready var fog_overlay : ColorRect = $FogOverlay
@onready var mushroom_glow_container : Node2D = $MushroomGlowContainer
@onready var tilemap_size : Vector2i = get_used_rect().end - get_used_rect().position
@onready var map_rect : Rect2i = Rect2i(Vector2i.ZERO, tilemap_size)
var mushroom_glow : PackedScene = load("res://entities/mushroom_glow.tscn")
var highlighted_tiles : Array = []
func _ready() -> void:
@ -79,6 +83,7 @@ func _unhandled_input(event : InputEvent) -> void:
redraw_surrounding_tiles(surrounding_cells)
update_passable()
check_for_visible_gatherables()
# Check if the tile is already highlighted
#if highlighted_tiles.has(tile_position):
@ -97,6 +102,11 @@ func redraw_surrounding_tiles(positions : Array) -> void:
set_cells_terrain_connect(0, walls, 0, 1)
func check_for_visible_gatherables() -> void:
# Remove all existing glowing lights
for child in mushroom_glow_container.get_children():
child.queue_free()
## Loop through the tiles on the gatherables layer and check if the thing on
# the layer below them is a wall, if it is they need to be hidden.
for i in tilemap_size.x:
@ -107,9 +117,18 @@ func check_for_visible_gatherables() -> void:
# Get the tile data from the base layer
var below_tile_data : TileData = get_cell_tile_data(0, coords)
if below_tile_data and below_tile_data.get_custom_data('navtype') == 'wall':
Log.pr("Gatherable is on a wall tile, it should be hidden!")
Log.pr("This is behind a wall...")
else:
if tile_data.get_custom_data('glowcolour'):
var glow_colour : String = tile_data.get_custom_data('glowcolour')
Log.pr("Glow colour: " + str(glow_colour))
var glow : MushroomGlow = mushroom_glow.instantiate()
glow.set_position(coords * get_tileset().tile_size + get_tileset().tile_size / 2)
glow.colour_name = glow_colour
mushroom_glow_container.add_child.call_deferred(glow)
Log.pr(glow)
# Log.pr(below_tile_data)
#if tile_data and tile_data.get_custom_data('navtype') == 'gatherable':
# var below_tile_data : TileData = get_cell_tile_data(0, coords + Vector2i(0, 1))
# if below_tile_data and below_tile_data.get_custom_data('navtype') == 'wall':
# set_cellv(coords, -1)
# set_cellv(coords, -1)

File diff suppressed because one or more lines are too long