blob: 1c788aee97e996a8dbe92f8a46884904d3aac730 (
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
56
57
58
59
60
61
62
63
64
65
66
67
|
extends Node
var game_stats_config = preload("res://resources/game_stats_config.tres")
var morale_down = preload("res://assets/morale_down.wav")
var wave_ready = preload("res://assets/wave_ready.wav")
signal life_changed
signal morale_changed
signal wave_started
var _life : int
var _morale : int
var _current_wave : int
var _is_spawning : bool
func reset():
_life = game_stats_config.starting_life
_morale = game_stats_config.starting_morale
_current_wave = -1
func get_life() -> int:
return _life
func add_life(amount: int):
_life += amount
emit_signal("life_changed")
func subtract_life(amount: int):
_life -= amount
emit_signal("life_changed")
func get_morale() -> int:
return _morale
func add_morale(amount: int):
_morale += amount
emit_signal("morale_changed")
func subtract_morale(amount: int):
_morale -= amount
emit_signal("morale_changed")
if (_morale < 1):
get_tree().change_scene_to_file("res://scenes/game_over.tscn")
else:
_play_sound(morale_down)
func get_is_spawning() -> bool:
return _is_spawning
func start_spawning():
if !_is_spawning && _current_wave < game_stats_config.wave_data.size():
_current_wave += 1
_is_spawning = true
emit_signal("wave_started", _current_wave)
func stop_spawning():
_is_spawning = false
if (_current_wave > game_stats_config.wave_data.size()):
# TODO
print("win!")
else:
_play_sound(wave_ready)
func _play_sound(sound : AudioStream):
var ap = get_tree().current_scene.get_node("Blips")
ap.stream = sound
ap.play()
|