summaryrefslogtreecommitdiff
path: root/Mob.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Mob.gd')
-rw-r--r--Mob.gd32
1 files changed, 15 insertions, 17 deletions
diff --git a/Mob.gd b/Mob.gd
index a83a119..9dfa923 100644
--- a/Mob.gd
+++ b/Mob.gd
@@ -11,9 +11,11 @@ var is_selected = false :
if value:
Mob.selected_unit = self
selected.emit()
+ $Label.visible = true
else:
if Mob.selected_unit == self:
Mob.selected_unit = null
+ $Label.visible = false
is_selected = value
queue_redraw()
@@ -58,6 +60,8 @@ func _ready():
%HPBar.init(hp)
set_hp(hp)
+
+ $SelectionArea/CollisionShape2D.shape.size = $Sprite2D.texture.get_size() * $Sprite2D.scale
func _physics_process(delta):
@@ -87,7 +91,7 @@ func _draw():
if is_selected:
draw_circle(
Vector2.ZERO,
- 8,
+ Game.map.tile_set.tile_size.x * 0.75,
Color(1, 1, 1, 0.75),
false,
1.0
@@ -96,7 +100,7 @@ func _draw():
elif is_hovered:
draw_circle(
Vector2.ZERO,
- 8,
+ Game.map.tile_set.tile_size.x * 0.75,
Color(1, 1, 1, 0.5),
false,
1.0
@@ -131,10 +135,7 @@ func set_hp(value):
hp = value
%HPBar.set_value(value)
- if is_selected:
- $Label.text = str(hp)
- else:
- $Label.text = ""
+ $Label.text = str(hp)
if hp <= 0:
queue_free()
@@ -151,12 +152,12 @@ func reset_path():
# reached end of partial path
if current_path.size() == 1 and current_path[0] == global_position:
roaming_mode = true
- current_path = PackedVector2Array([target.global_position])
+ current_path = PackedVector2Array([target.path_position + Vector2(16,16)])
# iterating between one or more closest paths
elif recent_closest_paths.count(current_path) >= 2:
roaming_mode = true
- current_path = PackedVector2Array([target.global_position])
+ current_path = PackedVector2Array([target.path_position + Vector2(16,16)])
recent_closest_paths = []
else:
recent_closest_paths = []
@@ -165,29 +166,26 @@ func reset_path():
current_path_idx = 0
func get_grid_path(partial = false):
- #return Game.path_grid.get_point_path(
- #Game.map.local_to_map(global_position) * 2,
- #Game.map.local_to_map(target.global_position) * 2,
- #partial
- #)
return Game.path_grid.get_point_path(
Game.map.local_to_map(global_position),
- Game.map.local_to_map(target.global_position),
+ Game.map.local_to_map(target.path_position),
partial
)
-func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
+func _on_selection_area_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if Game.mode == Game.Mode.DEFAULT:
if event.is_action_pressed("select"):
+ if selected_unit:
+ selected_unit.is_selected = false
is_selected = true
$Label.text = str(hp)
-func _on_mouse_entered() -> void:
+func _on_selection_area_mouse_entered() -> void:
is_hovered = true
-func _on_mouse_exited() -> void:
+func _on_selection_area_mouse_exited() -> void:
is_hovered = false