diff options
Diffstat (limited to 'Units')
-rw-r--r-- | Units/Unit.gd | 70 | ||||
-rw-r--r-- | Units/Unit.tscn | 11 |
2 files changed, 23 insertions, 58 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 diff --git a/Units/Unit.tscn b/Units/Unit.tscn index 39cfbe0..a7a86ae 100644 --- a/Units/Unit.tscn +++ b/Units/Unit.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=10 format=3 uid="uid://cslaufgh6ber3"] [ext_resource type="Script" path="res://Units/Unit.gd" id="1_bbcew"] -[ext_resource type="Texture2D" uid="uid://dsy7k2v5fhh6v" path="res://Units/Assets/angesnow-front.png" id="2_rxqq1"] +[ext_resource type="Resource" uid="uid://reijb7spqqwc" path="res://Stages/Wintermaul/Units/pekora.tres" id="2_pfs06"] [ext_resource type="SpriteFrames" uid="uid://c6o6hpltnsds0" path="res://Units/Assets/Pekora/sprite_frames.tres" id="3_84r8c"] [ext_resource type="PackedScene" uid="uid://bjcrf4o4a80iv" path="res://UI/HPBar.tscn" id="3_e777u"] [ext_resource type="PackedScene" uid="uid://cifs0kcy5r0x2" path="res://Units/UnitPathLine.tscn" id="4_r0qfv"] @@ -39,14 +39,7 @@ properties/5/replication_mode = 2 collision_mask = 4 input_pickable = true script = ExtResource("1_bbcew") - -[node name="Sprite2D" type="Sprite2D" parent="."] -visible = false -texture_filter = 1 -position = Vector2(0, -4) -scale = Vector2(0.5, 0.5) -texture = ExtResource("2_rxqq1") -region_rect = Rect2(480, 880, 96, 64) +unit_resource = ExtResource("2_pfs06") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] texture_filter = 1 |