From 8a720717e4ebc01d1460e4723f3990d322ca31f0 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 27 Nov 2019 00:50:35 +0100 Subject: [PATCH] refactor with ColorRect --- game/src/Piece.gd | 8 +++--- game/src/Piece.tscn | 62 ++++++++++++++++++++++++++++++++++++++++---- game/src/Taquin.gd | 9 ++++--- game/src/Taquin.tscn | 5 ++++ 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/game/src/Piece.gd b/game/src/Piece.gd index c63c7d3..e6779ae 100644 --- a/game/src/Piece.gd +++ b/game/src/Piece.gd @@ -5,11 +5,13 @@ tool export var size: int = 64 var number: int = 0 -func _draw() -> void: - draw_rect(Rect2(0, 0, size, size), Color.yellow) +#func _draw() -> void: +# draw_rect(Rect2(0, 0, size, size), Color.yellow) func set_number(num: int) -> void: number = num func _ready() -> void: - $Label.text = str(number) + $ColorRect.rect_size.x = size + $ColorRect.rect_size.y = size + $ColorRect/Label.text = str(number) diff --git a/game/src/Piece.tscn b/game/src/Piece.tscn index a4b700f..1e783fb 100644 --- a/game/src/Piece.tscn +++ b/game/src/Piece.tscn @@ -1,12 +1,64 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://src/Piece.gd" type="Script" id=1] +[sub_resource type="VisualShaderNodeColorConstant" id=1] +constant = Color( 0.73997, 0.960938, 0.446686, 1 ) + +[sub_resource type="VisualShader" id=2] +code = "shader_type canvas_item; + + + +void vertex() { +// Output:0 + +} + +void fragment() { +// Color:2 + vec3 n_out2p0; + float n_out2p1; + n_out2p0 = vec3(0.739970,0.960938,0.446686); + n_out2p1 = 1.000000; + +// Output:0 + COLOR.rgb = n_out2p0; + +} + +void light() { +// Output:0 + +} +" +mode = 1 +flags/light_only = false +nodes/fragment/0/position = Vector2( 380, 80 ) +nodes/fragment/2/node = SubResource( 1 ) +nodes/fragment/2/position = Vector2( 140, 80 ) +nodes/fragment/connections = PoolIntArray( 2, 0, 0, 0 ) + +[sub_resource type="ShaderMaterial" id=3] +shader = SubResource( 2 ) + [node name="Piece" type="Node2D"] script = ExtResource( 1 ) -[node name="Label" type="Label" parent="."] -margin_right = 40.0 -margin_bottom = 14.0 +[node name="ColorRect" type="ColorRect" parent="."] +material = SubResource( 3 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = 128.0 +margin_bottom = 128.0 + +[node name="Label" type="Label" parent="ColorRect"] +margin_left = 10.0 +margin_top = 10.0 +margin_right = 50.0 +margin_bottom = 50.0 +rect_scale = Vector2( 3, 3 ) +rect_clip_content = true +size_flags_vertical = 1 custom_colors/font_color = Color( 0, 0, 0, 1 ) -text = "!" +text = "0" diff --git a/game/src/Taquin.gd b/game/src/Taquin.gd index 031a2ed..bd862b4 100644 --- a/game/src/Taquin.gd +++ b/game/src/Taquin.gd @@ -19,8 +19,8 @@ var pieces: Array = [] var missing_piece: Vector2 var rng = RandomNumberGenerator.new() -func _draw() -> void: - draw_rect(Rect2(0, 0, width, height), Color.blue) +#func _draw() -> void: +# draw_rect(Rect2(0, 0, width, height), Color.blue) func position_for_index(index: Vector2, size: int) -> Vector2: var padding_w = (width - (size * columns)) / (columns + 1) @@ -29,6 +29,9 @@ func position_for_index(index: Vector2, size: int) -> Vector2: func _ready() -> void: + $ColorRect.rect_size.x = width + $ColorRect.rect_size.y = height + rng.randomize() var piece_size: int = compute_piece_size() @@ -46,7 +49,7 @@ func _ready() -> void: missing_piece.x = c missing_piece.y = r - add_child(piece) + $ColorRect.add_child(piece) pieces_row.append(piece) pieces.append(pieces_row) diff --git a/game/src/Taquin.tscn b/game/src/Taquin.tscn index 1455c92..75a68f5 100644 --- a/game/src/Taquin.tscn +++ b/game/src/Taquin.tscn @@ -4,3 +4,8 @@ [node name="Taquin" type="Node2D"] script = ExtResource( 1 ) + +[node name="ColorRect" type="ColorRect" parent="."] +margin_right = 512.0 +margin_bottom = 512.0 +color = Color( 0.254902, 0.329412, 0.45098, 1 )