End of lesson 29

This commit is contained in:
2025-04-18 16:36:11 -03:00
parent 75cbdf40b2
commit 2d87794af9
11 changed files with 87 additions and 7 deletions

View File

@@ -18,4 +18,10 @@ func spawnPlayerAtPosition(position, facing):
super.spawnPlayerAtPosition(position, facing)
return player
player.updateFacing(facing)
get_node("Entities").add_child(player)
func playerCanMoveTo(position:Vector2) -> bool:
return !player.wouldCollideAt(position)

View File

@@ -66,7 +66,7 @@ func _process(delta: float) -> void:
call_deferred("add_child", map)
map.spawnPlayerAtPosition(newSpawnpoint, newSpawnpoint)
map.spawnPlayerAtPosition(newSpawnpoint, newFacing)
CommandDispatcher.LOAD_COMPLETE.emit()
CommandDispatcher.WAIT_FOR_COMMAND.emit()

View File

@@ -0,0 +1,3 @@
extends Map2d
class_name TownMap

View File

@@ -0,0 +1 @@
uid://dcg3hnc5yq61d

View File

@@ -54,3 +54,29 @@ func updateAnimation(direction):
animator.frame = 0
else:
animator.frame += 1
func updateFacing(direction):
var sequence
match(direction):
Map.Direction.East:
sequence = "Idle Right"
Map.Direction.West:
sequence = "Idle Left"
Map.Direction.North:
sequence = "Idle Up"
Map.Direction.South:
sequence = "Idle Down"
animator.animation = sequence
animator.frame = 0
func wouldCollideAt(destination):
updateRaycasts(destination)
if collisionRay_1.is_colliding() || collisionRay_2.is_colliding():
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
return true