Raise-Your-Wand/Scripts/playerController.gd
nc543 5079a77296 Main Menu and AI
- Mostly finished the settings menu
- Got basic AI working on easy difficulty
- Changed when animations are loaded
- Music now changes when you hit play
- Changed how AI will work. All enemies should only need the combatant script now
2024-05-12 00:22:34 -04:00

64 lines
2.4 KiB
GDScript

extends Node
@onready var data: Data = get_node("/root/Root/Data")
@onready var castIndicator: CastIndicator = get_node("/root/Root/Arena/CastIndicator")
@export var avatar: Combatant
var casting = false
var spell: Spell
var spellIndex: int
var timer: float = 0
var anim: AnimationBase
# Called when the node enters the scene tree for the first time.
func _ready():
data.spellbook.initCooldowns()
for spel: Spell in data.spellbook.spells:
if (spel == null): continue
if !data.animations.has(spel.animation):
data.animations[spel.animation] = load(spel.animation)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if !casting:
for i in range(data.spellbook.spells.size()):
if Input.is_action_just_pressed("Spell" + str(i)) && data.spellbook.cooldowns[i] == 0:
casting = true
spell = data.spellbook.spells[i]
spellIndex = i
castIndicator.show()
castIndicator.setDirs(spell.castCombo[0], spell.castCombo[1])
anim = data.animations[spell.animation].instantiate()
anim.setProgress(0, spell.castCombo.size())
get_node("/root").add_child(anim)
timer = 0
else:
timer += delta
if (Input.is_action_just_pressed(spell.castCombo[spell.castProgress])):
spell.castProgress += 1
anim.setProgress(spell.castProgress)
if spell.castProgress == spell.castCombo.size() - 1:
castIndicator.setDirs(spell.castCombo[spell.castProgress])
elif spell.castProgress < spell.castCombo.size() - 1:
castIndicator.setDirs(spell.castCombo[spell.castProgress], spell.castCombo[spell.castProgress + 1])
if spell.castProgress == spell.castCombo.size():
casting = false
spell.castProgress = 0
avatar.renderer.play("attack1")
data.spellbook.cooldowns[spellIndex] = spell.cooldown
castIndicator.hide()
data.opponent.alterHealth(-spell.damage, false)
elif (timer >= spell.timeout || Input.is_action_just_pressed("up") || Input.is_action_just_pressed("down") || Input.is_action_just_pressed("left") || Input.is_action_just_pressed("right")):
avatar.alterHealth(-spell.backfireStrength, true)
casting = false
anim.castFailed()
spell.castProgress = 0
data.spellbook.cooldowns[spellIndex] = spell.cooldown * (float(spell.castProgress) / float(spell.castCombo.size()))
castIndicator.hide()
for i in range(data.spellbook.cooldowns.size()):
data.spellbook.cooldowns[i] -= delta
if data.spellbook.cooldowns[i] < 0: data.spellbook.cooldowns[i] = 0