-
Notifications
You must be signed in to change notification settings - Fork 37
/
global.gd
116 lines (89 loc) · 2.9 KB
/
global.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
extends Node
var mat_bad = preload("res://Materials/mat_segment_bad.tres")
var mat_regular = preload("res://Materials/mat_segment_regular.tres")
var mat_column = preload("res://Materials/mat_column.tres")
var mat_player = preload("res://Materials/mat_player.tres")
var mat_power_up_1
var environment_palette = []
var current_palette
var shadows_button_pattern = [[]]
var sound_button_pattern = [[]]
var player
onready var shadows_enabled = true
onready var sound_enabled = true
var player_color = []
var decal_materials = []
var total_points = 0
var current_points = 0
var progress = 0
var level_size = 29
var level = 0
signal update_points_viewer
signal update_progress
func apply_random_palette():
randomize()
current_palette = environment_palette[randi() % environment_palette.size()]
mat_regular.set_parameter(FixedMaterial.PARAM_DIFFUSE, Color(current_palette[0]))
mat_bad.set_parameter(FixedMaterial.PARAM_DIFFUSE, Color(current_palette[1]))
mat_column.set_parameter(FixedMaterial.PARAM_DIFFUSE, Color(current_palette[2]))
func handle_win():
apply_random_palette()
level += 1
progress = 0
total_points += current_points
current_points = 0
save_game()
get_tree().change_scene("res://Scenes/Input_Handler.tscn")
func handle_lose():
current_points = 0
save_game()
progress = 0
get_tree().change_scene("res://Scenes/Input_Handler.tscn")
func update_progress():
progress += 1
emit_signal("update_progress")
func update_points(addition):
current_points += addition
emit_signal("update_points_viewer", addition)
func _ready():
load_game()
save_game()
load_palette()
apply_random_palette()
func load_palette():
var palette = File.new()
if !palette.file_exists("res://palette.json"):
return #Error
var content = {}
palette.open("res://palette.json", File.READ)
content.parse_json(palette.get_as_text())
palette.close()
for element in content["environment"]:
environment_palette.push_back(element)
mat_player.set_parameter(FixedMaterial.PARAM_DIFFUSE, Color(content["player"]))
shadows_button_pattern = content["shadow_button_pattern"]
sound_button_pattern = content["sound_button_pattern"]
func save_game():
var savedict = {
total_points = total_points,
level = level,
shadows_enabled = shadows_enabled,
sound_enabled = sound_enabled
}
var savegame = File.new()
savegame.open("user://savegame.save", File.WRITE)
savegame.store_line(savedict.to_json())
savegame.close()
func load_game():
var savegame = File.new()
if !savegame.file_exists("user://savegame.save"):
return #Error! We don't have a save to load
var currentline = {}
savegame.open("user://savegame.save", File.READ)
currentline.parse_json(savegame.get_line())
total_points = currentline["total_points"]
level = currentline["level"]
if currentline.has("shadows_enabled"):
shadows_enabled = currentline["shadows_enabled"]
sound_enabled = currentline["sound_enabled"]
savegame.close()