Hexes will be prefab instances
This commit is contained in:
parent
63690ca3ed
commit
8298765b3f
18
Main.tscn
18
Main.tscn
@ -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 )]
|
|
41
Prefabs/Hex.tscn
Normal file
41
Prefabs/Hex.tscn
Normal file
@ -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 )
|
13
Scenes/Main.tscn
Normal file
13
Scenes/Main.tscn
Normal file
@ -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 )
|
@ -2,6 +2,8 @@ extends Node2D
|
|||||||
|
|
||||||
class_name Board
|
class_name Board
|
||||||
|
|
||||||
|
const hex_prefab = preload("res://Prefabs/Hex.tscn")
|
||||||
|
|
||||||
const Y_OFFSET = Vector2(Hex.HALFWIDTH, Hex.HEIGHT)
|
const Y_OFFSET = Vector2(Hex.HALFWIDTH, Hex.HEIGHT)
|
||||||
const X_OFFSET = Vector2(Hex.WIDTH, 0)
|
const X_OFFSET = Vector2(Hex.WIDTH, 0)
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ func _ready():
|
|||||||
randomize()
|
randomize()
|
||||||
tiles.shuffle()
|
tiles.shuffle()
|
||||||
for index in indices:
|
for index in indices:
|
||||||
var hex = Hex.new()
|
var hex = hex_prefab.instance()
|
||||||
hex.name = "Hex#%d#%d" % [index.x, index.y]
|
hex.name = "Hex#%d#%d" % [index.x, index.y]
|
||||||
hex.translate(X_OFFSET * index.x)
|
hex.translate(X_OFFSET * index.x)
|
||||||
hex.translate(Y_OFFSET * index.y)
|
hex.translate(Y_OFFSET * index.y)
|
||||||
|
@ -21,19 +21,12 @@ var type = "desert" setget set_type
|
|||||||
var index = Vector2.ZERO
|
var index = Vector2.ZERO
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var sprite = Sprite.new()
|
$Image.texture = TEXTURE_MAP[type]
|
||||||
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)
|
|
||||||
|
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
if Debug.on:
|
if Debug.on:
|
||||||
$Lbl.text = "(%+d, %+d)" % [index.x, index.y]
|
$DebugLabel.text = "(%+d, %+d)" % [index.x, index.y]
|
||||||
|
|
||||||
func set_type(newtype):
|
func set_type(newtype):
|
||||||
$Img.texture = TEXTURE_MAP[newtype]
|
$Image.texture = TEXTURE_MAP[newtype]
|
||||||
type = newtype
|
type = newtype
|
||||||
|
@ -27,7 +27,7 @@ _global_script_class_icons={
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Hexland"
|
config/name="Hexland"
|
||||||
run/main_scene="res://Main.tscn"
|
run/main_scene="res://Scenes/Main.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
Loading…
Reference in New Issue
Block a user