much better input handling, mvp arr
This commit is contained in:
parent
065ee3d481
commit
04dc259568
2 changed files with 34 additions and 12 deletions
44
main.gd
44
main.gd
|
@ -45,7 +45,8 @@ func _process(delta: float) -> void:
|
|||
$UndoButton.disabled = not hist.has_undo()
|
||||
$RedoButton.disabled = not hist.has_redo()
|
||||
$RestartButton.disabled = not hist.has_undo()
|
||||
$Clock.text = "T = %d\n%d FPS" % [time, Engine.get_frames_per_second()]
|
||||
$Clock.text = "T = %d\n%d FPS\n%f hold time\n%f arrf" % \
|
||||
[time, Engine.get_frames_per_second(), move_hold_time, arrf(move_hold_time)]
|
||||
var slowmo := Input.is_action_pressed("slowmo");
|
||||
$SlowmoIndicator.text = "slowmo" if slowmo else ""
|
||||
Engine.time_scale = slowmo_speed if slowmo else 1.0
|
||||
|
@ -53,17 +54,38 @@ func _process(delta: float) -> void:
|
|||
AudioServer.playback_speed_scale = slowmo_speed if slowmo else 1.0
|
||||
if not $TopLeft.is_on_screen() or not $BottomRight.is_on_screen():
|
||||
camera.position.y += 10*delta
|
||||
|
||||
handle_move(delta)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("u", false, true):
|
||||
step(Vector2i.UP)
|
||||
elif event.is_action_pressed("d", false, true):
|
||||
step(Vector2i.DOWN)
|
||||
elif event.is_action_pressed("l", false, true):
|
||||
step(Vector2i.LEFT)
|
||||
elif event.is_action_pressed("r", false, true):
|
||||
step(Vector2i.RIGHT)
|
||||
elif event.is_action_pressed("undo", false, true):
|
||||
var move_last := Vector2i.ZERO
|
||||
var move_hold_time := 0.0
|
||||
var move_last_integer := -1
|
||||
|
||||
func arrf(x: float) -> float:
|
||||
return 5*x**(4.0/3)
|
||||
#return 20*x*log(x+1)/log(10)
|
||||
|
||||
func handle_move(delta: float):
|
||||
var dir := Vector2i(Input.get_vector(&"l", &"r", &"u", &"d").snapped(Vector2.ONE))
|
||||
|
||||
if dir == Vector2i.ZERO or (abs(dir.x) > 0 and abs(dir.y) > 0):
|
||||
move_last = Vector2i.ZERO
|
||||
move_hold_time = 0
|
||||
move_last_integer = -1
|
||||
return
|
||||
|
||||
var fx := floori(arrf(move_hold_time))
|
||||
if fmod(arrf(move_hold_time), 1) < 0.1 and fx != move_last_integer:
|
||||
var steps := maxi(1, fx - move_last_integer)
|
||||
for i in range(steps):
|
||||
step(dir)
|
||||
move_last_integer = fx
|
||||
|
||||
move_last = dir
|
||||
move_hold_time += delta
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("undo", false, true):
|
||||
undo()
|
||||
elif event.is_action_pressed("redo", false, true):
|
||||
redo()
|
||||
|
|
2
piece.gd
2
piece.gd
|
@ -121,7 +121,7 @@ func do_bump(move: Vector2i, old_lvel := lvel) -> Callable:
|
|||
tweens.push_back(tween)
|
||||
|
||||
# TODO?: maybe fix? maybe the bump should be more complicated?
|
||||
func undo_bump(move: Vector2i) -> Callable:
|
||||
func undo_bump(_move: Vector2i) -> Callable:
|
||||
return func(): pass
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
Loading…
Reference in a new issue