dial in sun movement

make it take as long as it takes the balls to move during rolltime basically
This commit is contained in:
mehbark 2025-05-29 18:00:59 -04:00
parent 70f7ef747d
commit e16482627a
3 changed files with 32 additions and 12 deletions

View file

@ -1,6 +1,9 @@
class_name Board
extends Node3D
## squares per second
@export_range(0.0, 1, 0.01) var anim_time := 0.15
var dims: Vector2i
func _ready():
@ -75,7 +78,12 @@ func finish_tween():
# diagonal velocity
# uhh that's it lol?
# well, subphases: higher lvel magnitude moves first within a phase
# TODO: maybe show these phases with the sun
## returns the total time animation *will* take
func step_anim_time() -> float:
var pieces_moving := pieces().filter(func(piece): return piece.lvel != Vector2i.ZERO).size()
return pieces_moving * anim_time
func do_step():
var pieces_moving := pieces().filter(func(piece): return piece.lvel != Vector2i.ZERO)
var pieces_cardinal := pieces_moving.filter(func(piece): return piece.lvel.x == 0 or piece.lvel.y == 0)

25
main.gd
View file

@ -26,11 +26,8 @@ var levels: Array[PackedScene] = [
]
# TODO: sun movement takes exactly as much time as all piece movement
var time := 0:
set(new_time):
var tween := get_tree().create_tween()
tween.tween_property($Sun, "rotation_degrees:y", -15*new_time, 0.1)
time = new_time
var time := 0
var advancing := false
@onready var sound: AudioStreamPlayer = $Sound
@ -118,11 +115,29 @@ func restart():
# scratch that i like that, don't clear the history
# you can like replay your steps up to a point
var last_sun_tween: Tween = null
# time advancing, basically
func board_step():
var anim_time := maxf(board.step_anim_time(), board.anim_time)
hist.add_do_method(board.do_step)
hist.add_do_property(self, "time", time+1)
hist.add_do_method(func():
if last_sun_tween:
last_sun_tween.custom_step(413)
last_sun_tween.kill()
var tween := get_tree().create_tween()
tween.tween_property($Sun, "rotation_degrees:y", -15*time, anim_time)
last_sun_tween = tween
)
hist.add_undo_property(self, "time", time)
hist.add_undo_method(func():
if last_sun_tween:
last_sun_tween.custom_step(413)
last_sun_tween.kill()
var tween := get_tree().create_tween()
tween.tween_property($Sun, "rotation_degrees:y", -15*time, 0.1)
last_sun_tween = tween
)
hist.add_undo_method(board.undo_step())
func step(move: Vector2i):

View file

@ -16,9 +16,6 @@ enum Type {
PlayerBarrier,
}
## squares per second
@export_range(0.0, 1, 0.01) var anim_time := 0.1
func pos_of_lpos(pos: Vector2i, y := 0.0) -> Vector3:
return Vector3(pos.x, y, pos.y)
@ -26,7 +23,7 @@ func target_pos() -> Vector3:
return pos_of_lpos(lpos, position.y) + Vector3(0.5, 0, 0.5)
var last_move_tween: Tween = null
func tween_to_target(tween := get_tree().create_tween()):
func tween_to_target(tween := get_tree().create_tween(), anim_time: float = get_parent().anim_time):
if last_move_tween:
last_move_tween.custom_step(413)
last_move_tween.kill()
@ -113,7 +110,7 @@ func do_bump(move: Vector2i, tween := get_tree().create_tween(), bumpee: Piece =
if bumpee:
old_lvel_bumpee = bumpee.lvel
return func():
tween.tween_property(self, "position", target_pos() + pos_of_lpos(move)/2, anim_time/2)
tween.tween_property(self, "position", target_pos() + pos_of_lpos(move)/2, get_parent().anim_time/2)
if bumpee:
tween.tween_callback(func():
if delay_bumpee_update:
@ -122,7 +119,7 @@ func do_bump(move: Vector2i, tween := get_tree().create_tween(), bumpee: Piece =
bumpee.lvel_displayed = old_lvel_bumpee
)
tween.tween_callback(func(): lvel_displayed = lvel)
tween_to_target(tween)
tween_to_target(tween, get_parent().anim_time/2)
# TODO?: maybe fix? maybe the bump should be more complicated?
func undo_bump(_move: Vector2i) -> Callable: