-
Notifications
You must be signed in to change notification settings - Fork 1
/
Battle.gd
52 lines (43 loc) · 1.39 KB
/
Battle.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
extends Node
const BattleUnits = preload("res://BattleUnits.tres")
export(Array, PackedScene) var enemies = []
onready var battleActionButtons = $UI/BattleActionButtons
onready var animationPlayer = $AnimationPlayer
onready var nexRoomButton = $UI/CenterContainer/NextRoomButton
onready var enemyPosition = $EnemyPosition
func _ready():
randomize()
start_player_turn()
var enemy = BattleUnits.Enemy
if enemy != null :
enemy.connect("died", self, "_on_Enemy_died")
func start_enemy_turn():
battleActionButtons.hide()
var enemy = BattleUnits.Enemy
if enemy != null and not enemy.is_queued_for_deletion():
enemy.attack()
yield(enemy, "end_turn")
start_player_turn()
func start_player_turn():
battleActionButtons.show()
var playerStats = BattleUnits.PlayerStats
playerStats.ap = playerStats.max_ap
yield(playerStats, "end_turn")
start_enemy_turn()
func create_new_enemy():
enemies.shuffle()
var Enemy = enemies.front() #Enemy Scene
var enemy = Enemy.instance() #Enemy instance
enemyPosition.add_child(enemy)
enemy.connect("died", self, "_on_Enemy_died")
func _on_Enemy_died():
nexRoomButton.show()
battleActionButtons.hide()
func _on_NextRoomButton_pressed():
nexRoomButton.hide()
animationPlayer.play("FadeToNewRoom")
yield(animationPlayer, "animation_finished")
var playerStats = BattleUnits.PlayerStats
playerStats.ap = playerStats.max_ap
battleActionButtons.show()
create_new_enemy()