From 9526275e3d3cf7f38a3795f7ada0a9339d7f230a Mon Sep 17 00:00:00 2001 From: Jack Case Date: Mon, 18 Aug 2025 20:44:32 -0400 Subject: [PATCH] grid with randomly assigned token types out of 4 choices --- game_window.tscn | 5 ++++- grid.gd | 8 +++++--- token.gd | 20 ++++++++++++++++++++ token.gd.uid | 1 + token.tscn | 15 ++++++++++++++- 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 token.gd create mode 100644 token.gd.uid diff --git a/game_window.tscn b/game_window.tscn index 10ea5b9..69d9152 100644 --- a/game_window.tscn +++ b/game_window.tscn @@ -5,5 +5,8 @@ [node name="GameWindow" type="Node2D"] [node name="Grid" type="Node2D" parent="."] -position = Vector2(553, 259) +position = Vector2(393, 224) script = ExtResource("1_mn5vm") +rows = 4 +cols = 4 +offset = 60.0 diff --git a/grid.gd b/grid.gd index 50de5a8..f0edeb4 100644 --- a/grid.gd +++ b/grid.gd @@ -1,7 +1,9 @@ extends Node2D -var rows: int = 5 -var cols: int = 5 +@export var rows: int = 5 +@export var cols: int = 5 + +@export var offset: float = 55.0 var grid: Array @@ -13,5 +15,5 @@ func _ready(): for column in cols: var token_node = token.instantiate() add_child(token_node) - token_node.position = Vector2(10*row, 10*column) + token_node.position = Vector2(offset*row, offset*column) grid[row].append(token_node) diff --git a/token.gd b/token.gd new file mode 100644 index 0000000..a5a8c68 --- /dev/null +++ b/token.gd @@ -0,0 +1,20 @@ +extends Node2D + +enum token_type {TYPE_1, TYPE_2, TYPE_3, TYPE_4} + +var type: token_type = token_type.TYPE_1 + +var color_polygon + +func _ready(): + color_polygon = $Color + type = randi_range(0, 3) + match type: + token_type.TYPE_1: + color_polygon.color = Color.RED + token_type.TYPE_2: + color_polygon.color = Color.GREEN + token_type.TYPE_3: + color_polygon.color = Color.BLUE + token_type.TYPE_4: + color_polygon.color = Color.YELLOW diff --git a/token.gd.uid b/token.gd.uid new file mode 100644 index 0000000..65c6bfe --- /dev/null +++ b/token.gd.uid @@ -0,0 +1 @@ +uid://cy18iue2caocn diff --git a/token.tscn b/token.tscn index 6183969..c6d25d0 100644 --- a/token.tscn +++ b/token.tscn @@ -1,8 +1,21 @@ -[gd_scene load_steps=2 format=3 uid="uid://b50otusq306jl"] +[gd_scene load_steps=4 format=3 uid="uid://b50otusq306jl"] +[ext_resource type="Script" uid="uid://cy18iue2caocn" path="res://token.gd" id="1_0ucay"] [ext_resource type="Texture2D" uid="uid://cqtw7t2uag6f8" path="res://icon.svg" id="1_bd72f"] +[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_bd72f"] +blend_mode = 1 + [node name="Token" type="Node2D"] +script = ExtResource("1_0ucay") [node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.4, 0.4) texture = ExtResource("1_bd72f") +centered = false + +[node name="Color" type="Polygon2D" parent="."] +material = SubResource("CanvasItemMaterial_bd72f") +position = Vector2(6, 6) +color = Color(3.94672e-06, 0.565612, 0.802131, 1) +polygon = PackedVector2Array(0, 0, 40, 0, 40, 40, 0, 40)