-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.gd
125 lines (109 loc) · 2.87 KB
/
main.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
extends Node2D
const FIRST_SCENE = "res://scenes/elevator/elevator.tscn"
const MENU_SCENE = "res://scences/start_menu/start_menu.tscn"
func _ready():
game.main = self
#game.music = $music
call_deferred("_first_screen")
func _first_screen():
_load_scene(FIRST_SCENE)
var load_state = 0
var current_scene = ""
func _load_scene(scene):
print( "Loading scene: ", scene, " State: ", load_state )
#print( game.gamestate )
if load_state==0:
#get_tree().paused = true
# set current scene
current_scene = scene
# fade out
$fade_layer/fadeanim.play("fade_out")
load_state = 1
$loadtimer.set_wait_time(0.3)
$loadtimer.start()
elif load_state==1:
# hide hud
#$hud_layer/hud.hide()
# clear current act
var children = $scenes.get_children()
if not children.empty():
_disconnect_scene(children[0])
children[0].queue_free()
load_state = 2
$loadtimer.set_wait_time(0.1)
$loadtimer.start()
elif load_state == 2:
# load new act
var act = load(current_scene).instance()
$scenes.add_child(act)
_connect_scene(act)
#if act is preload( "res://levels/level.gd" ):
# $hud_layer/hud.show()
load_state = 3
$loadtimer.set_wait_time( 0.1 )
$loadtimer.start()
elif load_state == 3:
#show hud
if current_scene != MENU_SCENE:
# $hud_layer/hud.show()
pass
else:
#$hud_layer/hud.hide()
pass
# fade in
$fade_layer/fadeanim.play("fade_in")
# play stuff
load_state = 4
$loadtimer.set_wait_time( 0.3 )
$loadtimer.start()
get_tree().paused = false
elif load_state == 4:
print( "finished loading" )
load_state = 0
func update_hud():
pass
#$hud_layer/hud/coinmgr/coincount/coincount.text = "%d" % game.gamestate.coins
#if game.gamestate.coins > oldcoins:
# oldcoins = game.gamestate.coins
# $hud_layer/hud/coinget.play( "cycle" )
func _on_loadtimer_timeout():
_load_scene(current_scene)
func _connect_scene(v):
v.connect("restart_scene", self, "_restart_scene" )
v.connect("next_scene", self, "_next_scene" )
v.connect("game_over", self, "_game_over" )
func _disconnect_scene(v):
v.disconnect("restart_scene", self, "_restart_scene" )
v.disconnect("next_scene", self, "_next_scene" )
v.disconnect("game_over", self, "_game_over" )
func _restart_scene():
_load_scene(current_scene)
func _next_scene(next_scene):
game.gamestate.start_position = null
_load_scene(next_scene)
func _game_over():
#print( cur_scn, " ", MENU_SCN )
if current_scene==MENU_SCENE:
get_tree().quit()
else:
_load_scene(MENU_SCENE)
var mstate = 0
var curmusic = null
func play_music(res):
#print( " play music ", mstate )
#print( curmusic, " ", res )
match mstate:
0:
curmusic = res
mstate = 1
#$music/musicfade.play("fadeout")
1:
#print( "STARTING MUSIC" )
#$music.stream = curmusic
#$music.play()
#$music/musicfade.play("fadein")
mstate = 2
2:
mstate = 0
func _on_musicfade_animation_finished(anim_name):
play_music( null )