Feat/10 adding multiplayer fundamentals #14
@@ -11,6 +11,7 @@ var max_shield: float = 100.0
|
||||
var shield: float = 100.0
|
||||
|
||||
var is_dead: bool = false
|
||||
var time_since_last_damage: float = 0.0
|
||||
var ragdoll_instance: Node3D = null
|
||||
var pending_impulse: Vector3 = Vector3.ZERO
|
||||
var recent_attackers: Dictionary = {}
|
||||
@@ -39,6 +40,16 @@ func _ready() -> void:
|
||||
|
||||
_update_label()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if is_dead:
|
||||
return
|
||||
time_since_last_damage += delta
|
||||
if time_since_last_damage >= 5.0 and shield < max_shield:
|
||||
shield += 20.0 * delta
|
||||
if shield > max_shield:
|
||||
shield = max_shield
|
||||
_update_label()
|
||||
|
||||
func take_damage(amount: float, hit_position: Vector3, source: Node = null, _impulse: Vector3 = Vector3.ZERO) -> void:
|
||||
if is_dead:
|
||||
return
|
||||
@@ -55,6 +66,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, _imp
|
||||
if attacker_id != 0:
|
||||
recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0
|
||||
|
||||
time_since_last_damage = 0.0
|
||||
|
||||
var dmg_taken = amount
|
||||
if shield > 0:
|
||||
if shield >= amount:
|
||||
|
||||
@@ -11,6 +11,7 @@ var max_shield: float = 100.0
|
||||
var shield: float = 100.0
|
||||
|
||||
var is_dead: bool = false
|
||||
var time_since_last_damage: float = 0.0
|
||||
var recent_attackers: Dictionary = {} # attacker_id: timestamp
|
||||
var ragdoll_instance: Node3D = null
|
||||
var pending_impulse: Vector3 = Vector3.ZERO
|
||||
@@ -51,6 +52,14 @@ func _physics_process(delta: float) -> void:
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
# Shield recharge logic
|
||||
time_since_last_damage += delta
|
||||
if time_since_last_damage >= 5.0 and shield < max_shield:
|
||||
shield += 20.0 * delta
|
||||
if shield > max_shield:
|
||||
shield = max_shield
|
||||
_update_label()
|
||||
|
||||
# Basic gravity
|
||||
if not is_on_floor():
|
||||
velocity.y -= 9.8 * delta
|
||||
@@ -98,6 +107,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, impu
|
||||
if attacker_id != 0:
|
||||
recent_attackers[attacker_id] = Time.get_ticks_msec() / 1000.0
|
||||
|
||||
time_since_last_damage = 0.0
|
||||
|
||||
var dmg_taken = amount
|
||||
if shield > 0:
|
||||
if shield >= amount:
|
||||
@@ -109,6 +120,8 @@ func take_damage(amount: float, hit_position: Vector3, source: Node = null, impu
|
||||
|
||||
if amount > 0:
|
||||
health -= amount
|
||||
if health <= 0:
|
||||
health = 0
|
||||
|
||||
_update_label()
|
||||
|
||||
|
||||
@@ -499,7 +499,6 @@ func rpc_take_damage(amount: float, hit_pos: Vector3, attacker_id: int, weapon_n
|
||||
if multiplayer.is_server():
|
||||
var nm = get_node_or_null("/root/NetworkManager")
|
||||
if nm and multiplayer.has_multiplayer_peer():
|
||||
var victim_id = multiplayer.get_unique_id()
|
||||
var killer_id = attacker_id
|
||||
|
||||
var assist_ids: Array = []
|
||||
@@ -722,6 +721,15 @@ func _process(delta: float) -> void:
|
||||
humanoid.set_weapon(synced_weapon_path)
|
||||
humanoid.set_meta("current_weapon_path", synced_weapon_path)
|
||||
return
|
||||
|
||||
# Update UI
|
||||
if is_instance_valid(health_bar):
|
||||
health_bar.value = health
|
||||
health_label.text = "%d / %d" % [ceil(health), max_health]
|
||||
if is_instance_valid(shield_bar):
|
||||
shield_bar.value = shield
|
||||
shield_label.text = "%d / %d" % [ceil(shield), max_shield]
|
||||
|
||||
if is_dead:
|
||||
# Continuously follow the ragdoll torso
|
||||
if is_instance_valid(ragdoll_instance) and is_instance_valid(camera):
|
||||
@@ -744,14 +752,6 @@ func _process(delta: float) -> void:
|
||||
shield += 20.0 * delta
|
||||
if shield > max_shield:
|
||||
shield = max_shield
|
||||
|
||||
# Update UI
|
||||
if is_instance_valid(health_bar):
|
||||
health_bar.value = health
|
||||
health_label.text = "%d / %d" % [ceil(health), max_health]
|
||||
if is_instance_valid(shield_bar):
|
||||
shield_bar.value = shield
|
||||
shield_label.text = "%d / %d" % [ceil(shield), max_shield]
|
||||
|
||||
func _setup_hud() -> void:
|
||||
var margin = MarginContainer.new()
|
||||
|
||||
Reference in New Issue
Block a user