more consistent, deeper, animated collisions

This commit is contained in:
mehbark 2025-05-04 19:00:23 -04:00
parent 20a708651f
commit 193888cd2b
2 changed files with 21 additions and 12 deletions

12
main.gd
View file

@ -108,16 +108,8 @@ func step(move: Vector2i):
elif ball != null: elif ball != null:
hist.create_action("push") hist.create_action("push")
hist.add_do_method(ball.do_push(move)) hist.add_do_method(ball.do_push(move))
hist.add_do_method(func(): hist.add_do_method(player.do_bump(move))
player.lpos = pos + move hist.add_undo_method(player.undo_bump(move))
player.lpos = pos
player.anim_progress = 0.5
)
hist.add_undo_method(func():
player.lpos = pos + move
player.lpos = pos
player.anim_progress = 0.5
)
hist.add_undo_method(ball.undo_push()) hist.add_undo_method(ball.undo_push())
hist.commit_action() hist.commit_action()
else: else:

View file

@ -48,11 +48,15 @@ func do_step(board: Board):
return return
var move := lvel.clampi(-1, 1) var move := lvel.clampi(-1, 1)
var new_pos := lpos + move var new_pos := lpos + move
# ball being collided *with* gets the remainder of the momentum
# EMERGENT COMPLEXITY!??!?
if board.solid_at(new_pos): if board.solid_at(new_pos):
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:
ball_here.do_push(lvel-move).call() do_bump(move).call()
lvel = -move var rem := lvel % 2
ball_here.do_push(lvel/2 + rem).call()
lvel = -lvel/2
else: else:
lpos = lpos lpos = lpos
lvel -= move lvel -= move
@ -89,6 +93,19 @@ func undo_push() -> Callable:
lvel = old_vel lvel = old_vel
anim_progress = 1 anim_progress = 1
# no logical effect, purely for aesthetics
# (and communicating !!!! player yes)
func do_bump(move: Vector2i) -> Callable:
var real_lpos := lpos
return func():
lpos += move
lpos = real_lpos
anim_progress = 0.5
# TODO?: maybe fix? maybe the bump should be more complicated?
func undo_bump(move: Vector2i) -> Callable:
return do_bump(move)
static func ball(pos: Vector2i) -> Piece: static func ball(pos: Vector2i) -> Piece:
return BALL.instantiate().with_lpos(pos) return BALL.instantiate().with_lpos(pos)