X-Git-Url: http://git.purplebirdman.com/catris.git/blobdiff_plain/35c13ea7b3cdfe2da392fbd9c5b0c7aac97f5d6f..859af48f3aea3fd3dde07c42a79d795feb905761:/script/board.gd diff --git a/script/board.gd b/script/board.gd index f820e00..2e90425 100644 --- a/script/board.gd +++ b/script/board.gd @@ -16,6 +16,7 @@ var _grid_final_y_row: int = 0 var _grid_final_x_row: int = 0 var num_pieces: int = 0 +const start_pos: Vector2i = Vector2i(5, 2) func _ready() -> void: assert(piece_catalogue.size() >= 1, "Expected at least one piece in catalogue") @@ -39,8 +40,9 @@ func _input(event: InputEvent) -> void: _move(Vector2i(1, 0)) if event.is_action_pressed("player_up"): - # TODO: rotate - pass + if _player_piece: + _player_piece.rotate_left() + print(_player_piece.to_string()) if event.is_action("player_down"): _move(Vector2i(0, 1)) @@ -52,7 +54,7 @@ func _add_player_piece(): piece.block_size = block_size # TODO: start piece at center of board - _player_position = Vector2i(5, 0) + _player_position = start_pos piece.position = _player_position * block_size _player_piece = piece @@ -68,7 +70,7 @@ func _move(v: Vector2i): var new_player_position: Vector2i = _player_position + v # for each cell in the block, offset it by new position and check for collision - for pos: Vector2i in _player_piece.cell_grid: + for pos: Vector2i in _player_piece.get_cell_grid(): pos += new_player_position if pos.x < 0 or pos.x >= _grid_final_x_row: # ignore input that moves beyond lateral boundaries @@ -86,14 +88,15 @@ func _move(v: Vector2i): _player_piece.position = _player_position * block_size # if any cell's at the bottom of the grid, we're done - for pos: Vector2i in _player_piece.cell_grid: + for pos: Vector2i in _player_piece.get_cell_grid(): pos += _player_position if (pos.y >= _grid_final_y_row - 1): end_round.emit() + func _on_end_round(): # fill in collision grid with piece cells - for pos: Vector2i in _player_piece.cell_grid: + for pos: Vector2i in _player_piece.get_cell_grid(): pos += _player_position _set_grid_position(pos, true)