Fixed names for a better traceability of code errors with orignal code lesson. End of lesson 25. Player is moving on the map viewport!
This commit is contained in:
@@ -8,16 +8,39 @@ func _ready():
|
||||
CommandDispatcher.LOAD_MAP.connect(loadMap)
|
||||
|
||||
|
||||
func loadMap(currentMapPath, newMapPath, spawnpoint, facing):
|
||||
var newMap:Map = load(newMapPath).instantiate()
|
||||
func loadMap(newMapPath, spawnpoint, facing):
|
||||
var newMap:Map
|
||||
|
||||
CommandDispatcher.PAUSE_PROCESSOR.emit()
|
||||
|
||||
if (currentMapPath != null):
|
||||
currentMapPath.queue_free()
|
||||
if (map != null):
|
||||
map.queue_free()
|
||||
|
||||
map = load(newMapPath).instantiate()
|
||||
|
||||
add_child(map)
|
||||
|
||||
entities.add_child(map.spawnPlayerAtPosition(spawnpoint, facing))
|
||||
|
||||
GameManager.currentMap = newMapPath
|
||||
|
||||
add_child(newMap)
|
||||
|
||||
entities.add_child(newMap.spawnPlayerAtPosition(spawnpoint, facing))
|
||||
|
||||
CommandDispatcher.WAIT_FOR_COMMAND.emit()
|
||||
|
||||
|
||||
func _unhandled_key_input(event):
|
||||
var direction
|
||||
|
||||
if (Input.is_action_pressed("ui_right")):
|
||||
direction = Map.Direction.East
|
||||
|
||||
if (Input.is_action_pressed("ui_left")):
|
||||
direction = Map.Direction.West
|
||||
|
||||
if (Input.is_action_pressed("ui_up")):
|
||||
direction = Map.Direction.North
|
||||
|
||||
if (Input.is_action_pressed("ui_down")):
|
||||
direction = Map.Direction.South
|
||||
|
||||
if (direction != null):
|
||||
CommandDispatcher.PROCESS_COMMAND.emit(MoveCommand.new(direction))
|
||||
|
||||
Reference in New Issue
Block a user