/
boot.lua
369 lines (301 loc) · 11.1 KB
/
boot.lua
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
362
363
364
365
366
367
368
369
-- Boot animation script file
-- Set the boot tablespace name.
local ns = {}
setmetatable(ns, {__index = _G})
boot = ns;
setfenv(1, ns);
-- The Boot instance
local Boot = {};
local Script = {};
local animation_timer = {};
local boot_state = {};
local bckgrnd_id = {};
local logo_id = {};
local cloud_field_id = {};
local mist_id = {};
local fog_id = {};
local crystal_id = {};
local crystal_shadow_id = {};
local satellite_id = {};
local satellite_shadow_id = {};
local flare_id = {};
-- Init all the needed variables
function Initialize(boot_instance)
Boot = boot_instance;
Script = Boot:GetScriptSupervisor();
boot_state = Boot:GetState();
-- Load the necessary files
bckgrnd_id = Script:AddImage("img/backdrops/boot/background.png", 1024, 768);
logo_id = Script:AddImage("img/logos/valyria_logo_black.png", 630, 318);
cloud_field_id = Script:AddImage("img/backdrops/boot/cloudfield.png", 248, 120);
mist_id = Script:AddImage("img/backdrops/boot/cloudy_mist.png", 1024, 768);
fog_id = Script:AddImage("img/backdrops/boot/fog.png", 1024, 768);
crystal_id = Script:AddImage("img/backdrops/boot/crystal.png", 140, 220);
crystal_shadow_id = Script:AddImage("img/backdrops/boot/crystal_shadow.png", 192, 168);
satellite_id = Script:AddImage("img/backdrops/boot/satellite.png", 34, 34);
satellite_shadow_id = Script:AddImage("img/backdrops/boot/satellite_shadow.png", 48, 32);
flare_id = Script:AddImage("img/backdrops/boot/flare.png", 256, 256);
-- Init the timer
animation_timer = vt_system.SystemTimer(7000, 0);
end
function Reset()
if (Boot:GetState() == vt_boot.BootMode.BOOT_STATE_MENU) then
AudioManager:PlayMusic("mus/Soliloquy_1-OGA-mat-pablo.ogg");
end
end
-- The image alpha channel values
local logo_alpha = 0.0;
local bckgrnd_alpha = 0.0;
-- cloud field members
local x_positions1 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position1 = 368.0;
local x_positions2 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position2 = 438.0;
local x_positions3 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position3 = 508.0;
local x_positions4 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position4 = 578.0;
local x_positions5 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position5 = 648.0;
local x_positions6 = { -110.0, 0.0, 110.0, 220.0 , 330.0, 440.0, 550.0, 660.0, 770.0, 880.0, 990.0};
local y_position6 = 718.0;
-- crystal members
local crystal_decay = 0.0;
local crystal_time = 0;
-- satellite members
local sat1_decay = 0.0;
local sat1_x_position = -15.0;
local sat1_time = 0;
local sat1_behind = false;
local sat2_decay = 20.0;
local sat2_x_position = 80.0;
local sat2_time = 0;
local sat2_behind = false;
local sat3_decay = 10.0;
local sat3_x_position = 40.0;
local sat3_time = 0;
local sat3_behind = true;
function UpdateIntroFade()
-- After one second of black, start fade in the logo
if (animation_timer:GetTimeExpired() > 1000
and animation_timer:GetTimeExpired() <= 4000) then
logo_alpha = (animation_timer:GetTimeExpired() - 1000) / (4000 - 1000);
elseif (animation_timer:GetTimeExpired() > 4000
and animation_timer:GetTimeExpired() <= 7000) then
bckgrnd_alpha = (animation_timer:GetTimeExpired() - 4000) / (7000 - 4000);
end
end
-- Put the x coord on screen
function fix_pos(position)
if (position <= -248.0) then
return position + 1224.0;
else
return position;
end
end
function UpdateBackgroundAnimation()
local time_expired = SystemManager:GetUpdateTime();
-- deal with all the clouds
for i=1, #x_positions1 do
x_positions1[i] = fix_pos(x_positions1[i]) - 0.025 * time_expired;
end
for i=1, #x_positions2 do
x_positions2[i] = fix_pos(x_positions2[i]) - 0.05 * time_expired;
end
for i=1, #x_positions3 do
x_positions3[i] = fix_pos(x_positions3[i]) - 0.075 * time_expired;
end
for i=1, #x_positions4 do
x_positions4[i] = fix_pos(x_positions4[i]) - 0.1 * time_expired;
end
for i=1, #x_positions5 do
x_positions5[i] = fix_pos(x_positions5[i]) - 0.125 * time_expired;
end
for i=1, #x_positions6 do
x_positions6[i] = fix_pos(x_positions6[i]) - 0.15 * time_expired;
end
-- Compute the crystal and shadow movement
crystal_time = crystal_time + time_expired
if (crystal_time >= 31400) then
crystal_time = crystal_time - 31400;
end
crystal_decay = 10 + math.sin(0.002 * crystal_time) * 10;
-- compute the satellites movement
sat1_time = sat1_time + time_expired
if (sat1_time >= 31400) then
sat1_time = sat1_time - 31400;
end
sat1_decay = -5 + math.sin(0.003 * sat1_time) * 10;
sat1_x_position = 50 + (math.sin(0.0008 * sat1_time - 0.785) * 75);
if (sat1_behind) then
if (sat1_x_position < -24.0) then
sat1_behind = false;
end
else
if (sat1_x_position > 124.0) then
sat1_behind = true;
end
end
sat2_time = sat2_time + time_expired
if (sat2_time >= 31400) then
sat2_time = sat2_time - 31400;
end
sat2_decay = -5 + math.sin(0.003 * sat2_time + 1.57) * 10;
sat2_x_position = 50 + (math.sin(0.0008 * sat2_time + 3.14) * 75);
if (sat2_behind) then
if (sat2_x_position < -24.0) then
sat2_behind = false;
end
else
if (sat2_x_position > 124.0) then
sat2_behind = true;
end
end
sat3_time = sat3_time + time_expired
if (sat3_time >= 31400) then
sat3_time = sat3_time - 31400;
end
sat3_decay = -5 + math.sin(0.003 * sat3_time + 0.785) * 10;
sat3_x_position = 50 + (math.sin(0.0008 * sat3_time + 0.785) * 75);
if (sat3_behind) then
if (sat3_x_position < -24.0) then
sat3_behind = false;
end
else
if (sat3_x_position > 124.0) then
sat3_behind = true;
end
end
end
local music_started = false;
local snow_started = false;
-- Update the animation
function Update()
animation_timer:Update();
UpdateBackgroundAnimation();
if (Boot:GetState() == vt_boot.BootMode.BOOT_STATE_INTRO) then
-- Start the timer
if (animation_timer:IsInitial() == true and animation_timer:IsRunning() ~= true) then
animation_timer:Run();
elseif (animation_timer:IsFinished() == true) then
-- Show the menu once the presentation is done
Boot:ChangeState(vt_boot.BootMode.BOOT_STATE_MENU);
end
-- Update the starting animation
UpdateIntroFade();
else
logo_alpha = 1.0;
bckgrnd_alpha = 1.0;
animation_timer:Finish();
end
if (music_started == false) then
AudioManager:PlayMusic("mus/Soliloquy_1-OGA-mat-pablo.ogg");
music_started = true;
end
-- Update the menu bar alpha in menu mode.
if (Boot:GetState() == vt_boot.BootMode.BOOT_STATE_MENU) then
if (snow_started == false) then
Boot:GetParticleManager():AddParticleEffect("dat/effects/particles/snow.lua", 512.0, 384.0);
snow_started = true;
end
end
end
local cloud_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
function DrawCloudFieldLine(x_positions, y_position)
for _,v in pairs(x_positions) do
Script:DrawImage(cloud_field_id,
v, y_position,
cloud_color);
end
end
local background_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
function DrawBackground()
-- The background image
background_color:SetAlpha(bckgrnd_alpha);
Script:DrawImage(bckgrnd_id, 0.0, 0.0, background_color);
-- The passing clouds
cloud_color:SetAlpha(0.6 * bckgrnd_alpha);
DrawCloudFieldLine(x_positions1, y_position1);
DrawCloudFieldLine(x_positions2, y_position2);
DrawCloudFieldLine(x_positions3, y_position3);
DrawCloudFieldLine(x_positions4, y_position4);
DrawCloudFieldLine(x_positions5, y_position5);
DrawCloudFieldLine(x_positions6, y_position6);
end
local mist_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
local fog_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
local logo_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
local sat_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
local sat_shadow_color = vt_video.Color(1.0, 1.0, 1.0, 1.0);
function DrawPostEffects()
-- front mist + fog
mist_color:SetAlpha(bckgrnd_alpha * 0.6);
fog_color:SetAlpha(bckgrnd_alpha * 0.8);
Script:DrawImage(mist_id, 0.0, 0.0, mist_color);
Script:DrawImage(fog_id, 0.0, 0.0, fog_color);
sat_shadow_color:SetAlpha(bckgrnd_alpha * 0.3);
sat_color:SetAlpha(bckgrnd_alpha * 0.7);
-- satellite behind
if (sat1_behind) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat1_decay + (sat1_x_position / 2.0), 438.0 + (sat1_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat1_x_position, 368.0 - sat1_decay,
sat_color);
end
if (sat2_behind) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat2_decay + (sat2_x_position / 2.0), 438.0 + (sat2_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat2_x_position, 368.0 - sat2_decay,
sat_color);
end
if (sat3_behind) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat3_decay + (sat3_x_position / 2.0), 438.0 + (sat3_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat3_x_position, 368.0 - sat3_decay,
sat_color);
end
-- Crystal
Script:DrawImage(crystal_shadow_id,
498.0 + crystal_decay, 438.0,
sat_shadow_color);
Script:DrawImage(crystal_id,
448.0, 368.0 - crystal_decay,
sat_color);
Script:DrawImage(flare_id,
384.0, 328.0 - crystal_decay,
mist_color);
-- satellite in front
if (sat1_behind == false) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat1_decay + (sat1_x_position / 2.0), 438.0 + (sat1_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat1_x_position, 368.0 - sat1_decay,
sat_color);
end
if (sat2_behind == false) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat2_decay + (sat2_x_position / 2.0), 438.0 + (sat2_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat2_x_position, 368.0 - sat2_decay,
sat_color);
end
if (sat3_behind == false) then
Script:DrawImage(satellite_shadow_id,
640.0 + sat3_decay + (sat3_x_position / 2.0), 438.0 + (sat3_x_position / 3.0),
sat_shadow_color);
Script:DrawImage(satellite_id,
448.0 + sat3_x_position, 368.0 - sat3_decay,
sat_color);
end
-- Logo
logo_color:SetAlpha(logo_alpha);
Script:DrawImage(logo_id, 198.0, 18.0, logo_color);
end