aboutsummaryrefslogtreecommitdiffstats
path: root/Scripts/game.gd
blob: 42918c57367cd794584a6c98a9c665e85c2b63ab (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
extends Node2D

const NUM_LEVELS = 3

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

var scenes = [
#	preload("res://Nodes/levels/level1/level1.tscn"), 
#	preload("res://Nodes/levels/level2/level2.tscn")
	preload("res://Nodes/Level_test.tscn"),
	preload("res://Nodes/Level_test_2.tscn")
	]

# Called when the node enters the scene tree for the first time.
func _ready():
#	$JinglePlayer.stream.loop_mode = AudioStream.LOOP_DISABLED
	load_scene_by_index(0)


# 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
		$CanvasLayer/PausePopup.show()
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)


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


func _on_ResumeButton_pressed():
	$CanvasLayer/PausePopup.hide()
	get_tree().paused = false
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)


func _on_MainMenuButton_pressed():
	get_tree().paused = false
	get_tree().change_scene_to_file("res://Nodes/main_menu.tscn")


func end_level():
#	evaluate_player(current_strokes, PAR[current_level_id])
	$BGMPLayer.stream_paused = true
	$JinglePlayer.play()
	post_game = true


func next_level():
	current_level_id += 1
	
	if current_level_id >= NUM_LEVELS:
		get_tree().change_scene("res://scenes/levels/MainMenu.tscn")
		return 
	
	load_scene_by_index(current_level_id)
	
	# $BGMPLayer.stream_paused = false
	# $JinglePlayer.stop()


func load_scene_by_index(index):
	# clear level
	for n in $LoadedLevel.get_children():
		$LoadedLevel.remove_child(n)
		n.queue_free()
	
	# add new level
	var instance = scenes[index].instantiate()
	$LoadedLevel.add_child(instance)