center pieces inside taquin
This commit is contained in:
parent
ed8c3576c4
commit
fb287b8264
|
@ -13,7 +13,8 @@ export var height: int = 512
|
|||
export var difficulty: int = 10
|
||||
|
||||
var interpiece: int = 4
|
||||
var padding = 15
|
||||
var min_padding = 15
|
||||
var padding = Vector2(min_padding, min_padding)
|
||||
|
||||
var pieces: Array = []
|
||||
var missing_piece: Vector2
|
||||
|
@ -24,8 +25,19 @@ var current_animation_path: String = "AnimationPlayer/MockPiece:position"
|
|||
var swipe = Vector2(0, 0)
|
||||
|
||||
func position_for_index(index: Vector2, size: int) -> Vector2:
|
||||
return Vector2(padding + index.x * (size + interpiece), padding + index.y * (size + interpiece))
|
||||
|
||||
return padding + Vector2(index.x * (size + interpiece), index.y * (size + interpiece))
|
||||
|
||||
func compute_piece_size() -> int:
|
||||
var w_size: int = (width - (2 * min_padding) - ((columns - 1) * interpiece)) / columns
|
||||
var h_size: int = (height - (2 * min_padding) - ((rows - 1) * interpiece)) / rows
|
||||
return int(min(w_size, h_size))
|
||||
|
||||
func compute_padding(piece_size: int) -> Vector2:
|
||||
var padding = Vector2(0, 0)
|
||||
padding.x = width - columns * piece_size - (columns - 1) * interpiece
|
||||
padding.y = height - rows * piece_size - (rows - 1) * interpiece
|
||||
padding = padding / Vector2(2, 2)
|
||||
return padding
|
||||
|
||||
func _ready() -> void:
|
||||
$AnimationPlayer/MockPiece.visible = false
|
||||
|
@ -35,6 +47,9 @@ func _ready() -> void:
|
|||
|
||||
rng.randomize()
|
||||
var piece_size: int = compute_piece_size()
|
||||
padding = compute_padding(piece_size)
|
||||
print("piece size: ", piece_size)
|
||||
print("padding: ", padding)
|
||||
|
||||
for c in range(columns):
|
||||
var pieces_row: Array = []
|
||||
|
@ -59,11 +74,6 @@ func _ready() -> void:
|
|||
|
||||
shuffle(difficulty)
|
||||
|
||||
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):
|
||||
if $AnimationPlayer.is_playing():
|
||||
# Disable input during animation
|
||||
|
|
|
@ -23,8 +23,8 @@ tracks/0/keys = {
|
|||
[node name="Taquin" type="Control"]
|
||||
rect_min_size = Vector2( 540, 540 )
|
||||
script = ExtResource( 1 )
|
||||
rows = 3
|
||||
columns = 3
|
||||
rows = 5
|
||||
columns = 5
|
||||
difficulty = 0
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
|
|
Loading…
Reference in a new issue