[ext_resource type="PackedScene" uid="uid://36g8xep7m4ly" path="res://piece/T-piece.tscn" id="7_6upfg"]
[node name="Board" type="Control"]
-custom_minimum_size = Vector2(200, 400)
+custom_minimum_size = Vector2(200, 500)
layout_mode = 3
anchors_preset = 5
anchor_left = 0.5
layout_mode = 2
alignment = 1
+[node name="VSplitContainer3" type="HSplitContainer" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer"]
+layout_mode = 2
+split_offset = 150
+dragging_enabled = false
+
+[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer3"]
+layout_mode = 2
+text = "Score:"
+horizontal_alignment = 2
+
+[node name="label_score" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer3"]
+unique_name_in_owner = true
+layout_mode = 2
+text = "0"
+
[node name="VSplitContainer2" type="HSplitContainer" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer"]
layout_mode = 2
split_offset = 150
[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer2"]
layout_mode = 2
text = "Time passed:"
+horizontal_alignment = 2
[node name="label_time_passed" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer2"]
unique_name_in_owner = true
[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer"]
layout_mode = 2
text = "Number of pieces:"
+horizontal_alignment = 2
[node name="label_num_pieces" type="Label" parent="MarginContainer/HBoxContainer/right/MarginContainer/VBoxContainer/VSplitContainer"]
unique_name_in_owner = true
_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))
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
_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)
var cells: Array[Cell] = []
var block_size: int = 0
-var cell_grid: Array[Vector2i] = []
+var _cell_grid: Array[Vector2i] = []
+
+var _rotation_angles: Array[float] = [0.0, 90.0, 180.0, 270.0]
+var _rotation_index: int = 0
+
func _ready() -> void:
for c in self.get_children():
for c in cells:
var pos_x: int = floori(c.position.x / block_size)
var pos_y: int = floori(c.position.y / block_size)
- cell_grid.append(Vector2i(pos_x, pos_y))
+ _cell_grid.append(Vector2i(pos_x, pos_y))
func _to_string() -> String:
- return str(cell_grid)
+ return "%d: %s" % [rotation_degrees, str(get_cell_grid())]
+
+
+func get_cell_grid() -> Array:
+ if rotation_degrees == 0.0:
+ return _cell_grid
+ elif rotation_degrees == 90.0:
+ return _cell_grid.map(func f(v): return Vector2i(v.y, v.x))
+ elif rotation_degrees == 180.0:
+ return _cell_grid.map(func f(v): return Vector2i(-v.x, -v.y))
+ elif rotation_degrees == 270.0:
+ return _cell_grid.map(func f(v): return Vector2i(-v.y, -v.x))
+ else:
+ assert(false, "Invalid rotation: " + str(global_rotation_degrees))
+ return []
+
+
+func rotate_left():
+ _rotation_index += 1
+ rotation_degrees = _rotation_angles[_rotation_index % _rotation_angles.size()]