57 lines
982 B
GDScript
57 lines
982 B
GDScript
extends Node3D
|
|
|
|
var microban_1 := "
|
|
####
|
|
# .#
|
|
# ###
|
|
#*@ #
|
|
# $ #
|
|
# ###
|
|
####
|
|
"
|
|
|
|
var states: Array[State] = [State.from_string(microban_1)]
|
|
|
|
func _ready() -> void:
|
|
render()
|
|
|
|
func render() -> void:
|
|
print(current_state())
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("u"):
|
|
step(Vector2i.UP)
|
|
elif event.is_action_pressed("d"):
|
|
step(Vector2i.DOWN)
|
|
elif event.is_action_pressed("l"):
|
|
step(Vector2i.LEFT)
|
|
elif event.is_action_pressed("r"):
|
|
step(Vector2i.RIGHT)
|
|
elif event.is_action_pressed("undo"):
|
|
undo()
|
|
elif event.is_action_pressed("redo"):
|
|
pass
|
|
elif event.is_action_pressed("restart"):
|
|
restart()
|
|
|
|
|
|
func current_state() -> State:
|
|
return states[-1]
|
|
|
|
func push_state(state: State):
|
|
states.push_back(state)
|
|
render()
|
|
|
|
func undo():
|
|
if states.size() == 1:
|
|
return
|
|
states.pop_back()
|
|
render()
|
|
|
|
# todo: don't restart multiple times
|
|
func restart():
|
|
push_state(states[0])
|
|
|
|
func step(move: Vector2i):
|
|
push_state(current_state().step(move))
|