var time_part1_start = 1085;
var time_spinner_start = 10302;
var time_spinner_end = 11140;
var time_first_object = 11811;
var time_part1_end = 24213;
var time_part2 = 25219;
var time_part2_voice_a = 42984;
var time_part2_voice_b = 43654;
var time_part3 = 46671;
var time_part4_start = 57397;
var time_part4_1 = 62760;
var time_part4_2 = 65107;
var time_part4_3 = 65442;
var time_part4_4 = 68794;
var time_part4_end = 69800;
var time_chorus_start = 70805;
var time_chorus_end = 92258;
var time_part5 = 94939;
var time_part6 = 102984;
var time_outro = 113710;
var time_end = 121755;
var time_true_end = 124436;
var time_scorescreen = 125777;
function make_title_glow(t0, t1) {
var time_title_start = t0;
var time_title_end = t1;
var time_title_a = time_title_start + (time_title_end - time_title_start) / 4.0;
var time_title_b = time_title_start + 3 * (time_title_end - time_title_start) / 4.0;
var deg_to_rad = 3.14 / 180;
var ls1 = new Sprite("ls.png", Pass, CentreLeft);
ls1.color(time_title_start, time_title_end, 17,254,176, 173,255,95);
ls1.additive(time_title_start, time_title_end);
ls1.fade(time_title_start, time_title_a, 0, 0.7);
ls1.fade(time_title_b, time_title_end, 0.7, 0);
ls1.move(time_title_start, time_title_end, 0, 142, 0 + 50, 142);
ls1.rotate(time_title_start, time_title_end, -10 * deg_to_rad, 5 * deg_to_rad);
ls1.scale(2, time_title_start, time_title_end, 1, 2);
var ls2 = new Sprite("ls.png", Pass, CentreRight);
ls2.color(time_title_start, time_title_end, 255,88,100, 255,94,55);
ls2.additive(time_title_start, time_title_end);
ls2.flipH(time_title_start, time_title_end);
ls2.flipV(time_title_start, time_title_end);
ls2.fade(time_title_start, time_title_a, 0, 1);
ls2.fade(time_title_b, time_title_end, 1, 0);
ls2.move(time_title_start, time_title_end, 640, 120, 640 - 50, 120);
ls2.rotate(time_title_start, time_title_end, -10 * deg_to_rad, 5 * deg_to_rad);
ls2.scale(2, time_title_start, time_title_end, 1, 2);
}
function make_glow(t0, duration) {
var lf = new Sprite("g.png", Foreground, Centre);
var lf_t0 = t0;
var lf_t1 = t0 + duration / 4.0;
var lf_t2 = t0 + 3 * duration / 4.0;
var lf_t3 = t0 + duration;
var screen_width = 640;
var screen_height = 480;
var offset = 100;
var lf_x = rand(offset, screen_width - offset);
var lf_y = rand(offset, screen_height - offset);
var lf_size = rand(60, 120) / 100.0;
var lf_opacity = rand(40, 70) / 100.0;
var deg_to_rad = 3.14 / 180;
var angle = rand(0, 360) * deg_to_rad;
lf.rotate(lf_t0, lf_t3, angle, angle);
lf.scale(lf_t0, lf_t3, lf_size, lf_size * 1.5);
lf.move(lf_t0, lf_t3, lf_x, lf_y, lf_x, lf_y);
lf.fade(1, lf_t0, lf_t1, 0, lf_opacity);
lf.fade(2, lf_t2, lf_t3, lf_opacity, 0);
lf.additive(lf_t0, lf_t3);
if (rand(0, 1) == 1) {
lf.flipH(lf_t0, lf_t3);
}
if (rand(0, 1) == 1) {
lf.flipV(lf_t0, lf_t3);
}
var color = rand(0, 4);
if (color == 0) {
lf.color(lf_t0, lf_t3, 17,254,176, 17,254,176);
} else if (color == 1) {
lf.color(lf_t0, lf_t3, 173,255,95, 173,255,95);
} else if (color == 2) {
lf.color(lf_t0, lf_t3, 255,88,100, 255,88,100);
} else if (color == 3) {
lf.color(lf_t0, lf_t3, 255,94,55, 255,94,55);
}
}
function make_snowflake(t0, duration, fall_speed, pop_time) {
var pop_delay = 1005; // 3 beats for this song
var pops = false;
if (pop_time > 0 && t0 + duration > pop_time) {
duration = pop_time - t0;
pops = true;
}
var lf_t0 = t0;
var lf_t1 = t0 + duration / 4.0;
var lf_t2 = t0 + 3 * duration / 4.0;
var lf_t3 = t0 + duration;
// they should never take more than one second to appear
if (lf_t1 - lf_t0 > 1000) {
lf_t1 = lf_t0 + 1000;
}
var screen_width = 640 * (1366 / 1024.0);
var screen_height = 480;
var x_offset = -((screen_width / 2) - (640 / 2));
var y_offset = - (lf_t1 - lf_t0) / 1000 * fall_speed;
var lf_x = rand(0, screen_width) + x_offset;
var lf_y = rand(0, screen_height - y_offset) + y_offset;
var lf_x_end = lf_x;
var lf_y_end = lf_y + fall_speed * duration / 1000.0;
var lf_size = rand(10, 100) / 100.0;
var lf_opacity = rand(20, 80) / 100.0;
var lf = new Sprite("star2.png", Foreground, Centre);
var abs_fall_speed = fall_speed;
if (abs_fall_speed < 0) {
abs_fall_speed = -abs_fall_speed;
}
var speed_scale_multiplier = abs_fall_speed / 200.0;
if (speed_scale_multiplier < 1) {
speed_scale_multiplier = 1;
}
var grow_factor = 1.5;
lf.scaleVec(lf_t0, lf_t3, lf_size, lf_size * speed_scale_multiplier, lf_size * grow_factor, lf_size * grow_factor * speed_scale_multiplier);
lf.move(lf_t0, lf_t3, lf_x, lf_y, lf_x_end, lf_y_end);
lf.fade(lf_t0, lf_t1, 0, lf_opacity);
if (pops) {
lf.scaleVec(pop_time, pop_time + pop_delay / 3 / 4, lf_size * grow_factor, lf_size * grow_factor * speed_scale_multiplier, lf_size * grow_factor, lf_size * grow_factor);
lf.fade(pop_time, pop_time + pop_delay / 3, lf_opacity, 1);
lf.fade(pop_time + pop_delay / 3, pop_time + pop_delay, 1, 0);
lf.additive(lf_t0, lf_t3 + pop_delay);
} else {
lf.fade(lf_t2, lf_t3, lf_opacity, 0);
lf.additive(lf_t0, lf_t3);
}
}
function make_snowflakes(t0, t1, lf_count, lf_duration, lf_minimal_duration, lf_speed, pop_time) {
for (var i = 0; i < lf_count; i++) {
var lf_t0 = rand(t0, t1 - lf_minimal_duration);
var lf_real_duration = lf_duration * rand(50, 100) / 100.0;
if (pop_time == 0 && lf_t0 + lf_duration > t1) {
lf_real_duration = t1 - lf_t0;
}
make_snowflake(lf_t0, lf_real_duration, lf_speed * rand(80, 120) / 100.0, pop_time);
}
}
function make_snowflakes_every(t0, t1, delta, pop_time) {
var lf_t0 = t0;
while (lf_t0 < t1) {
make_snowflake(lf_t0, delta * 8, 0, pop_time);
lf_t0 = lf_t0 + delta;
}
}
function make_glow_every(t0, t1, delta, max_glow_count) {
var lf_t0 = t0;
while (lf_t0 < t1) {
make_glow(lf_t0, delta * max_glow_count);
lf_t0 = lf_t0 + delta;
}
}
// --- BACKGROUND
var bg_width = 1024;
var widescreen_scale = 1366 / 1024.0;
var bg = new Sprite("bg.jpg", Background, Centre);
bg.scale(640.0 / bg_width * widescreen_scale);
bg.fade(0, time_spinner_end, 0.2, 0.2);
bg.fade(time_spinner_end, time_first_object, 0.2, 1);
bg.fade(time_first_object, time_outro, 1, 1);
bg.fade(time_outro, time_end, 1, 0.6);
bg.color(time_outro, time_end, 255, 255, 255, 221, 231, 255);
bg.fade(time_end, time_true_end, 0.6, 0.2);
bg.fade(time_true_end, time_scorescreen, 0.2, 0);
// --- TITLE
make_title_glow(time_part1_start, time_part1_start + 6000);
make_title_glow(time_part5, time_part6);
// --- SNOWFLAKES
var start_offset = 500;
// slow snowflake part
make_snowflakes(time_part1_start - start_offset, time_part1_end, 50, 10000, 1000, 30, 0);
// + spinner
make_snowflakes(time_spinner_start, time_spinner_end + 200, 400, 200, 100, 0, 0);
// fast snowflake part
make_snowflakes(time_part2, time_part3, 120, 5000, 1000, 100, 0);
// + slowdown
make_snowflakes(time_part2_voice_a, time_part2_voice_b + 400, 200, 500, 400, -140, 0);
// + faster snowflakes
make_snowflakes(time_part2_voice_b, time_part3 + 400, 500, 500, 400, -500, 0);
// denser slow snowflake part
make_snowflakes(time_part3 - start_offset, time_part4_start, 200, 10000, 1000, 30, 0);
// lots of fast snowflake part
make_snowflakes(time_part4_start - start_offset, time_part4_2, 200, 5000, 1000, 140, 0);
make_snowflakes(time_part4_1 - start_offset, time_part4_3, 100, 5000, 1000, -100, 0);
make_snowflakes(time_part4_2 - start_offset, time_part4_4, 100, 2000, 800, -200, 0);
make_snowflakes(time_part4_3 - start_offset, time_part4_end, 100, 700, 0, -350, time_part4_end);
make_snowflakes(time_part4_4 - start_offset, time_part4_end, 200, 500, 0, -500, time_part4_end);
// chorus
make_glow_every(time_chorus_start, time_chorus_end, 1005, 4);
// outro
make_snowflakes_every(time_outro, time_end, (time_end - time_outro) / (6 * 4 * 4), 0);
// end part
make_snowflakes(time_end, time_true_end, 500, 400, 300, 0, 0);
make_snowflakes(time_end, time_scorescreen, 100, 2000, 500, 0, 0);