Made more enemies, easier to kill, more slashy. You get passive health regen, health orbs. Little key bindings tooltip.

This commit is contained in:
2026-06-30 22:57:11 +01:00
parent 7fa2efabaf
commit 97ebbb1618
17 changed files with 404 additions and 6 deletions
+29
View File
@@ -11,15 +11,29 @@ signal respawned()
@export var max_health: float = 100.0
@export var can_respawn: bool = true
@export var respawn_delay: float = 3.0
@export var health_regen: float = 0.0 ## HP restored per second by passive regen (server-applied). 0 = disabled.
@export var regen_delay: float = 4.0 ## Seconds to wait after taking damage before regen resumes.
const REGEN_TICK := 0.5 # Seconds between regen applications
var current_health: float = 100.0
var is_dead: bool = false
var _respawn_point: Vector3 = Vector3.ZERO
var _last_damage_time: float = -1000.0
func _ready():
current_health = max_health
_respawn_point = global_position
# Server drives a passive regen tick for any unit with health_regen > 0
if multiplayer.is_server() and health_regen > 0.0:
var regen_timer := Timer.new()
regen_timer.name = "RegenTimer"
regen_timer.wait_time = REGEN_TICK
regen_timer.autostart = true
add_child(regen_timer)
regen_timer.timeout.connect(_on_regen_tick)
func _enter_tree():
set_multiplayer_authority(str(name).to_int())
@@ -34,6 +48,9 @@ func take_damage(amount: float, attacker_id: int = -1, knockback: float = 0.0, a
if is_dead:
return
# Record when we were last hit so passive regen can pause briefly
_last_damage_time = Time.get_ticks_msec() / 1000.0
# Apply blocking reduction if applicable (duck typing - check if method exists)
var final_damage = amount
var final_knockback = knockback
@@ -68,6 +85,18 @@ func take_damage(amount: float, attacker_id: int = -1, knockback: float = 0.0, a
if current_health <= 0:
_die(attacker_id)
## Server-side passive regeneration tick (driven by RegenTimer)
func _on_regen_tick():
if not multiplayer.is_server():
return
if is_dead or health_regen <= 0.0 or current_health >= max_health:
return
# Hold off regen for a short window after taking damage
var now := Time.get_ticks_msec() / 1000.0
if now - _last_damage_time < regen_delay:
return
heal(health_regen * REGEN_TICK)
## Heal the unit
@rpc("any_peer", "reliable")
func heal(amount: float):