diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-09-28 15:27:43 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-09-28 15:27:43 +0200 |
commit | b96e384d8299473b14edcbf885fa914a9308d18f (patch) | |
tree | 0bde9428f42b309ea167a41473252bda8035e21a /Units | |
parent | 4597189f157834c80f56b12b701fd2b2a15c2798 (diff) |
next commit
Diffstat (limited to 'Units')
-rw-r--r-- | Units/Unit.gd | 55 | ||||
-rw-r--r-- | Units/Unit.tscn | 5 |
2 files changed, 45 insertions, 15 deletions
diff --git a/Units/Unit.gd b/Units/Unit.gd index 6c3b254..8373a59 100644 --- a/Units/Unit.gd +++ b/Units/Unit.gd @@ -23,6 +23,11 @@ var is_selected = false : var is_hovered = false : set(value): + if value: + $Label.visible = true + else: + if not is_selected: + $Label.visible = false is_hovered = value queue_redraw() @@ -39,9 +44,6 @@ var current_path_idx = 0 : if line: line.points = PackedVector2Array(current_path.slice(value)) -var previous_path: PackedVector2Array -var previous_path_idx = 0 - var previous_position: Vector2 var recent_closest_paths: Array[PackedVector2Array] @@ -52,15 +54,15 @@ var roaming_mode = false # rpc owner id var owner_id = 1 -# unique shared id on the network on all clients -var network_id - @export var base_speed: float = 100 @export var speed: float = base_speed -@export var hp = 50 +@export var hp = 50 : + set = set_hp @onready var line: Line2D = $UnitPathLine.duplicate() +@onready var sprite = $Sprite2D + func _ready(): if not target: @@ -89,6 +91,12 @@ func _ready(): func _physics_process(delta): + if get_multiplayer_authority() != multiplayer.get_unique_id(): + Network.update_unit.rpc(get_path(), { + "hp": hp, + }) + return + previous_position = global_position if not current_path.is_empty(): @@ -113,6 +121,12 @@ func _physics_process(delta): reset_path() else: stuck_position_accumulator = 0 + + Network.update_unit.rpc(get_path(), { + "position": global_position, + "hp": hp, + "sprite": {"self_modulate": $Sprite2D.self_modulate} + }) func _draw(): @@ -139,8 +153,12 @@ func _draw(): func _on_navigation_base_area_entered(area: Area2D): + if get_multiplayer_authority() != multiplayer.get_unique_id(): + return + if area.is_in_group("goal"): Client.player.score += 1 + Client.update_player() queue_free() if area.is_in_group("path"): var path_node = area.get_parent() @@ -150,7 +168,7 @@ func _on_navigation_base_area_entered(area: Area2D): func walk_along_path(path: PackedVector2Array, index: int, delta: float): immediate_target = path[index] - var displacement := (path[index]) - global_position + var displacement := immediate_target - global_position var direction := displacement.normalized() var distance := displacement.length() @@ -161,7 +179,7 @@ func walk_along_path(path: PackedVector2Array, index: int, delta: float): if effect.has_method("apply_physics"): effect.apply_physics(delta) # todo: changing velocity here doesn't work nicely - # todo: because the velocity expects to each the point, so it stutters + # todo: because the velocity expects ??to each the point??, so it stutters move_and_slide() @@ -170,9 +188,11 @@ func set_hp(value): # TODO: rpc on damage hp = value - %HPBar.set_value(value) - $Label.text = str(hp) + if get_node("%HPBar"): + %HPBar.set_value(value) + if get_node("Label"): + $Label.text = str(hp) if hp <= 0: queue_free() @@ -192,6 +212,9 @@ func reset_path(): current_path = get_grid_path() if current_path.is_empty(): + # TODO: nimm letzte route davor die noch ging, falls verfügbar + # TODO: schneide ab bis eins vor neue tower position. (=partial path) + # TODO: laufe bis dahin und checke dann end of partial path current_path = get_grid_path(true) recent_closest_paths.append(current_path) @@ -224,6 +247,10 @@ func get_grid_path(partial = false): func _on_selection_area_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: + # disable remote select for now + if owner_id != multiplayer.get_unique_id(): + return + if Client.state is StateDefault: if event.is_action_pressed("select"): if selected_unit: @@ -243,14 +270,20 @@ func _on_selection_area_mouse_exited() -> void: func _on_tree_exiting() -> void: is_selected = false line.queue_free() + + #if get_multiplayer_authority() == multiplayer.get_unique_id(): + Network.remove_unit.rpc(get_path()) func get_rpc_properties(): return { + "name": null, "global_position": null, "target": "res://Stages/Paths/PathNode.tscn", "hp": null, "speed": null, "current_path": null, "current_path_idx": null, + "sprite": "node://Sprite2D", + "owner_id": null, } diff --git a/Units/Unit.tscn b/Units/Unit.tscn index 312389e..879df08 100644 --- a/Units/Unit.tscn +++ b/Units/Unit.tscn @@ -53,7 +53,7 @@ text = "1000" horizontal_alignment = 1 [node name="SelectionArea" type="Area2D" parent="."] -collision_layer = 16 +collision_layer = 32 collision_mask = 0 [node name="CollisionShape2D" type="CollisionShape2D" parent="SelectionArea"] @@ -65,9 +65,6 @@ width = 1.0 default_color = Color(1, 1, 1, 0.392157) target_circle_radius = 4.0 -[connection signal="input_event" from="." to="." method="_on_input_event"] -[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] [connection signal="tree_exiting" from="." to="." method="_on_tree_exiting"] [connection signal="area_entered" from="NavigationBase" to="." method="_on_navigation_base_area_entered"] [connection signal="input_event" from="SelectionArea" to="." method="_on_selection_area_input_event"] |