diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-05 11:34:49 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-05 11:34:49 +0100 |
commit | c8f674ac6fa0914d9e448d2929f2385cdad80d60 (patch) | |
tree | a913454c42bb520aa644f4e2dcf0d42ba11c83de /Units/Unit.gd | |
parent | 84365b6f901a9c0251a9f724a8d9f81a3787e97d (diff) |
next commit
Diffstat (limited to 'Units/Unit.gd')
-rw-r--r-- | Units/Unit.gd | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/Units/Unit.gd b/Units/Unit.gd index ea64c26..f5bb6a6 100644 --- a/Units/Unit.gd +++ b/Units/Unit.gd @@ -63,7 +63,11 @@ var roaming_mode = false @onready var line: Line2D = $UnitPathLine.duplicate() -@onready var sprite: Sprite2D = $Sprite2D +var sprite: AnimatedSprite2D: + get(): + if not sprite: + return get_node("AnimatedSprite2D") + return sprite func _init(): @@ -72,6 +76,7 @@ func _init(): func _ready(): base_speed *= scale.x + speed = base_speed if not target: if target_path: @@ -102,9 +107,6 @@ func _ready(): func _physics_process(delta): if not multiplayer.is_server(): - #Network.update_unit.rpc(get_path(), { - #"hp": hp, - #}) return previous_position = global_position @@ -132,13 +134,7 @@ func _physics_process(delta): else: stuck_position_accumulator = 0 - #Network.update_unit.rpc(get_path(), { - #"position": global_position, - #"hp": hp, - #"sprite": {"self_modulate": $Sprite2D.self_modulate}, - #"current_path_idx": current_path_idx, - #"current_path": current_path, - #}) + #Client.update_unit(get_path(), to_network_data()) func _draw(): @@ -192,6 +188,23 @@ func walk_along_path(path: PackedVector2Array, index: int, delta: float): # todo: changing velocity here doesn't work nicely # todo: because the velocity expects ??to each the point??, so it stutters + if velocity.x > 0 and velocity.y == 0: + $AnimatedSprite2D.play("right") + elif velocity.x < 0 and velocity.y == 0: + $AnimatedSprite2D.play("left") + elif velocity.x == 0 and velocity.y > 0: + $AnimatedSprite2D.play("down") + elif velocity.x == 0 and velocity.y < 0: + $AnimatedSprite2D.play("up") + elif velocity.x > 0 and velocity.y > 0: + $AnimatedSprite2D.play("down_right") + elif velocity.x > 0 and velocity.y < 0: + $AnimatedSprite2D.play("up_right") + elif velocity.x < 0 and velocity.y > 0: + $AnimatedSprite2D.play("down_left") + elif velocity.x < 0 and velocity.y < 0: + $AnimatedSprite2D.play("up_left") + move_and_slide() @@ -294,28 +307,59 @@ 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 + + var base_speed: float var speed: float + var texture_path: String + var sprite_frames_path: String + var sprite_modulate: Color + var sprite_self_modulate: Color + var sprite_animation: StringName + var sprite_frame: int 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 - data.speed = speed - data.texture_path = get_node("Sprite2D").texture.resource_path + + #data.hp = hp + + #data.base_speed = base_speed + #data.speed = speed + + #data.texture_path = sprite.texture.resource_path + data.sprite_frames_path = sprite.sprite_frames.resource_path + #data.sprite_modulate = sprite.modulate + #data.sprite_self_modulate = sprite.self_modulate + #data.sprite_animation = sprite.animation + #data.sprite_frame = sprite.frame return data -#func update_with_network_data(data: NetworkData): - # TODO +func update_with_network_data(_data: NetworkData): + pass + #position = data.position + + #hp = data.hp + + #speed = data.speed + + #sprite.self_modulate = data.sprite_self_modulate + #data.sprite_animation = sprite.animation + #data.sprite_frame = sprite.frame static func from_network_data(data: NetworkData) -> Unit: @@ -323,11 +367,19 @@ static func from_network_data(data: NetworkData) -> Unit: 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_path = data.target_path - unit.hp = data.hp - unit.speed = data.speed - unit.get_node("Sprite2D").texture = load(data.texture_path) + + #unit.hp = data.hp + + #unit.base_speed = data.base_speed + #unit.speed = data.speed + + #unit.sprite.texture = load(data.texture_path) + unit.sprite.sprite_frames = load(data.sprite_frames_path) + #unit.sprite.modulate = data.sprite_modulate return unit |