End of chapter 6. A lot of problems took to much time to solve. It was good to know better Godot internal mechanism.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
extends Timer
|
||||
|
||||
class_name CommandProcessor
|
||||
signal BROADCAST_COMMAND(label)
|
||||
|
||||
var resumeWaiting:bool = true
|
||||
@@ -16,17 +15,15 @@ func processCommand(command:Command):
|
||||
return
|
||||
|
||||
stop()
|
||||
|
||||
command.COMMAND_PROCESSED.connect(onCommandProcessed)
|
||||
|
||||
BROADCAST_COMMAND.emit(command.getCommandText())
|
||||
|
||||
emit_signal("BROADCAST_COMMAND", command.getCommandText())
|
||||
command.execute()
|
||||
|
||||
|
||||
func waitForCommand():
|
||||
resumeWaiting = true
|
||||
start()
|
||||
CommandDispatcher.DISPLAY_COMMAND_PROMPT.emit()
|
||||
|
||||
|
||||
func pauseProcessor():
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
extends Node
|
||||
|
||||
var defaultMapPath: String = "res://scenes/game/maps/world_map.tscn"
|
||||
var currentMapPath: String = ""
|
||||
var defaultMapPath:String = "res://scenes/game/maps/world_map.tscn"
|
||||
|
||||
var currentMapPath
|
||||
|
||||
func startNewGame():
|
||||
currentMapPath = defaultMapPath
|
||||
|
||||
@@ -4,7 +4,6 @@ signal COMMAND_PROCESSED(label)
|
||||
|
||||
var commandLabel
|
||||
|
||||
|
||||
func execute():
|
||||
COMMAND_PROCESSED.emit(commandLabel)
|
||||
|
||||
|
||||
@@ -3,3 +3,9 @@ extends Node
|
||||
signal PROCESS_COMMAND(command)
|
||||
signal WAIT_FOR_COMMAND
|
||||
signal PAUSE_PROCESSOR
|
||||
|
||||
signal PLAYER_MOVE(direction)
|
||||
|
||||
signal DISPLAY_MESSAGE(message)
|
||||
signal DISPLAY_COMMAND_PROMPT
|
||||
signal DISPLAY_CLEAR
|
||||
|
||||
22
scripts/game/commands/MoveCommand.gd
Normal file
22
scripts/game/commands/MoveCommand.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
extends Command
|
||||
|
||||
class_name MoveCommand
|
||||
|
||||
var direction
|
||||
|
||||
func _init(dir):
|
||||
commandLabel = "Move"
|
||||
direction = dir
|
||||
|
||||
|
||||
func execute():
|
||||
CommandDispatcher.PLAYER_MOVE.emit(direction)
|
||||
emit_signal("COMMAND_PROCESSED", getCommandText())
|
||||
|
||||
|
||||
func getDirectionString() -> String:
|
||||
return Map.Direction.keys()[direction]
|
||||
|
||||
|
||||
func getCommandText():
|
||||
return "%s %s" % [commandLabel, getDirectionString()]
|
||||
1
scripts/game/commands/MoveCommand.gd.uid
Normal file
1
scripts/game/commands/MoveCommand.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c136g73lrccts
|
||||
@@ -2,9 +2,10 @@ extends Command
|
||||
|
||||
class_name PassCommand
|
||||
|
||||
func _init() -> void:
|
||||
func _init():
|
||||
commandLabel = "Pass"
|
||||
|
||||
|
||||
func execute():
|
||||
print("Player passed.")
|
||||
COMMAND_PROCESSED.emit(commandLabel)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
extends Node
|
||||
|
||||
class_name GameScreen
|
||||
class_name GameScreen
|
||||
|
||||
@export var map: Node
|
||||
@export var map:Node
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
func _ready():
|
||||
map.add_child(load(GameManager.currentMapPath).instantiate())
|
||||
CommandDispatcher.WAIT_FOR_COMMAND.emit()
|
||||
|
||||
func _on_pass_button_pressed() -> void:
|
||||
|
||||
func _on_pass_button_pressed():
|
||||
CommandDispatcher.PROCESS_COMMAND.emit(PassCommand.new())
|
||||
|
||||
5
scripts/game/maps/map.gd
Normal file
5
scripts/game/maps/map.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends TileMap
|
||||
|
||||
class_name Map
|
||||
|
||||
enum Direction { North, East, South, West }
|
||||
1
scripts/game/maps/map.gd.uid
Normal file
1
scripts/game/maps/map.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dg5n82oyi536p
|
||||
@@ -1,27 +1,26 @@
|
||||
extends TileMap
|
||||
extends Map
|
||||
|
||||
class_name Map2d
|
||||
|
||||
enum TerrainDataTypes { TerrainType }
|
||||
|
||||
|
||||
func getTerrainDataForTile(layer, data, x, y):
|
||||
var tile: TileData = get_cell_tile_data(layer, Vector2i(x, y))
|
||||
if tile != null:
|
||||
var tile:TileData = get_cell_tile_data(layer, Vector2i(x, y))
|
||||
|
||||
if (tile != null):
|
||||
return tile.get_custom_data(TerrainDataTypes.keys()[data])
|
||||
else:
|
||||
return null
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17))
|
||||
print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0))
|
||||
print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11))
|
||||
print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9))
|
||||
print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 22, 22))
|
||||
|
||||
|
||||
#func _ready() -> void:
|
||||
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 39, 17))
|
||||
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 0, 0))
|
||||
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 11, 11))
|
||||
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 6, 9))
|
||||
# print(getTerrainDataForTile(0, TerrainDataTypes.TerrainType, 22, 22))
|
||||
#
|
||||
#
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
#func _process(delta: float) -> void:
|
||||
# pass
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
extends Map2d
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
|
||||
#func _ready() -> void:
|
||||
# super._ready()
|
||||
|
||||
Reference in New Issue
Block a user