summaryrefslogtreecommitdiff
path: root/unit
diff options
context:
space:
mode:
Diffstat (limited to 'unit')
-rw-r--r--unit/area_2d.gd5
-rw-r--r--unit/area_2d.gd.uid1
-rw-r--r--unit/unit.gd27
-rw-r--r--unit/unit.tscn22
-rw-r--r--unit/unit_data.gd7
-rw-r--r--unit/unit_data.gd.uid1
6 files changed, 46 insertions, 17 deletions
diff --git a/unit/area_2d.gd b/unit/area_2d.gd
deleted file mode 100644
index 15b6a72..0000000
--- a/unit/area_2d.gd
+++ /dev/null
@@ -1,5 +0,0 @@
-extends Area2D
-
-
-func get_entity() -> Unit:
- return get_parent()
diff --git a/unit/area_2d.gd.uid b/unit/area_2d.gd.uid
deleted file mode 100644
index 7d11abc..0000000
--- a/unit/area_2d.gd.uid
+++ /dev/null
@@ -1 +0,0 @@
-uid://u5kpy6jybqon
diff --git a/unit/unit.gd b/unit/unit.gd
index e0f9025..066aee6 100644
--- a/unit/unit.gd
+++ b/unit/unit.gd
@@ -2,17 +2,26 @@ class_name Unit
extends Node2D
-@export var max_hp := 0
-@export var current_hp := 0
+@export var unit_data: UnitData
@export var current_team: String
+@export var current_player: Player
-
-# Called when the node enters the scene tree for the first time.
-func _ready() -> void:
- pass # Replace with function body.
+var current_hp := 0:
+ set(value):
+ current_hp = value
+ $Label.text = str(value)
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(_delta: float) -> void:
- pass
+func _ready() -> void:
+ current_hp = unit_data.health
+
+ $Label.visible = false
+
+ var grid_selector := get_tree().get_first_node_in_group("grid_selector") as GridSelector
+ grid_selector.hover_enter.connect(func(node: Node2D):
+ $Label.visible = node == self
+ )
+ grid_selector.hover_exit.connect(func():
+ $Label.visible = false
+ )
diff --git a/unit/unit.tscn b/unit/unit.tscn
index 39de6e6..b69e717 100644
--- a/unit/unit.tscn
+++ b/unit/unit.tscn
@@ -1,7 +1,16 @@
-[gd_scene load_steps=4 format=3 uid="uid://dglv8ajgj4i4c"]
+[gd_scene load_steps=7 format=3 uid="uid://dglv8ajgj4i4c"]
[ext_resource type="Texture2D" uid="uid://blanietpri1be" path="res://icon.svg" id="1_0d47j"]
[ext_resource type="Script" uid="uid://rbk7n3puwr3q" path="res://unit/unit.gd" id="1_5uy8y"]
+[ext_resource type="Script" uid="uid://bs4wgt1curlf7" path="res://unit/unit_data.gd" id="2_japly"]
+[ext_resource type="Script" uid="uid://drs01qvt6fnrx" path="res://area_2d.gd" id="3_hs7ws"]
+
+[sub_resource type="Resource" id="Resource_japly"]
+script = ExtResource("2_japly")
+health = 2
+attack = 2
+defense = 1
+metadata/_custom_type_script = "uid://bs4wgt1curlf7"
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4xd6x"]
size = Vector2(8, 8)
@@ -9,14 +18,23 @@ size = Vector2(8, 8)
[node name="Unit" type="Node2D"]
z_index = 2
script = ExtResource("1_5uy8y")
+unit_data = SubResource("Resource_japly")
[node name="Icon" type="Sprite2D" parent="."]
scale = Vector2(0.063, 0.063)
texture = ExtResource("1_0d47j")
-[node name="Area2D" type="Area2D" parent="."]
+[node name="Area2D" type="Area2D" parent="." node_paths=PackedStringArray("root_node")]
collision_layer = 2
collision_mask = 0
+script = ExtResource("3_hs7ws")
+root_node = NodePath("..")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_4xd6x")
+
+[node name="Label" type="Label" parent="."]
+offset_left = -5.0
+offset_right = 5.0
+offset_bottom = 23.0
+text = "0"
diff --git a/unit/unit_data.gd b/unit/unit_data.gd
new file mode 100644
index 0000000..e5f59b1
--- /dev/null
+++ b/unit/unit_data.gd
@@ -0,0 +1,7 @@
+class_name UnitData
+extends Resource
+
+
+@export var health: int
+@export var attack: int
+@export var defense: int
diff --git a/unit/unit_data.gd.uid b/unit/unit_data.gd.uid
new file mode 100644
index 0000000..03f7d41
--- /dev/null
+++ b/unit/unit_data.gd.uid
@@ -0,0 +1 @@
+uid://bs4wgt1curlf7