aboutsummaryrefslogtreecommitdiffstats
path: root/godot/scenes/Game.gd
blob: 8b8626385a4a6b8c1f658a829e087a97e3108382 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
extends Spatial

const NUM_LEVELS = 9
const PAR = [1,2,3,4,5,6,7,8,9]

# level control
var current_level_id = 0
var levels = []
var post_game = false

# stroke control
var current_strokes = 0
var strokes_per_level = [0,0,0,0,0,0,0,0,0]

# Called when the node enters the scene tree for the first time.
func _ready():
	for i in range(NUM_LEVELS):
		levels.append(get_node("/root/Game/Level%d" % (i+1)))
		
	current_strokes = 0
	levels[0].show()


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if Input.is_action_just_pressed("ui_cancel"):
		get_tree().paused = true
		$PausePopup.show()
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
		close_scoreboard()
		


func _on_QuitButton_pressed():
	get_tree().quit()


func _on_ResumeButton_pressed():
	$PausePopup.hide()
	get_tree().paused = false
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)


func end_level():
	# save current strokes and reset 
	strokes_per_level[current_level_id] = current_strokes
	current_strokes = 0
	
	post_game = true
	
	open_scoreboard()


func add_stroke():
	current_strokes += 1


func revoke_stroke():
	current_strokes -= 1


func open_scoreboard():
	$Scoreboard.update_values(strokes_per_level, PAR)
	$Scoreboard.show()


func close_scoreboard():
	$Scoreboard.hide()


func is_post_game():
	return post_game


func next_level():
	post_game = false
	
	levels[current_level_id].hide()
	current_level_id = current_level_id + 1
	
	if current_level_id >= NUM_LEVELS:
		# TODO load main menu
		return 
	
	# load next level
	levels[current_level_id].show()
	
	close_scoreboard()