-
Notifications
You must be signed in to change notification settings - Fork 1
/
EndingCutscene2.gd
361 lines (312 loc) · 13.1 KB
/
EndingCutscene2.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
extends Node2D
class_name EndingCutscene2
onready var gamelogic = get_tree().get_root().find_node("LevelScene", true, false).gamelogic;
onready var holder : Label = get_node("CutsceneHolder/Panel3/Holder");
onready var pointer : Sprite = holder.get_node("Pointer");
onready var creditsbutton : Button = holder.get_node("CreditsButton");
onready var quitbutton : Button = holder.get_node("QuitButton");
onready var puzzlebutton : Button = holder.get_node("PuzzleButton");
var only_mouse = true;
onready var using_controller = gamelogic.using_controller;
var end_timer = 0.0;
var end_timer_max = 0.0;
var cutscene_step = 0;
var cutscene_step_cooldown = 0.1;
var has_shown_advance_label = false;
var skip_cutscene_label = null;
var ghost_type = 0;
var ghost_timer = 0.0;
var ghost_timer_max = 0.1;
var sparkle_timer = 0;
var sparkle_timer_max = 0.01;
var sparkles_remaining = 0.0;
var clones_active = 0;
onready var clone_players = [$CutsceneHolder/Panel2/AnimationPlayerClone1, $CutsceneHolder/Panel2/AnimationPlayerClone2, $CutsceneHolder/Panel2/AnimationPlayerClone3];
func _ready() -> void:
gamelogic.cut_sound();
gamelogic.target_track = gamelogic.music_info.find("Patashu - Cutscene E");
gamelogic.fadeout_timer_max = 1.0;
gamelogic.fadeout_timer = gamelogic.fadeout_timer_max - 0.0001;
creditsbutton.connect("pressed", self, "_creditsbutton_pressed");
quitbutton.connect("pressed", self, "_quitbutton_pressed");
puzzlebutton.connect("pressed", self, "_puzzlebutton_pressed");
$CutsceneHolder/Panel3.visible = false;
cutscene_step();
func _creditsbutton_pressed() -> void:
if (gamelogic.ui_stack.size() > 0 and gamelogic.ui_stack[gamelogic.ui_stack.size() - 1] != self):
return;
quitbutton.visible = true;
puzzlebutton.visible = true;
$CutsceneHolder/Panel2.visible = false;
var a = preload("res://CreditsModal.tscn").instance();
gamelogic.add_to_ui_stack(a, get_parent());
func _puzzlebutton_pressed() -> void:
if (gamelogic.ui_stack.size() > 0 and gamelogic.ui_stack[gamelogic.ui_stack.size() - 1] != self):
return;
begin_the_end();
func _quitbutton_pressed() -> void:
if (gamelogic.ui_stack.size() > 0 and gamelogic.ui_stack[gamelogic.ui_stack.size() - 1] != self):
return;
get_tree().quit();
func cutscene_step() -> void:
if (cutscene_step_cooldown < 0.1):
return;
if ($CutsceneHolder/Panel1/AnimationPlayer.current_animation == "Animate" and $CutsceneHolder/Panel1/AnimationPlayer.is_playing()):
return;
if ($CutsceneHolder/Panel2/AnimationPlayer.current_animation == "Animate" and $CutsceneHolder/Panel2/AnimationPlayer.is_playing()):
return;
cutscene_step_cooldown = 0;
$CutsceneHolder/AdvanceLabel.visible = false;
match cutscene_step:
0:
$CutsceneHolder.visible = true;
$CutsceneHolder/Panel1.visible = true;
$CutsceneHolder/Panel2.visible = false;
$CutsceneHolder/Panel2/ColorRect.visible = true;
$CutsceneHolder/Panel2/Mop.modulate = Color(1, 1, 1, 1);
$CutsceneHolder/Panel2/Broom.modulate = Color(1, 1, 1, 1);
$CutsceneHolder/Panel2/Stack.modulate = Color(1, 1, 1, 1);
$CutsceneHolder/Panel2/Toolbox.modulate = Color(1, 1, 1, 1);
$CutsceneHolder/Panel2/HeavyClone1.modulate = Color(1, 1, 1, 0);
$CutsceneHolder/Panel2/HeavyClone2.modulate = Color(1, 1, 1, 0);
$CutsceneHolder/Panel2/HeavyClone3.modulate = Color(1, 1, 1, 0);
$CutsceneHolder/Panel2/LightClone1.modulate = Color(1, 1, 1, 0);
$CutsceneHolder/Panel2/LightClone2.modulate = Color(1, 1, 1, 0);
$CutsceneHolder/Panel2/LightClone3.modulate = Color(1, 1, 1, 0);
var tween = get_tree().create_tween()
$CutsceneHolder/Panel1.modulate = Color(1, 1, 1, 0);
tween.tween_property($CutsceneHolder/Panel1, "modulate", Color.white, 0.5);
1:
$CutsceneHolder/Panel1/AnimationPlayer.play("Animate");
2:
change_ghosts(2);
$CutsceneHolder/Panel2.visible = true;
var tween = get_tree().create_tween()
$CutsceneHolder/Panel2.modulate = Color(1, 1, 1, 0);
tween.tween_property($CutsceneHolder/Panel2, "modulate", Color.white, 0.5);
$CutsceneHolder/Panel2/AnimationPlayer.play("Animate");
3:
ghost_type = 0;
setup_label_text();
$CutsceneHolder/Panel1.visible = false;
$CutsceneHolder/Panel3.visible = true;
var tween = get_tree().create_tween()
$CutsceneHolder/Panel3.modulate = Color(1, 1, 1, 0);
tween.tween_property($CutsceneHolder/Panel3, "modulate", Color.white, 1.0);
has_shown_advance_label = false;
cutscene_step += 1;
func setup_label_text() -> void:
var label = holder.get_node("Label");
label.text = "Congratulations on beating Entwined Time!\n\nAs a reward, all custom level editor elements are now unlocked!\n\n"
var standard_completion = standard_completion();
label.text += "Your rate for Standard puzzle completion is: " + str(standard_completion[0]) + "/" + str(standard_completion[1]);
if (standard_completion[1] - standard_completion[0] < 5):
label.text += "! Well done!\n\n"
var campaign_completion = campaign_completion();
label.text += "Your rate for Campaign puzzle completion is: " + str(campaign_completion[0]) + "/" + str(campaign_completion[1]) + "\n\n";
if (campaign_completion[0] >= campaign_completion[1]):
label.text += "Wow! I couldn't stump you at all! Maybe you can make a puzzle we can't solve now...?"
func standard_completion() -> Array:
# count all standard puzzles except Victory Lap, Secrets of Space-Time and Community Levels
var result = [0, 0];
for i in range(gamelogic.custom_past_here - 1):
if (i == 2):
continue;
var standard_start = gamelogic.chapter_standard_starting_levels[i];
var advanced_start = gamelogic.chapter_advanced_starting_levels[i];
for j in range(standard_start, advanced_start):
if (gamelogic.specific_puzzles_completed[j]):
result[0] += 1;
result[1] += 1;
return result;
func campaign_completion() -> Array:
var result = [gamelogic.puzzles_completed, gamelogic.custom_past_here_level_count];
return result;
func begin_the_end() -> void:
if (end_timer_max > 0.0):
return;
end_timer_max = 2.5;
holder.queue_free();
pointer = null;
random_good_level();
gamelogic.play_sound("bootup");
func random_good_level() -> void:
# logic:
# if first community puzzle isn't beaten, take the player to that
# else, take the player to a random unbeaten puzzle
# else, take the player to a random puzzle
if (gamelogic.specific_puzzles_completed[gamelogic.custom_past_here_level_count] == false):
gamelogic.load_level_direct(gamelogic.custom_past_here_level_count);
else:
var candidates = [];
for i in range(gamelogic.specific_puzzles_completed.size()):
if !gamelogic.specific_puzzles_completed[i]:
candidates.append(i);
if (candidates.size()) > 0:
gamelogic.load_level_direct(candidates[gamelogic.rng.randi_range(0, candidates.size() - 1)]);
else:
gamelogic.load_level_direct(gamelogic.rng.randi_range(0, gamelogic.specific_puzzles_completed.size() - 1));
func advance_label() -> void:
if (has_shown_advance_label):
return
if ($CutsceneHolder/Panel2/AnimationPlayer.is_playing()):
return
has_shown_advance_label = true;
$CutsceneHolder/AdvanceLabel.visible = true;
var tween = get_tree().create_tween()
tween.tween_property($CutsceneHolder/AdvanceLabel, "modulate", Color.white, 1);
if (only_mouse):
$CutsceneHolder/AdvanceLabel.text = "(Left click or tap the screen to advance cutscene)";
else:
$CutsceneHolder/AdvanceLabel.text = "(" + gamelogic.human_readable_input("ui_accept", 1) + " to advance cutscene)";
func skip_cutscene_label_grows(delta: float) -> void:
if (cutscene_step > 3):
return;
if (skip_cutscene_label == null):
skip_cutscene_label = preload("res://SkipCutsceneLabel.tscn").instance();
self.add_child(skip_cutscene_label);
var progressbar = skip_cutscene_label.get_node("ProgressBar");
progressbar.value += delta;
if (progressbar.value >= progressbar.max_value):
cutscene_step = 3;
$CutsceneHolder/Panel1/AnimationPlayer.stop();
$CutsceneHolder/Panel2/AnimationPlayer.stop();
cutscene_step();
func reset_skip_cutscene_label() -> void:
if (skip_cutscene_label != null):
skip_cutscene_label.queue_free();
skip_cutscene_label = null;
func play_sound(sound: String) -> void:
gamelogic.play_sound(sound);
if sound == "usegreenality":
gamelogic.achievement_get("RepairsComplete");
sparkles_remaining = 0.75;
if $CutsceneHolder/Panel2.visible:
clone_players[clones_active].play("Animate");
clones_active += 1;
func destroy() -> void:
self.queue_free();
gamelogic.ui_stack.erase(self);
func _input(event: InputEvent) -> void:
if cutscene_step > 0:
if event is InputEventScreenTouch:
if event.pressed:
cutscene_step();
func add_sparkle(end: bool = false) -> void:
var rng = gamelogic.rng;
var sprite = Sprite.new();
sprite.set_script(preload("res://FadingSprite.gd"));
sprite.texture = preload("res://assets/Sparkle.png")
if (end):
sprite.position = $CutsceneHolder/Panel2/Label.rect_position;
sprite.position.x += $CutsceneHolder/Panel2/Label.rect_size.x*gamelogic.rng.randf_range(0.0, 1.0);
sprite.position.y += $CutsceneHolder/Panel2/Label.rect_size.y*gamelogic.rng.randf_range(0.0, 1.0);
else:
sprite.position = Vector2(gamelogic.pixel_width/2, gamelogic.pixel_height/2);
sprite.position += Vector2(gamelogic.rng.randf_range(0, 100), 0).rotated(gamelogic.rng.randf_range(0, 2*PI));
sprite.frame = 0;
sprite.centered = true;
sprite.modulate = Color("A9F05F");
var scalify = gamelogic.rng.randf_range(0.25, 0.5);
sprite.scale = Vector2(scalify, scalify);
self.add_child(sprite);
func change_ghosts(type: int) -> void:
ghost_type = type;
ghost_timer = 0.0;
if (ghost_type == 2):
ghost_timer_max = 0.5;
else:
ghost_timer_max = 0.1;
func afterimage(sprite: Sprite, color: Color) -> void:
var afterimage = preload("res://Afterimage.tscn").instance();
afterimage.actor = sprite;
afterimage.set_material(gamelogic.get_afterimage_material_for(color));
$CutsceneHolder/Panel2.add_child(afterimage);
afterimage.scale = sprite.scale;
afterimage.get_child(0).centered = sprite.centered;
func ghost(sprite: Sprite) -> void:
var ghost = Sprite.new();
ghost.script = preload("res://GhostSprite.gd");
ghost.position = sprite.position;
ghost.target = sprite;
ghost.texture = sprite.texture;
ghost.centered = sprite.centered;
ghost.scale = sprite.scale;
ghost.flip_h = sprite.flip_h;
ghost.fadeout_timer = $CutsceneHolder/Panel2/ColorRect.modulate.a;
$CutsceneHolder/Panel2.add_child(ghost);
var end_sparkles_remaining = 0.0;
func the_end_sparkles() -> void:
sparkle_timer = 0.0;
end_sparkles_remaining = 3.0;
sparkle_timer_max *= 10.0;
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if (ghost_type == 1):
ghost_timer += delta;
if (ghost_timer > ghost_timer_max):
ghost_timer -= ghost_timer_max;
afterimage($CutsceneHolder/Panel2/HeavyActor, gamelogic.heavy_color);
afterimage($CutsceneHolder/Panel2/LightActor, gamelogic.light_color);
elif (ghost_type == 2):
ghost_timer += delta;
if (ghost_timer > ghost_timer_max):
ghost_timer -= ghost_timer_max;
ghost($CutsceneHolder/Panel2/HeavyActor);
ghost($CutsceneHolder/Panel2/LightActor);
if (sparkles_remaining > 0.0):
sparkles_remaining -= delta;
sparkle_timer += delta;
if (sparkle_timer > sparkle_timer_max):
sparkle_timer -= sparkle_timer_max;
add_sparkle(false);
if (end_sparkles_remaining > 0.0):
end_sparkles_remaining -= delta;
sparkle_timer += delta;
if (sparkle_timer > sparkle_timer_max):
sparkle_timer -= sparkle_timer_max;
add_sparkle(true);
cutscene_step_cooldown += delta;
if (cutscene_step > 0):
if (cutscene_step < 3 and cutscene_step_cooldown > 4.0):
advance_label();
if (Input.is_action_just_pressed("ui_accept") or Input.is_action_just_pressed("character_switch")
or Input.is_action_just_pressed("lmb")):
cutscene_step();
elif (Input.is_action_pressed("escape") and end_timer_max == 0.0):
skip_cutscene_label_grows(delta);
else:
reset_skip_cutscene_label();
if (Input.is_action_just_pressed("any_controller") or Input.is_action_just_pressed("any_controller_2")):
using_controller = true;
only_mouse = false;
if Input.is_action_just_pressed("any_keyboard"):
using_controller = false;
only_mouse = false;
if (end_timer_max > 0):
if (Input.is_action_pressed("escape")):
end_timer += delta*3;
else:
end_timer += delta;
if (end_timer >= end_timer_max):
destroy();
else:
self.modulate = Color(1, 1, 1, ((end_timer_max-end_timer)/end_timer_max));
if (gamelogic.ui_stack.size() > 0 and gamelogic.ui_stack[gamelogic.ui_stack.size() - 1] != self):
if (pointer != null):
pointer.visible = false;
return;
if (pointer != null and $CutsceneHolder/Panel3.visible):
pointer.visible = true;
var focus = holder.get_focus_owner();
if (focus == null):
creditsbutton.grab_focus();
focus = creditsbutton;
var focus_middle_x = focus.rect_position.x + focus.rect_size.x / 2;
pointer.position.y = focus.rect_position.y + focus.rect_size.y / 2;
if (focus_middle_x > holder.rect_size.x / 2):
pointer.texture = preload("res://assets/tutorial_arrows/LeftArrow.tres");
pointer.position.x = focus.rect_position.x + focus.rect_size.x + 12;
else:
pointer.texture = preload("res://assets/tutorial_arrows/RightArrow.tres");
pointer.position.x = focus.rect_position.x - 12;