lvel animation

This commit is contained in:
mehbark 2025-05-05 23:12:38 -04:00
parent a91b6999ec
commit b0826a934d

View file

@ -47,6 +47,7 @@ func lpos_of_pos(pos: Vector3) -> Vector2i:
## logical velocity ## logical velocity
@export var lvel := Vector2i.ZERO @export var lvel := Vector2i.ZERO
var lvel_displayed := lvel
@export var type: Piece.Type @export var type: Piece.Type
@ -60,7 +61,7 @@ func do_step(board: Board):
# ball being collided *with* gets the remainder of the momentum # ball being collided *with* gets the remainder of the momentum
# EMERGENT COMPLEXITY!??!? # EMERGENT COMPLEXITY!??!?
if board.solid_at(new_pos): if board.solid_at(new_pos):
do_bump(move).call() do_bump(move, lvel).call()
var ball_here := board.type_at(new_pos, Piece.Type.Ball) var ball_here := board.type_at(new_pos, Piece.Type.Ball)
if ball_here: if ball_here:
var rem := lvel % 2 var rem := lvel % 2
@ -73,6 +74,7 @@ func do_step(board: Board):
var on_ice := !!board.type_at(lpos, Piece.Type.FloorIce) var on_ice := !!board.type_at(lpos, Piece.Type.FloorIce)
if not on_ice: if not on_ice:
lvel -= move lvel -= move
lvel_displayed = lvel
tween_to_target() tween_to_target()
func undo_step() -> Callable: func undo_step() -> Callable:
@ -81,6 +83,7 @@ func undo_step() -> Callable:
return func(): return func():
lpos = old_pos lpos = old_pos
lvel = old_vel lvel = old_vel
lvel_displayed = lvel
tween_to_target() tween_to_target()
func do_move(move: Vector2i) -> Callable: func do_move(move: Vector2i) -> Callable:
@ -103,18 +106,22 @@ func undo_move() -> Callable:
func do_push(move: Vector2i) -> Callable: func do_push(move: Vector2i) -> Callable:
return func(): return func():
lvel += move lvel += move
lvel_displayed = lvel
func undo_push() -> Callable: func undo_push() -> Callable:
var old_vel := lvel var old_vel := lvel
return func(): return func():
lvel = old_vel lvel = old_vel
lvel_displayed = lvel
# no logical effect, purely for aesthetics # no logical effect, purely for aesthetics
# (and communicating !!!! player yes) # (and communicating !!!! player yes)
func do_bump(move: Vector2i) -> Callable: func do_bump(move: Vector2i, old_lvel := lvel) -> Callable:
return func(): return func():
lvel_displayed = old_lvel
var tween := create_tween() var tween := create_tween()
tween.tween_property(self, "position", target_pos() + pos_of_lpos(move)/2, anim_time()) tween.tween_property(self, "position", target_pos() + pos_of_lpos(move)/2, anim_time())
tween.tween_callback(func(): lvel_displayed = lvel)
tween_to_target(tween) tween_to_target(tween)
tweens.push_back(tween) tweens.push_back(tween)
@ -152,4 +159,4 @@ func format_vel(vel: Vector2) -> String:
return "%d,%d" % [vel.x,vel.y] return "%d,%d" % [vel.x,vel.y]
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
speedometer.text = format_vel(lvel) speedometer.text = format_vel(lvel_displayed)