Beginning of lesson 33. House polygon working and we are able to speak with NPC at world map, but not in starter town.

This commit is contained in:
2025-04-18 21:53:50 -03:00
parent ffbbfd455e
commit b0c7c3d3ff
13 changed files with 219 additions and 23 deletions

View File

@@ -12,6 +12,7 @@ var player
func _ready():
CommandDispatcher.PLAYER_MOVE.connect(onPlayerMove)
CommandDispatcher.TOGGLE_TILEMAP_LAYER.connect(onToggleRequest)
CommandDispatcher.PLAYER_SPEAK.connect(onSpeak)
@warning_ignore("unused_parameter")
@@ -50,10 +51,20 @@ func playerCanMoveTo(newPosition) -> bool:
return false
func onToggleRequest(layerName):
func onToggleRequest(layerName, visible):
for layer in range(get_layers_count()):
if(get_layer_name(layer) == layerName):
if(is_layer_enabled(layer)):
set_layer_enabled(layer, false)
else:
set_layer_enabled(layer, true)
set_layer_enabled(layer, visible)
func onSpeak():
var interactables:Array = player.speechCollider.get_overlapping_areas()
if (interactables.size() > 0):
for interactable in interactables:
interactable.get_parent().interact()
else:
CommandDispatcher.DISPLAY_MESSAGE.emit("There is no one to speak to.")

View File

@@ -5,8 +5,14 @@ class_name ToggleRoofTrigger
@export var layerName:String
func execute(target):
CommandDispatcher.TOGGLE_TILEMAP_LAYER.emit(layerName)
pass
func _on_area_entered(area: Area2D) -> void:
execute(area.get_parent())
CommandDispatcher.TOGGLE_TILEMAP_LAYER.emit(layerName, false)
print("entered")
func _on_area_exited(area: Area2D) -> void:
CommandDispatcher.TOGGLE_TILEMAP_LAYER.emit(layerName, true)
print("exited")

View File

@@ -9,6 +9,8 @@ class_name Mob
@export var collisionRay_1:RayCast2D
@export var collisionRay_2:RayCast2D
@export var speechCollider:Area2D
func updateRaycasts(destination):
var direction = destination - position
@@ -80,3 +82,7 @@ func wouldCollideAt(destination):
if collisionRay_1.is_colliding() || collisionRay_2.is_colliding():
return true
func interact():
print("Player interacted with %s" % name)