Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node
- # =========================================================
- # STATS
- # =========================================================
- @export var max_health = 100
- @export var hitstun_duration = 0.2
- var current_health = 0
- var is_stunned = false
- var stun_timer = 0.0
- var body: CharacterBody2D
- # =========================================================
- # INIT
- # =========================================================
- func _ready():
- print("\n[COMBAT] READY:", get_parent())
- body = get_parent()
- current_health = max_health
- print("[COMBAT] HP:", current_health)
- # =========================================================
- # FRAME LOOP
- # =========================================================
- func _process(delta):
- if is_stunned:
- stun_timer -= delta
- print("[COMBAT] stun_timer =", stun_timer)
- if stun_timer <= 0:
- is_stunned = false
- print("[COMBAT] HITSTUN END")
- # =========================================================
- # DAMAGE
- # =========================================================
- func take_damage(amount, knockback_dir := Vector2.ZERO, knockback_force := 0.0):
- print("\n[COMBAT] DAMAGE RECEIVED:", amount)
- current_health -= amount
- print("[COMBAT] HP:", current_health)
- apply_hitstun()
- if current_health <= 0:
- die()
- # =========================================================
- # HITSTUN
- # =========================================================
- func apply_hitstun():
- is_stunned = true
- stun_timer = hitstun_duration
- print("[COMBAT] HITSTUN START:", hitstun_duration)
- # =========================================================
- # KNOCKBACK DEBUG SAFE
- # =========================================================
- func apply_knockback(dir: Vector2, force: float):
- if body == null:
- print("[COMBAT] No body reference")
- return
- print("[COMBAT] Knockback attempted")
- if "knockback_velocity" in body:
- body.knockback_velocity = dir * force
- elif "external_velocity" in body:
- body.external_velocity = dir * force
- # =========================================================
- # DEATH
- # =========================================================
- func die():
- print("[COMBAT] DIE")
- get_parent().queue_free()
- # =========================================================
- # STATE CHECK
- # =========================================================
- func can_act() -> bool:
- return not is_stunned
Advertisement
Add Comment
Please, Sign In to add comment