82 lines
2.3 KiB
GDScript3
82 lines
2.3 KiB
GDScript3
|
|
class_name BattleState
|
||
|
|
extends Control
|
||
|
|
|
||
|
|
|
||
|
|
@export var enemy_list:Array[Enemy] = [null, null, null]
|
||
|
|
@export var animation_player:AnimationPlayer
|
||
|
|
@onready var enemy_label_1: Label = %EnemyLabel1
|
||
|
|
@onready var enemy_label_2: Label = %EnemyLabel2
|
||
|
|
@onready var enemy_label_3: Label = %EnemyLabel3
|
||
|
|
@onready var pos_1: Marker2D = %Pos1
|
||
|
|
@onready var pos_2: Marker2D = %Pos2
|
||
|
|
@onready var pos_3: Marker2D = %Pos3
|
||
|
|
var world:World
|
||
|
|
|
||
|
|
func start_battle(list:Array[PackedScene], enemy_name:Array[String]) -> void:
|
||
|
|
delete_all_enemies()
|
||
|
|
var i:int = 0
|
||
|
|
for enemy:PackedScene in list:
|
||
|
|
if enemy != null:
|
||
|
|
var new_enemy:Enemy = enemy.instantiate() as Enemy
|
||
|
|
if i == 0:
|
||
|
|
new_enemy.position = pos_1.global_position
|
||
|
|
enemy_label_1.text = enemy_name[0].to_upper()
|
||
|
|
elif i == 1:
|
||
|
|
new_enemy.position = pos_2.global_position
|
||
|
|
enemy_label_2.text = enemy_name[1].to_upper()
|
||
|
|
elif i == 2:
|
||
|
|
new_enemy.position = pos_3.global_position
|
||
|
|
enemy_label_3.text = enemy_name[2].to_upper()
|
||
|
|
add_child(new_enemy)
|
||
|
|
enemy_list[i] = new_enemy
|
||
|
|
i += 1
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
func start(current_world:World) -> void:
|
||
|
|
world = current_world
|
||
|
|
|
||
|
|
func start_animation() -> void:
|
||
|
|
animation_player.play("appear")
|
||
|
|
|
||
|
|
func command(current_command:String, input:String) -> void:
|
||
|
|
match current_command:
|
||
|
|
"FIGHT":
|
||
|
|
fight(input)
|
||
|
|
|
||
|
|
|
||
|
|
func fight(enemy_to_attack:String) -> void:
|
||
|
|
var new_input:String = enemy_to_attack.replace(" ", "")
|
||
|
|
new_input = new_input.to_upper()
|
||
|
|
if new_input == enemy_label_1.text.replace(" ", ""):
|
||
|
|
if enemy_list[0] != null:
|
||
|
|
enemy_list[0].health -= world.player.damage
|
||
|
|
if enemy_list[0].health <= 0:
|
||
|
|
enemy_list[0].queue_free()
|
||
|
|
enemy_list[0] = null
|
||
|
|
elif new_input == enemy_label_2.text.replace(" ", ""):
|
||
|
|
if enemy_list[1] != null:
|
||
|
|
enemy_list[1].health -= world.player.damage
|
||
|
|
if enemy_list[1].health <= 0:
|
||
|
|
enemy_list[1].queue_free()
|
||
|
|
enemy_list[1] = null
|
||
|
|
elif new_input == enemy_label_3.text.replace(" ", ""):
|
||
|
|
if enemy_list[2] != null:
|
||
|
|
enemy_list[2].health -= world.player.damage
|
||
|
|
if enemy_list[2].health <= 0:
|
||
|
|
enemy_list[2].queue_free()
|
||
|
|
enemy_list[2] = null
|
||
|
|
for enemy in enemy_list:
|
||
|
|
if enemy != null:
|
||
|
|
print(enemy)
|
||
|
|
return
|
||
|
|
animation_player.play("win")
|
||
|
|
await get_tree().create_timer(3).timeout
|
||
|
|
world.end_battle()
|
||
|
|
|
||
|
|
|
||
|
|
func delete_all_enemies() -> void:
|
||
|
|
for enemy in enemy_list:
|
||
|
|
if enemy != null:
|
||
|
|
enemy.queue_free()
|