summaryrefslogtreecommitdiff
path: root/Scripts/GameLoop.gd
blob: 5d3c3f49edd10abf7da38e5b46f5729c5b3dd631 (plain)
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
53
54
55
extends Node
class_name GameLoop

@export var turns : int
@export var label : Label
@export var turn_label : Label
@export_file var level : String
@export var can_play : bool = true
@export var win_control : Control
@export var anim : AnimationPlayer
@export var anim_label : Label

var current_turns : int = 0
var prev_turn : int = -1

# Called when the node enters the scene tree for the first time.
func _ready():
	GlobalVariables.gameloop = self
	current_turns = 0

func _process(_delta):
	if prev_turn != current_turns:
		prev_turn = current_turns
		label.text = str(turns - current_turns)
		if current_turns != 0: 
			can_play = false
			turn_label.text = "ai's turn..."
			$"BetweenPlayerAndAI".start()

	if Input.is_action_just_pressed("reset"):
		get_tree().change_scene_to_file(level)

func _on_between_player_and_ai_timeout():
	GlobalVariables.ai.step()
	can_play = true
	if current_turns < turns: turn_label.text = "your turn!"
	else: turn_label.text = ""

	if current_turns >= turns:
		$"AudioDelay".start()

func _on_audio_delay_timeout():
		win_control.visible = true
		anim.play("win")
		anim_label.size = Vector2(1280, 720)
		
		if GlobalVariables.player.get_node("..").value > GlobalVariables.ai.get_node("..").value: 
			anim_label.text = "YOU won!"
			win_control.get_node("Win").play()
		elif GlobalVariables.player.get_node("..").value < GlobalVariables.ai.get_node("..").value: 
			win_control.get_node("Lose").play()
			anim_label.text = "AI won!"
		else: 
			win_control.get_node("Win").play()
			anim_label.text = "It's a TIE!"