extends Node3D var microban_1 := " #### # .# # ### #*@ # # $ # # ### #### " var hist := UndoRedo.new() @onready var board := Board.from_string(microban_1) var player: Piece func _ready() -> void: add_child(board) for piece in board.pieces(): if piece.type == Piece.Type.Player: player = piece break func _input(event: InputEvent) -> void: if event.is_action_pressed("u", true, true): step(Vector2i.UP) elif event.is_action_pressed("d", true, true): step(Vector2i.DOWN) elif event.is_action_pressed("l", true, true): step(Vector2i.LEFT) elif event.is_action_pressed("r", true, true): step(Vector2i.RIGHT) elif event.is_action_pressed("undo", true, true): hist.undo() elif event.is_action_pressed("redo", true, true): hist.redo() elif event.is_action_pressed("restart", true, true): restart() # TODO: func restart(): pass func step(move: Vector2i): var pos := player.lpos var box := board.find_piece_at(pos + move, func(p): return p.type == Piece.Type.Box) if board.passable_at(pos + move): hist.create_action("move") hist.add_do_method(player.do_move(move)) hist.add_undo_method(player.undo_move()) hist.commit_action() elif box != null and board.passable_at(pos + move * 2): hist.create_action("push") hist.add_do_method(player.do_move(move)) hist.add_do_method(box.do_move(move)) hist.add_undo_method(player.undo_move()) hist.add_undo_method(box.undo_move()) hist.commit_action()