stretch pieces to fill taquin
This commit is contained in:
parent
1032891929
commit
13f0663963
|
@ -8,6 +8,8 @@ export var rows: int = 4
|
||||||
export var columns: int = 4
|
export var columns: int = 4
|
||||||
export var width: int = 512
|
export var width: int = 512
|
||||||
export var height: int = 512
|
export var height: int = 512
|
||||||
|
var interpiece: int = 5
|
||||||
|
var padding = 10
|
||||||
|
|
||||||
var pieces: Array = []
|
var pieces: Array = []
|
||||||
var missing_piece: Vector2
|
var missing_piece: Vector2
|
||||||
|
@ -24,12 +26,14 @@ func position_for_index(index: Vector2, size: int) -> Vector2:
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
rng.randomize()
|
rng.randomize()
|
||||||
|
var piece_size: int = compute_piece_size()
|
||||||
|
|
||||||
for c in range(columns):
|
for c in range(columns):
|
||||||
var pieces_row: Array = []
|
var pieces_row: Array = []
|
||||||
for r in range(rows):
|
for r in range(rows):
|
||||||
var piece = Piece.instance()
|
var piece = Piece.instance()
|
||||||
|
|
||||||
|
piece.size = piece_size
|
||||||
piece.position = position_for_index(Vector2(c, r), piece.size)
|
piece.position = position_for_index(Vector2(c, r), piece.size)
|
||||||
piece.set_number(1 + c + r * columns)
|
piece.set_number(1 + c + r * columns)
|
||||||
|
|
||||||
|
@ -45,6 +49,11 @@ func _ready() -> void:
|
||||||
|
|
||||||
shuffle(10)
|
shuffle(10)
|
||||||
|
|
||||||
|
func compute_piece_size() -> int:
|
||||||
|
var w_size: int = (width - (2 * padding) - ((columns - 1) * interpiece)) / columns
|
||||||
|
var h_size: int = (height - (2 * padding) - ((rows - 1) * interpiece)) / rows
|
||||||
|
return int(min(w_size, h_size))
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("ui_up"):
|
if event.is_action_pressed("ui_up"):
|
||||||
move_piece(Direction.DOWN)
|
move_piece(Direction.DOWN)
|
||||||
|
|
Loading…
Reference in a new issue