basic collisions, pool level

This commit is contained in:
mehbark 2025-05-04 13:52:51 -04:00
parent ff40f68ef7
commit 379ea91bbc
4 changed files with 24 additions and 7 deletions

View file

@ -42,7 +42,7 @@ func type_at(pos: Vector2i, type: Piece.Type) -> Piece:
# TODO: ball collisions # TODO: ball collisions
func solid_at(pos: Vector2i) -> bool: func solid_at(pos: Vector2i) -> bool:
return any_at(pos, func(p): return p.type == Piece.Type.Wall or p.type == Piece.Type.Ball) return any_at(pos, func(p): return p.type == Piece.Type.Wall or p.type == Piece.Type.Ball or p.type == Piece.Type.Player)
func passable_at(pos: Vector2i) -> bool: func passable_at(pos: Vector2i) -> bool:
return not solid_at(pos) return not solid_at(pos)

View file

@ -12,6 +12,7 @@
; second level is the same layout but the *floor* is different ; second level is the same layout but the *floor* is different
; TODO: multiple levels (could just be stacked on top) ; TODO: multiple levels (could just be stacked on top)
; TODO: notation for ball on ice ; TODO: notation for ball on ice
; TODO: levels.gd
; 1 ; 1
@ -41,3 +42,9 @@
# o# # o#
###o.# ###o.#
#### ####
; 4 pool
#############
# @ o o_ . #
#############

View file

@ -134,7 +134,7 @@ func advance_level():
advancing = true advancing = true
if level_num != 0: if level_num != 0:
print("level won") print("level won")
await get_tree().create_timer(2).timeout await get_tree().create_timer(0.5).timeout
advancing = false advancing = false
time = 0 time = 0
level_num += 1 level_num += 1

View file

@ -45,14 +45,21 @@ var speedometer: Label3D
func do_step(board: Board): func do_step(board: Board):
if lvel == Vector2i.ZERO: if lvel == Vector2i.ZERO:
return return
if board.solid_at(lpos + lvel.clampi(-1, 1)): var move := lvel.clampi(-1, 1)
lpos = lpos var new_pos := lpos + move
lvel -= lvel.clampi(-1, 1) if board.solid_at(new_pos):
var ball := board.type_at(new_pos, Piece.Type.Ball)
if ball:
ball.do_push(lvel-move).call()
lvel = -move
else:
lpos = lpos
lvel -= move
return return
lpos += lvel.clampi(-1, 1) lpos = new_pos
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 -= lvel.clampi(-1, 1) lvel -= move
func undo_step() -> Callable: func undo_step() -> Callable:
var old_pos := lpos var old_pos := lpos
@ -110,6 +117,9 @@ func _ready() -> void:
speedometer.billboard = BaseMaterial3D.BILLBOARD_ENABLED speedometer.billboard = BaseMaterial3D.BILLBOARD_ENABLED
speedometer.no_depth_test = true speedometer.no_depth_test = true
speedometer.font_size = 64 speedometer.font_size = 64
var font := SystemFont.new()
font.font_names = PackedStringArray(["monospace"])
speedometer.font = font
add_child(speedometer) add_child(speedometer)
#TODO: arrow! #TODO: arrow!