diff --git a/Main.gd b/Main.gd deleted file mode 100644 index 7185423..0000000 --- a/Main.gd +++ /dev/null @@ -1,4 +0,0 @@ -extends Node2D - -func _ready(): - Debug.on = true diff --git a/Main.tscn b/Main.tscn deleted file mode 100644 index 4f92cc5..0000000 --- a/Main.tscn +++ /dev/null @@ -1,18 +0,0 @@ -[gd_scene load_steps=5 format=2] - -[ext_resource path="res://Prefabs/StdBoard.tscn" type="PackedScene" id=1] -[ext_resource path="res://Main.gd" type="Script" id=2] -[ext_resource path="res://Scripts/GameCamera.gd" type="Script" id=3] -[ext_resource path="res://Prefabs/StdExtBoard.tscn" type="PackedScene" id=4] - -[node name="Main" type="Node2D"] -script = ExtResource( 2 ) - -[node name="StdBoard" parent="." instance=ExtResource( 1 )] - -[node name="Camera2D" type="Camera2D" parent="."] -current = true -zoom = Vector2( 2, 2 ) -script = ExtResource( 3 ) - -[node name="StdExtBoard" parent="." instance=ExtResource( 4 )] diff --git a/Prefabs/Hex.tscn b/Prefabs/Hex.tscn new file mode 100644 index 0000000..82e9e5a --- /dev/null +++ b/Prefabs/Hex.tscn @@ -0,0 +1,41 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Scripts/Hex.gd" type="Script" id=1] +[ext_resource path="res://Assets/desert-hex.png" type="Texture" id=2] +[ext_resource path="res://Assets/clacon.ttf" type="DynamicFontData" id=3] + +[sub_resource type="DynamicFont" id=1] +size = 32 +font_data = ExtResource( 3 ) + +[node name="Hex" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Image" type="Sprite" parent="."] +texture = ExtResource( 2 ) + +[node name="DebugLabel" type="Label" parent="."] +grow_horizontal = 2 +grow_vertical = 2 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) + +[node name="Corners" type="Node2D" parent="."] + +[node name="0" type="Node2D" parent="Corners"] +position = Vector2( 0, -128 ) + +[node name="1" type="Node2D" parent="Corners"] +position = Vector2( 109, -63 ) + +[node name="2" type="Node2D" parent="Corners"] +position = Vector2( 111, 64 ) + +[node name="3" type="Node2D" parent="Corners"] +position = Vector2( 0, 127 ) + +[node name="4" type="Node2D" parent="Corners"] +position = Vector2( -111, 63 ) + +[node name="5" type="Node2D" parent="Corners"] +position = Vector2( -110, -64 ) diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn new file mode 100644 index 0000000..b91db34 --- /dev/null +++ b/Scenes/Main.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Scripts/GameCamera.gd" type="Script" id=1] +[ext_resource path="res://Prefabs/StdBoard.tscn" type="PackedScene" id=2] + +[node name="Main" type="Node2D"] + +[node name="StdBoard" parent="." instance=ExtResource( 2 )] + +[node name="Camera2D" type="Camera2D" parent="."] +current = true +zoom = Vector2( 2, 2 ) +script = ExtResource( 1 ) diff --git a/Scripts/Board.gd b/Scripts/Board.gd index 6147b99..1d14805 100644 --- a/Scripts/Board.gd +++ b/Scripts/Board.gd @@ -2,6 +2,8 @@ extends Node2D class_name Board +const hex_prefab = preload("res://Prefabs/Hex.tscn") + const Y_OFFSET = Vector2(Hex.HALFWIDTH, Hex.HEIGHT) const X_OFFSET = Vector2(Hex.WIDTH, 0) @@ -23,7 +25,7 @@ func _ready(): randomize() tiles.shuffle() for index in indices: - var hex = Hex.new() + var hex = hex_prefab.instance() hex.name = "Hex#%d#%d" % [index.x, index.y] hex.translate(X_OFFSET * index.x) hex.translate(Y_OFFSET * index.y) diff --git a/Scripts/Hex.gd b/Scripts/Hex.gd index 275c102..39c8362 100644 --- a/Scripts/Hex.gd +++ b/Scripts/Hex.gd @@ -21,19 +21,12 @@ var type = "desert" setget set_type var index = Vector2.ZERO func _ready(): - var sprite = Sprite.new() - sprite.texture = TEXTURE_MAP[type] - sprite.name = "Img" - add_child(sprite) - var label = Label.new() - label.name = "Lbl" - label.add_font_override("font", Debug.font) - add_child(label) + $Image.texture = TEXTURE_MAP[type] func _process(_delta): if Debug.on: - $Lbl.text = "(%+d, %+d)" % [index.x, index.y] + $DebugLabel.text = "(%+d, %+d)" % [index.x, index.y] func set_type(newtype): - $Img.texture = TEXTURE_MAP[newtype] + $Image.texture = TEXTURE_MAP[newtype] type = newtype diff --git a/project.godot b/project.godot index 40b02ad..e4d148c 100644 --- a/project.godot +++ b/project.godot @@ -27,7 +27,7 @@ _global_script_class_icons={ [application] config/name="Hexland" -run/main_scene="res://Main.tscn" +run/main_scene="res://Scenes/Main.tscn" config/icon="res://icon.png" [autoload]