diff options
Diffstat (limited to 'Units/Unit.gd')
-rw-r--r-- | Units/Unit.gd | 70 |
1 files changed, 21 insertions, 49 deletions
diff --git a/Units/Unit.gd b/Units/Unit.gd index 11115d3..889eec3 100644 --- a/Units/Unit.gd +++ b/Units/Unit.gd @@ -53,16 +53,14 @@ var stuck_position_accumulator = 0.0 var roaming_mode = false -var additional_data: Dictionary - -var unit_resource: UnitResource - # rpc owner id @export var owner_id = 1 -@export var base_speed: float = 100 -@export var speed: float = base_speed -@export var hp = 50 : +@export var unit_resource: UnitResource + +var base_speed: float = 100 +var speed: float = base_speed +var hp = 50 : set = set_hp @onready var line: Line2D = $UnitPathLine.duplicate() @@ -79,10 +77,10 @@ func _init(): func _ready(): - if unit_resource: - $AnimatedSprite2D.sprite_frames = unit_resource.sprite_frames - base_speed = unit_resource.speed - hp = unit_resource.hp + # setup with data from UnitResource + sprite.sprite_frames = unit_resource.sprite_frames + base_speed = unit_resource.speed + hp = unit_resource.hp base_speed *= scale.x speed = base_speed @@ -111,7 +109,8 @@ func _ready(): %HPBar.init(hp) set_hp(hp) - $SelectionArea/CollisionShape2D.shape.size = $Sprite2D.texture.get_size() * $Sprite2D.scale + var sprite_texture: Texture2D = sprite.sprite_frames.get_frame_texture("down", 0) + $SelectionArea/CollisionShape2D.shape.size = sprite_texture.get_size() func _physics_process(delta): @@ -149,7 +148,7 @@ func _physics_process(delta): func _draw(): if is_selected: draw_circle( - $Sprite2D.position, + sprite.position, Client.current_stage.map.tile_set.tile_size.x * 0.75, Color(1, 1, 1, 0.75), false, @@ -158,7 +157,7 @@ func _draw(): modulate = Color(1.5, 1.5, 1.5) elif is_hovered: draw_circle( - $Sprite2D.position, + sprite.position, Client.current_stage.map.tile_set.tile_size.x * 0.75, Color(1, 1, 1, 0.5), false, @@ -198,28 +197,26 @@ func walk_along_path(path: PackedVector2Array, index: int, delta: float): # todo: because the velocity expects ??to each the point??, so it stutters if velocity.x > 0 and velocity.y == 0: - $AnimatedSprite2D.play("right") + sprite.play("right") elif velocity.x < 0 and velocity.y == 0: - $AnimatedSprite2D.play("left") + sprite.play("left") elif velocity.x == 0 and velocity.y > 0: - $AnimatedSprite2D.play("down") + sprite.play("down") elif velocity.x == 0 and velocity.y < 0: - $AnimatedSprite2D.play("up") + sprite.play("up") elif velocity.x > 0 and velocity.y > 0: - $AnimatedSprite2D.play("down_right") + sprite.play("down_right") elif velocity.x > 0 and velocity.y < 0: - $AnimatedSprite2D.play("up_right") + sprite.play("up_right") elif velocity.x < 0 and velocity.y > 0: - $AnimatedSprite2D.play("down_left") + sprite.play("down_left") elif velocity.x < 0 and velocity.y < 0: - $AnimatedSprite2D.play("up_left") + sprite.play("up_left") move_and_slide() func set_hp(value): - # TODO: rpc on damage - hp = value if get_node("%HPBar"): @@ -326,14 +323,8 @@ class NetworkData extends Resource: 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 - var additional_data: Dictionary var unit_resource: UnitResource func to_network_data() -> NetworkData: @@ -351,14 +342,8 @@ func to_network_data() -> NetworkData: 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 - data.additional_data = additional_data data.unit_resource = unit_resource return data @@ -366,15 +351,6 @@ func to_network_data() -> NetworkData: 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: @@ -385,7 +361,6 @@ static func from_network_data(data: NetworkData) -> Unit: 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 @@ -393,11 +368,8 @@ static func from_network_data(data: NetworkData) -> Unit: 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 - unit.additional_data = data.additional_data unit.unit_resource = data.unit_resource return unit |