grid with randomly assigned token types out of 4 choices
This commit is contained in:
@@ -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
|
||||
|
||||
8
grid.gd
8
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)
|
||||
|
||||
20
token.gd
Normal file
20
token.gd
Normal file
@@ -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
|
||||
1
token.gd.uid
Normal file
1
token.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cy18iue2caocn
|
||||
15
token.tscn
15
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)
|
||||
|
||||
Reference in New Issue
Block a user