Add block collision

This commit is contained in:
karl 2021-11-17 18:24:58 +01:00
parent d18fec84bf
commit 89fd29430e

View File

@ -19,15 +19,33 @@ func get_random_shape():
func update_board():
if active_shape.position.y == RASTER_SIZE * 10:
if can_active_move_down():
move_active_down()
else:
turn_active_into_static()
check_for_full_line()
active_shape = get_random_shape()
func move_active_down():
active_shape.position.y += RASTER_SIZE
func can_active_move_down():
if active_shape.position.y >= RASTER_SIZE * 10:
return false
for block in active_shape.get_blocks():
var down_x = block.global_position.x
var down_y = block.global_position.y + RASTER_SIZE
if is_block_at_position(down_x, down_y):
return false
return true
func turn_active_into_static():
for block in active_shape.get_blocks():
var global_shape_position = block.global_position
@ -72,12 +90,21 @@ func rotate_shape():
func drop():
active_shape.position.y = BOTTOM
while can_active_move_down():
move_active_down()
# Restart the timer to give full time for sliding the piece
$GravityTimer.start()
func is_block_at_position(pos_x, pos_y):
for block in $StaticBlocks.get_children():
if block.global_position.x == pos_x and block.global_position.y == pos_y:
return true
return false
func _input(event):
if event.is_action_pressed("move_left"):
move_left()