summaryrefslogtreecommitdiff
path: root/Units
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-12 23:09:56 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-12 23:09:56 +0200
commit0697f674ec33f8381ba68cf064732ee40e6e584f (patch)
tree89334f288356390d193fa327bb3895fa366985b5 /Units
parent647e2e1812c00e29337a61560644f7aa91d0eb0f (diff)
next commit
Diffstat (limited to 'Units')
-rw-r--r--Units/Unit.gd27
1 files changed, 17 insertions, 10 deletions
diff --git a/Units/Unit.gd b/Units/Unit.gd
index 3ce9384..551e13f 100644
--- a/Units/Unit.gd
+++ b/Units/Unit.gd
@@ -2,6 +2,7 @@ class_name Unit
extends CharacterBody2D
+signal reached_goal
signal selected
static var selected_unit: Unit
@@ -31,6 +32,7 @@ var is_hovered = false :
is_hovered = value
queue_redraw()
+var target_path: NodePath
var target: Node2D:
set(value):
target = value
@@ -66,13 +68,14 @@ var roaming_mode = false
func _ready():
if not target:
- target = Client.stage.get_node("%Goal").path_position
+ if target_path:
+ target = get_node(target_path)
line.name = "Line@" + name
- Client.stage.units.add_child(line)
+ get_parent().add_child(line)
reset_path()
- Client.stage.path_grid_changed.connect(func():
+ Client.current_stage.path_grid_changed.connect(func():
# TODO: get current position from owner_id rpc
var has_intersection = Client.array_intersect(current_path, Stage.last_solid_set_points)
@@ -136,7 +139,7 @@ func _draw():
if is_selected:
draw_circle(
Vector2.ZERO,
- Client.stage.map.tile_set.tile_size.x * 0.75,
+ Client.current_stage.map.tile_set.tile_size.x * 0.75,
Color(1, 1, 1, 0.75),
false,
1.0
@@ -145,7 +148,7 @@ func _draw():
elif is_hovered:
draw_circle(
Vector2.ZERO,
- Client.stage.map.tile_set.tile_size.x * 0.75,
+ Client.current_stage.map.tile_set.tile_size.x * 0.75,
Color(1, 1, 1, 0.5),
false,
1.0
@@ -160,7 +163,7 @@ func _on_navigation_base_area_entered(area: Area2D):
return
if area.is_in_group("goal"):
- Client.player.score += 1
+ reached_goal.emit()
queue_free()
if area.is_in_group("path"):
var path_node: PathNode = area.get_parent()
@@ -248,9 +251,9 @@ func reset_path():
func get_grid_path(partial = false):
- return Client.stage.path_grid.get_point_path(
- Client.stage.map.local_to_map(global_position),
- Client.stage.map.local_to_map(target.path_position),
+ return Client.current_stage.path_grid.get_point_path(
+ Client.current_stage.map.local_to_map(global_position),
+ Client.current_stage.map.local_to_map(target.path_position),
partial
)
@@ -284,6 +287,7 @@ func _on_tree_exiting() -> void:
class NetworkData extends Resource:
var name: String
+ var owner_id: int
var position: Vector2
var target_path: String
var hp: int
@@ -294,6 +298,7 @@ func to_network_data() -> NetworkData:
var data = NetworkData.new()
data.name = name
+ data.owner_id = owner_id
data.position = global_position
data.target_path = target.get_path()
data.hp = hp
@@ -311,8 +316,10 @@ static func from_network_data(data: NetworkData) -> Unit:
var unit: Unit = preload("res://Units/Unit.tscn").instantiate()
unit.name = data.name
+ unit.owner_id = data.owner_id
unit.global_position = data.position
- unit.target = unit.get_tree().current_scene.get_node(data.target_path)
+ #unit.target = unit.get_tree().current_scene.get_node(data.target_path)
+ unit.target_path = data.target_path
unit.hp = data.hp
unit.speed = data.speed
unit.get_node("Sprite2D").texture = load(data.texture_path)