73 lines
1.7 KiB
GDScript
73 lines
1.7 KiB
GDScript
class_name Combatant extends Node2D
|
|
|
|
signal healthChanged(health: float)
|
|
|
|
@onready var renderer: AnimatedSprite2D = $AnimatedSprite2D
|
|
@onready var healthbar: HealthBar = $HealthBar
|
|
@onready var data: Data = get_node("/root/Root/Data")
|
|
|
|
@export var spellbook: Spellbook
|
|
@export var maxHealth: float = 10
|
|
@export var health: float = maxHealth
|
|
@export var player: bool = false
|
|
|
|
var casting: bool = false
|
|
var castCooldown: float = 0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
renderer.animation_finished.connect(animationFinished)
|
|
renderer.play("idle")
|
|
spellbook.initCooldowns()
|
|
healthbar.maxHealth = maxHealth
|
|
if !player:
|
|
data.opponent = self
|
|
renderer.flip_h = true
|
|
healthbar.position.x *= -1
|
|
match data.difficulty:
|
|
Data.Difficulty.EASY: castCooldown = 3
|
|
Data.Difficulty.NORMAL: castCooldown = 1
|
|
Data.Difficulty.HARD: castCooldown = 0.5
|
|
Data.Difficulty.GAMER: castCooldown = 0
|
|
else:
|
|
data.player = self
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if !player:
|
|
match data.difficulty:
|
|
Data.Difficulty.EASY: _easyAI(delta)
|
|
Data.Difficulty.NORMAL: _normalAI(delta)
|
|
Data.Difficulty.HARD: _hardAI(delta)
|
|
Data.Difficulty.GAMER: _gamerAI(delta)
|
|
|
|
func _easyAI(delta) -> void:
|
|
pass
|
|
|
|
func _normalAI(delta) -> void:
|
|
pass
|
|
|
|
func _hardAI(delta) -> void:
|
|
pass
|
|
|
|
func _gamerAI(delta) -> void:
|
|
pass
|
|
|
|
func _finishedCasting() -> void:
|
|
pass
|
|
|
|
func timing(delta) -> void:
|
|
castCooldown -= delta
|
|
if castCooldown <= 0:
|
|
pass
|
|
|
|
func alterHealth(change: float, stun: bool) -> void:
|
|
health += change
|
|
if stun:
|
|
casting = false
|
|
renderer.play("hit")
|
|
healthChanged.emit(health)
|
|
|
|
func animationFinished() -> void:
|
|
renderer.play("idle")
|