diff --git a/Assets/clacon.ttf b/Assets/clacon.ttf new file mode 100644 index 0000000..c7b98fc Binary files /dev/null and b/Assets/clacon.ttf differ diff --git a/Main.gd b/Main.gd new file mode 100644 index 0000000..7185423 --- /dev/null +++ b/Main.gd @@ -0,0 +1,4 @@ +extends Node2D + +func _ready(): + Debug.on = true diff --git a/Main.tscn b/Main.tscn index ad73ba9..4f92cc5 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,14 +1,18 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://Prefabs/StdBoard.tscn" type="PackedScene" id=1] -[ext_resource path="res://Prefabs/StdExtBoard.tscn" type="PackedScene" id=2] +[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="Node2D" type="Node2D"] +[node name="Main" type="Node2D"] +script = ExtResource( 2 ) [node name="StdBoard" parent="." instance=ExtResource( 1 )] -[node name="StdExtBoard" parent="." instance=ExtResource( 2 )] - [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/Scripts/Board.gd b/Scripts/Board.gd index 01c88ee..6147b99 100644 --- a/Scripts/Board.gd +++ b/Scripts/Board.gd @@ -29,3 +29,4 @@ func _ready(): hex.translate(Y_OFFSET * index.y) add_child(hex) hex.type = tiles.pop_front() + hex.index = index diff --git a/Scripts/Debug.gd b/Scripts/Debug.gd new file mode 100644 index 0000000..0a99aad --- /dev/null +++ b/Scripts/Debug.gd @@ -0,0 +1,10 @@ +extends Node + +var on = false + +var font + +func _ready(): + font = DynamicFont.new() + font.size = 32 + font.font_data = load("res://Assets/clacon.ttf") diff --git a/Scripts/GameCamera.gd b/Scripts/GameCamera.gd new file mode 100644 index 0000000..db84376 --- /dev/null +++ b/Scripts/GameCamera.gd @@ -0,0 +1,21 @@ +extends Camera2D + +const ZOOM_SPEED = 0.2 + +var pan = false + +func _process(_delta): + if Input.is_action_just_released("ui_zoom_in"): + zoom -= Vector2.ONE * ZOOM_SPEED + elif Input.is_action_just_released("ui_zoom_out"): + zoom += Vector2.ONE * ZOOM_SPEED + + if Input.is_action_pressed("ui_pan"): + pan = true + else: + pan = false + +func _input(event): + if event is InputEventMouseMotion: + if pan: + translate(-event.relative * zoom) diff --git a/Scripts/Hex.gd b/Scripts/Hex.gd index 264721a..275c102 100644 --- a/Scripts/Hex.gd +++ b/Scripts/Hex.gd @@ -18,12 +18,21 @@ const TEXTURE_MAP = { } 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) + +func _process(_delta): + if Debug.on: + $Lbl.text = "(%+d, %+d)" % [index.x, index.y] func set_type(newtype): $Img.texture = TEXTURE_MAP[newtype] diff --git a/project.godot b/project.godot index 1161796..40b02ad 100644 --- a/project.godot +++ b/project.godot @@ -30,10 +30,32 @@ config/name="Hexland" run/main_scene="res://Main.tscn" config/icon="res://icon.png" +[autoload] + +Debug="*res://Scripts/Debug.gd" + [gui] common/drop_mouse_on_gui_input_disabled=true +[input] + +ui_zoom_in={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"pressed":false,"doubleclick":false,"script":null) + ] +} +ui_zoom_out={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null) + ] +} +ui_pan={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":3,"pressed":false,"doubleclick":false,"script":null) + ] +} + [physics] common/enable_pause_aware_picking=true