]> Untitled Git - catris.git/blob - script/piece.gd
Added pieces. Needs proper collision handling
[catris.git] / script / piece.gd
1 extends Node2D
2 class_name Piece
3
4
5 @export var piece_name: String = ""
6
7 var cells: Array[Cell] = []
8 var block_size: int = 0
9
10 var cell_grid: Array[Vector2i] = []
11
12 func _ready() -> void:
13         for c in self.get_children():
14                 if c is Cell:
15                         cells.append(c)
16         
17         # all cells must have same block size
18         for c in cells:
19                 if block_size == 0:
20                         block_size = c.block_size
21                 else:
22                         assert(block_size == c.block_size, "All cells must have same block size")
23         
24         # build cell grid coordinates
25         for c in cells:
26                 var pos_x: int = floori(c.position.x / block_size)
27                 var pos_y: int = floori(c.position.y / block_size)
28                 cell_grid.append(Vector2i(pos_x, pos_y))