set piece reflection when winning
This commit is contained in:
parent
6b17d2ea8a
commit
9830c5c51d
|
@ -18,8 +18,13 @@ func _ready() -> void:
|
|||
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))
|
||||
mat.set_shader_param("reflection", false)
|
||||
$ColorRect.material = mat
|
||||
|
||||
func set_reflection(value: bool) -> void:
|
||||
var mat = $ColorRect.material as ShaderMaterial
|
||||
mat.set_shader_param("reflection", value)
|
||||
|
||||
func debug_print(name: String):
|
||||
print("%s order: %s" % [name, order])
|
||||
print("%s taquin index: %s" % [name, taquin_index])
|
||||
|
|
136
src/Piece.tscn
136
src/Piece.tscn
|
@ -1,9 +1,9 @@
|
|||
[gd_scene load_steps=14 format=2]
|
||||
[gd_scene load_steps=19 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="VisualShaderNodeExpression" id=12]
|
||||
[sub_resource type="VisualShaderNodeExpression" id=1]
|
||||
output_port_for_preview = 0
|
||||
size = Vector2( 657, 584 )
|
||||
expression = "// https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
|
||||
|
@ -20,36 +20,58 @@ vec2 d_thick = abs(rel_p) - box_thick;
|
|||
float dist_thick = length(max(d_thick, 0.0)) + min(max(d_thick.x, d_thick.y), 0.0);
|
||||
is_thickness = rel_p.y > 0.0 && dist_thick > (0.5 - box_size);"
|
||||
|
||||
[sub_resource type="VisualShaderNodeColorConstant" id=13]
|
||||
[sub_resource type="VisualShaderNodeColorConstant" id=2]
|
||||
constant = Color( 0.734375, 0.347832, 0.0657608, 1 )
|
||||
|
||||
[sub_resource type="VisualShaderNodeSwitch" id=14]
|
||||
[sub_resource type="VisualShaderNodeSwitch" id=3]
|
||||
output_port_for_preview = 0
|
||||
|
||||
[sub_resource type="VisualShaderNodeTexture" id=2]
|
||||
[sub_resource type="VisualShaderNodeExpression" id=4]
|
||||
output_port_for_preview = 0
|
||||
size = Vector2( 545, 407 )
|
||||
expression = "float speed = 2.0;
|
||||
float delta = mod(t * speed, 3) - 1.0;
|
||||
float slope = 1.5;
|
||||
float thickness = 0.05;
|
||||
if (abs(input0.x - ((1.0 - input0.y + delta) / slope)) < thickness) {
|
||||
output0 = vec3(0.5);
|
||||
}"
|
||||
|
||||
[sub_resource type="VisualShaderNodeColorOp" id=14]
|
||||
|
||||
[sub_resource type="VisualShaderNodeInput" id=15]
|
||||
input_name = "time"
|
||||
|
||||
[sub_resource type="VisualShaderNodeSwitch" id=16]
|
||||
|
||||
[sub_resource type="VisualShaderNodeBooleanUniform" id=17]
|
||||
uniform_name = "reflection"
|
||||
|
||||
[sub_resource type="VisualShaderNodeTexture" id=6]
|
||||
output_port_for_preview = 0
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="VisualShaderNodeInput" id=3]
|
||||
[sub_resource type="VisualShaderNodeInput" id=7]
|
||||
output_port_for_preview = 0
|
||||
input_name = "uv"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=4]
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=8]
|
||||
output_port_for_preview = 0
|
||||
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.25, 0.25, 1 ) ]
|
||||
operator = 2
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=5]
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id=9]
|
||||
default_input_values = [ 0, Vector3( 0, 0, 0 ), 1, Vector3( 0.8, 0.1, 0 ) ]
|
||||
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=6]
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=10]
|
||||
uniform_name = "scale"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=7]
|
||||
[sub_resource type="VisualShaderNodeVec3Uniform" id=11]
|
||||
uniform_name = "offset"
|
||||
|
||||
[sub_resource type="VisualShader" id=9]
|
||||
[sub_resource type="VisualShader" id=12]
|
||||
code = "shader_type canvas_item;
|
||||
uniform bool reflection;
|
||||
uniform vec3 scale;
|
||||
uniform vec3 offset;
|
||||
uniform sampler2D tex_frg_3;
|
||||
|
@ -90,6 +112,9 @@ void fragment() {
|
|||
vec3 n_out15p0 = vec3(0.734375, 0.347832, 0.065761);
|
||||
float n_out15p1 = 1.000000;
|
||||
|
||||
// BooleanUniform:24
|
||||
bool n_out24p0 = reflection;
|
||||
|
||||
// VectorUniform:7
|
||||
vec3 n_out7p0 = scale;
|
||||
|
||||
|
@ -107,6 +132,36 @@ void fragment() {
|
|||
vec3 n_out3p0 = tex_frg_3_read.rgb;
|
||||
float n_out3p1 = tex_frg_3_read.a;
|
||||
|
||||
// Input:22
|
||||
float n_out22p0 = TIME;
|
||||
|
||||
// Expression:19
|
||||
vec3 n_out19p0;
|
||||
n_out19p0 = vec3(0.0, 0.0, 0.0);
|
||||
{
|
||||
float speed = 2.0;
|
||||
float delta = mod(n_out22p0 * speed, 3) - 1.0;
|
||||
float slope = 1.5;
|
||||
float thickness = 0.05;
|
||||
if (abs(n_out6p0.x - ((1.0 - n_out6p0.y + delta) / slope)) < thickness) {
|
||||
n_out19p0 = vec3(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
// ColorOp:21
|
||||
vec3 n_out21p0 = vec3(1.0) - (vec3(1.0) - n_out3p0) * (vec3(1.0) - n_out19p0);
|
||||
|
||||
// VectorSwitch:23
|
||||
vec3 n_out23p0;
|
||||
if(n_out24p0)
|
||||
{
|
||||
n_out23p0 = n_out21p0;
|
||||
}
|
||||
else
|
||||
{
|
||||
n_out23p0 = n_out3p0;
|
||||
}
|
||||
|
||||
// VectorSwitch:17
|
||||
vec3 n_out17p0;
|
||||
if(n_out13p1)
|
||||
|
@ -115,7 +170,7 @@ void fragment() {
|
|||
}
|
||||
else
|
||||
{
|
||||
n_out17p0 = n_out3p0;
|
||||
n_out17p0 = n_out23p0;
|
||||
}
|
||||
|
||||
// Output:0
|
||||
|
@ -129,23 +184,23 @@ void light() {
|
|||
|
||||
}
|
||||
"
|
||||
graph_offset = Vector2( -268.615, -149.836 )
|
||||
graph_offset = Vector2( 463.214, -151.656 )
|
||||
mode = 1
|
||||
flags/light_only = false
|
||||
nodes/fragment/0/position = Vector2( 1400, 300 )
|
||||
nodes/fragment/3/node = SubResource( 2 )
|
||||
nodes/fragment/0/position = Vector2( 1480, 300 )
|
||||
nodes/fragment/3/node = SubResource( 6 )
|
||||
nodes/fragment/3/position = Vector2( 740, 20 )
|
||||
nodes/fragment/4/node = SubResource( 3 )
|
||||
nodes/fragment/4/node = SubResource( 7 )
|
||||
nodes/fragment/4/position = Vector2( 0, 260 )
|
||||
nodes/fragment/5/node = SubResource( 4 )
|
||||
nodes/fragment/5/node = SubResource( 8 )
|
||||
nodes/fragment/5/position = Vector2( 280, -20 )
|
||||
nodes/fragment/6/node = SubResource( 5 )
|
||||
nodes/fragment/6/node = SubResource( 9 )
|
||||
nodes/fragment/6/position = Vector2( 540, 140 )
|
||||
nodes/fragment/7/node = SubResource( 6 )
|
||||
nodes/fragment/7/node = SubResource( 10 )
|
||||
nodes/fragment/7/position = Vector2( -20, 60 )
|
||||
nodes/fragment/8/node = SubResource( 7 )
|
||||
nodes/fragment/8/node = SubResource( 11 )
|
||||
nodes/fragment/8/position = Vector2( 300, 240 )
|
||||
nodes/fragment/13/node = SubResource( 12 )
|
||||
nodes/fragment/13/node = SubResource( 1 )
|
||||
nodes/fragment/13/position = Vector2( 340, 400 )
|
||||
nodes/fragment/13/size = Vector2( 657, 584 )
|
||||
nodes/fragment/13/input_ports = "0,1,input;"
|
||||
|
@ -163,23 +218,44 @@ vec2 box_thick = vec2(box_size, box_size - thickness);
|
|||
vec2 d_thick = abs(rel_p) - box_thick;
|
||||
float dist_thick = length(max(d_thick, 0.0)) + min(max(d_thick.x, d_thick.y), 0.0);
|
||||
is_thickness = rel_p.y > 0.0 && dist_thick > (0.5 - box_size);"
|
||||
nodes/fragment/15/node = SubResource( 13 )
|
||||
nodes/fragment/15/position = Vector2( 780, -100 )
|
||||
nodes/fragment/17/node = SubResource( 14 )
|
||||
nodes/fragment/17/position = Vector2( 1080, 20 )
|
||||
nodes/fragment/connections = PoolIntArray( 5, 0, 6, 0, 6, 0, 3, 0, 13, 0, 0, 1, 4, 0, 5, 0, 4, 0, 13, 0, 13, 1, 17, 0, 15, 0, 17, 1, 3, 0, 17, 2, 17, 0, 0, 0, 8, 0, 6, 1, 7, 0, 5, 1 )
|
||||
nodes/fragment/15/node = SubResource( 2 )
|
||||
nodes/fragment/15/position = Vector2( 1280, 0 )
|
||||
nodes/fragment/17/node = SubResource( 3 )
|
||||
nodes/fragment/17/position = Vector2( 1260, 120 )
|
||||
nodes/fragment/19/node = SubResource( 4 )
|
||||
nodes/fragment/19/position = Vector2( 420, -500 )
|
||||
nodes/fragment/19/size = Vector2( 545, 407 )
|
||||
nodes/fragment/19/input_ports = "0,1,input0;1,0,t;"
|
||||
nodes/fragment/19/output_ports = "0,1,output0;"
|
||||
nodes/fragment/19/expression = "float speed = 2.0;
|
||||
float delta = mod(t * speed, 3) - 1.0;
|
||||
float slope = 1.5;
|
||||
float thickness = 0.05;
|
||||
if (abs(input0.x - ((1.0 - input0.y + delta) / slope)) < thickness) {
|
||||
output0 = vec3(0.5);
|
||||
}"
|
||||
nodes/fragment/21/node = SubResource( 14 )
|
||||
nodes/fragment/21/position = Vector2( 1020, -160 )
|
||||
nodes/fragment/22/node = SubResource( 15 )
|
||||
nodes/fragment/22/position = Vector2( 160, -300 )
|
||||
nodes/fragment/23/node = SubResource( 16 )
|
||||
nodes/fragment/23/position = Vector2( 1000, 60 )
|
||||
nodes/fragment/24/node = SubResource( 17 )
|
||||
nodes/fragment/24/position = Vector2( 1000, -20 )
|
||||
nodes/fragment/connections = PoolIntArray( 5, 0, 6, 0, 6, 0, 3, 0, 13, 0, 0, 1, 4, 0, 5, 0, 4, 0, 13, 0, 13, 1, 17, 0, 15, 0, 17, 1, 17, 0, 0, 0, 8, 0, 6, 1, 7, 0, 5, 1, 3, 0, 21, 0, 19, 0, 21, 1, 22, 0, 19, 1, 6, 0, 19, 0, 24, 0, 23, 0, 3, 0, 23, 2, 21, 0, 23, 1, 23, 0, 17, 2 )
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=10]
|
||||
shader = SubResource( 9 )
|
||||
[sub_resource type="ShaderMaterial" id=13]
|
||||
shader = SubResource( 12 )
|
||||
shader_param/reflection = false
|
||||
shader_param/scale = Vector3( 0.25, 0.25, 1 )
|
||||
shader_param/offset = Vector3( 0.3, 0.3, 0 )
|
||||
shader_param/offset = Vector3( 0, 0, 0 )
|
||||
|
||||
[node name="Piece" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
size = 64
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
material = SubResource( 10 )
|
||||
material = SubResource( 13 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 64.0
|
||||
|
|
|
@ -301,6 +301,12 @@ func ensure_validity() -> void:
|
|||
assert(piece.taquin_index.x == c)
|
||||
assert(piece.taquin_index.y == r)
|
||||
|
||||
func set_pieces_reflection(value: bool) -> void:
|
||||
for c in range(columns):
|
||||
for r in range(rows):
|
||||
var piece = pieces[c][r]
|
||||
piece.set_reflection(value)
|
||||
|
||||
func current_state_name() -> String:
|
||||
return State.keys()[current_state]
|
||||
|
||||
|
@ -313,6 +319,7 @@ func transition_to(state):
|
|||
match current_state:
|
||||
State.WINNING:
|
||||
$Particles2D.emitting = true
|
||||
set_pieces_reflection(true)
|
||||
$Timer.start(-1)
|
||||
State.GAME_OVER:
|
||||
$Particles2D.emitting = false
|
||||
|
|
Loading…
Reference in a new issue