use specific texture part for pieces
This commit is contained in:
parent
efcb9ca4ed
commit
4419e84e25
|
@ -4,15 +4,17 @@ tool
|
|||
|
||||
export var size: int = 64
|
||||
var number: int = 0
|
||||
|
||||
func set_number(num: int) -> void:
|
||||
number = num
|
||||
var taquin_position = Vector2(0, 0)
|
||||
var piece_scale = Vector2(0.25, 0.25)
|
||||
|
||||
func _ready() -> void:
|
||||
$ColorRect.rect_size.x = size
|
||||
$ColorRect.rect_size.y = size
|
||||
$ColorRect/Label.text = str(number)
|
||||
|
||||
var shader = $ColorRect.material as ShaderMaterial
|
||||
shader.set_shader_param("scale", Vector3(0.5, 0.5, 1.0))
|
||||
shader.set_shader_param("offset", Vector3(0.8, 0.1, 0.0))
|
||||
# We need a dedicated material to have separate uniform,
|
||||
# otherwise uniforms will be shared.
|
||||
var mat = $ColorRect.material.duplicate() as ShaderMaterial
|
||||
mat.set_shader_param("scale", Vector3(piece_scale.x, piece_scale.y, 1.0))
|
||||
mat.set_shader_param("offset", Vector3(taquin_position.x, taquin_position.y, 0.0))
|
||||
$ColorRect.material = mat
|
||||
|
|
|
@ -1,31 +1,37 @@
|
|||
[gd_scene load_steps=11 format=2]
|
||||
[gd_scene load_steps=13 format=2]
|
||||
|
||||
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
|
||||
[ext_resource path="res://assets/escher_lizards.jpg" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="VisualShaderNodeTexture" id=2]
|
||||
[sub_resource type="VisualShaderNodeVec3Constant" id=11]
|
||||
constant = Vector3( 0.3, 0.3, 0 )
|
||||
|
||||
[sub_resource type="VisualShaderNodeTexture" id=1]
|
||||
output_port_for_preview = 0
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="VisualShaderNodeInput" id=5]
|
||||
[sub_resource type="VisualShaderNodeInput" id=2]
|
||||
output_port_for_preview = 0
|
||||
input_name = "uv"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=6]
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=3]
|
||||
output_port_for_preview = 0
|
||||
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.5, 0.5, 1 ) ]
|
||||
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.25, 0.25, 1 ) ]
|
||||
operator = 2
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=7]
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=4]
|
||||
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.8, 0.1, 0 ) ]
|
||||
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=8]
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=5]
|
||||
uniform_name = "scale"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=9]
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=6]
|
||||
uniform_name = "offset"
|
||||
|
||||
[sub_resource type="VisualShader" id=3]
|
||||
[sub_resource type="VisualShaderNodeVec3Constant" id=9]
|
||||
constant = Vector3( 0.25, 0.25, 1 )
|
||||
|
||||
[sub_resource type="VisualShader" id=7]
|
||||
code = "shader_type canvas_item;
|
||||
uniform vec3 scale;
|
||||
uniform vec3 offset;
|
||||
|
@ -75,34 +81,38 @@ void light() {
|
|||
|
||||
}
|
||||
"
|
||||
graph_offset = Vector2( -175, -3.73047 )
|
||||
graph_offset = Vector2( -352.066, -39.2305 )
|
||||
mode = 1
|
||||
flags/light_only = false
|
||||
nodes/fragment/0/position = Vector2( 1080, 160 )
|
||||
nodes/fragment/3/node = SubResource( 2 )
|
||||
nodes/fragment/3/node = SubResource( 1 )
|
||||
nodes/fragment/3/position = Vector2( 820, 120 )
|
||||
nodes/fragment/4/node = SubResource( 5 )
|
||||
nodes/fragment/4/position = Vector2( 140, 120 )
|
||||
nodes/fragment/5/node = SubResource( 6 )
|
||||
nodes/fragment/5/position = Vector2( 360, 100 )
|
||||
nodes/fragment/6/node = SubResource( 7 )
|
||||
nodes/fragment/6/position = Vector2( 620, 220 )
|
||||
nodes/fragment/7/node = SubResource( 8 )
|
||||
nodes/fragment/7/position = Vector2( 140, 320 )
|
||||
nodes/fragment/8/node = SubResource( 9 )
|
||||
nodes/fragment/8/position = Vector2( 420, 360 )
|
||||
nodes/fragment/4/node = SubResource( 2 )
|
||||
nodes/fragment/4/position = Vector2( 40, 60 )
|
||||
nodes/fragment/5/node = SubResource( 3 )
|
||||
nodes/fragment/5/position = Vector2( 360, 80 )
|
||||
nodes/fragment/6/node = SubResource( 4 )
|
||||
nodes/fragment/6/position = Vector2( 620, 240 )
|
||||
nodes/fragment/7/node = SubResource( 5 )
|
||||
nodes/fragment/7/position = Vector2( 40, 240 )
|
||||
nodes/fragment/8/node = SubResource( 6 )
|
||||
nodes/fragment/8/position = Vector2( 360, 380 )
|
||||
nodes/fragment/9/node = SubResource( 9 )
|
||||
nodes/fragment/9/position = Vector2( 40, 300 )
|
||||
nodes/fragment/11/node = SubResource( 11 )
|
||||
nodes/fragment/11/position = Vector2( 360, 440 )
|
||||
nodes/fragment/connections = PoolIntArray( 3, 0, 0, 0, 4, 0, 5, 0, 5, 0, 6, 0, 6, 0, 3, 0, 7, 0, 5, 1, 8, 0, 6, 1 )
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=4]
|
||||
shader = SubResource( 3 )
|
||||
shader_param/scale = null
|
||||
shader_param/offset = null
|
||||
[sub_resource type="ShaderMaterial" id=12]
|
||||
shader = SubResource( 7 )
|
||||
shader_param/scale = Vector3( 1, 1, 1 )
|
||||
shader_param/offset = Vector3( 0.75, 0.75, 0 )
|
||||
|
||||
[node name="Piece" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
material = SubResource( 4 )
|
||||
material = SubResource( 12 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 64.0
|
||||
|
|
|
@ -12,17 +12,15 @@ export var width: int = 512
|
|||
export var height: int = 512
|
||||
export var difficulty: int = 10
|
||||
|
||||
var interpiece: int = 5
|
||||
var padding = 10
|
||||
var interpiece: int = 4
|
||||
var padding = 15
|
||||
|
||||
var pieces: Array = []
|
||||
var missing_piece: Vector2
|
||||
var rng = RandomNumberGenerator.new()
|
||||
|
||||
func position_for_index(index: Vector2, size: int) -> Vector2:
|
||||
var padding_w = (width - (size * columns)) / (columns + 1)
|
||||
var padding_h = (height - (size * rows)) / (rows + 1)
|
||||
return Vector2(padding_w + index.x * (size + padding_w), padding_h + index.y * (size + padding_h))
|
||||
return Vector2(padding + index.x * (size + interpiece), padding + index.y * (size + interpiece))
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -39,7 +37,9 @@ func _ready() -> void:
|
|||
|
||||
piece.size = piece_size
|
||||
piece.position = position_for_index(Vector2(c, r), piece.size)
|
||||
piece.set_number(1 + c + r * columns)
|
||||
piece.number = 1 + c + r * columns
|
||||
piece.piece_scale = Vector2((float(piece_size) / width), (float(piece_size) / height))
|
||||
piece.taquin_position = Vector2(float(piece.position.x) / width, float(piece.position.y) / height)
|
||||
|
||||
if r == rows - 1 && c == columns - 1:
|
||||
piece.visible = false
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
[node name="Taquin" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
rows = 3
|
||||
columns = 3
|
||||
difficulty = 0
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
margin_right = 512.0
|
||||
|
|
Loading…
Reference in a new issue