End of lesson 29
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
3
scripts/game/maps/TownMap.gd
Normal file
3
scripts/game/maps/TownMap.gd
Normal file
@@ -0,0 +1,3 @@
|
||||
extends Map2d
|
||||
|
||||
class_name TownMap
|
||||
1
scripts/game/maps/TownMap.gd.uid
Normal file
1
scripts/game/maps/TownMap.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dcg3hnc5yq61d
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user