Skip to content

Instantly share code, notes, and snippets.

@VictorJL VictorJL/title.chai
Created Apr 5, 2015

Embed
What would you like to do?
Latest title.chai
var title := stage.create_scene()
var init = fun[title](){
auto window_size := core.video.window.get_size()
auto main_camera := title.create_camera(window_size)
title.set_camera("main_camera", main_camera)
core.mixer.load_music("logo_bgm", core.filesystem.get_file_path("logo_bgm.ogg"))
core.mixer.load_music("title_bgm", core.filesystem.get_file_path("title_bgm.ogg"))
auto sega_logo := title.create_actor()
auto team_logo := title.create_actor()
auto title_logo := title.create_actor()
sega_logo.construct(fun[sega_logo](){
sega_logo.add_model("sega_logo",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"sega_logo.json")
}, fun[sega_logo](){
}, fun[sega_logo](delta){
})
team_logo.construct(fun[team_logo](){
auto window_size := core.video.window.get_size()
auto x_scale = window_size.x / 1920.0f
auto y_scale = window_size.y / 1080.0f
team_logo.add_model("team_logo",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * x_scale, -100.0f * y_scale, 0.0f),
"team_logo.json")
}, fun[team_logo](){
}, fun[team_logo](delta){
})
title_logo.construct(fun[title_logo](){
auto window_size := core.video.window.get_size()
title_logo.add_model("gh_background_1",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background.json");
title_logo.add_model("gh_background_water_1",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background_water.json");
title_logo.add_model("gh_background_2",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background.json");
title_logo.add_model("gh_background_water_2",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background_water.json");
title_logo.add_model("gh_background_3",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background.json");
title_logo.add_model("gh_background_water_3",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"gh_background_water.json");
var a_origin = window_size.x / 2.0f - title_logo.get_model("gh_background_1").get_size().x / 2.0f;
title_logo.get_model("gh_background_1").set_origin(vec3(-a_origin, 0.0f, 0.0f))
title_logo.get_model("gh_background_water_1").set_origin(vec3(-a_origin, 0.0f, 0.0f));
var b_origin = title_logo.get_model("gh_background_1").get_origin().x +
title_logo.get_model("gh_background_1").get_size().x / 2.0f +
title_logo.get_model("gh_background_2").get_size().x / 2.0f
title_logo.get_model("gh_background_2").set_origin(vec3(b_origin, 0.0f, 0.0f))
title_logo.get_model("gh_background_water_2").set_origin(vec3(b_origin, 0.0f, 0.0f))
title_logo.get_model("gh_background_2").change_animation("waterfal_b", true)
var c_origin = title_logo.get_model("gh_background_2").get_origin().x +
title_logo.get_model("gh_background_2").get_size().x / 2.0f +
title_logo.get_model("gh_background_3").get_size().x / 2.0f
title_logo.get_model("gh_background_3").set_origin(vec3(c_origin, 0.0f, 0.0f))
title_logo.get_model("gh_background_water_3").set_origin(vec3(c_origin, 0.0f, 0.0f))
title_logo.get_model("gh_background_3").change_animation("waterfal_c", true)
title_logo.add_model("title_logo_a",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"title_logo_a.json")
title_logo.add_model("title_sonic",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"title_sonic.json")
title_logo.add_model("title_logo_b",
vec3(0.0f, 0.0f, 0.0f),
vec3(-100.0f * 640.0f/320.0f, -100.0f*480.0f/224.0f, 0.0f),
"title_logo_b.json")
}, fun[title_logo](){
}, fun[title_logo](delta){
})
title.add_actor("sega_logo", sega_logo)
title.add_actor("team_logo", team_logo)
title.add_actor("title_logo", title_logo)
title.load_actor("sega_logo")
title.load_actor("team_logo")
title.load_actor("title_logo")
title.get_camera("main_camera").set_position(vec3(0.0f, 0.0f, 0.0f));
core.video.window.set_clear_color(vec4(1.0f, 1.0f, 1.0f, 1.0f))
title.get_actor("sega_logo").set_alpha(0.0f)
title.get_actor("team_logo").set_alpha(0.0f)
title.get_actor("title_logo").set_alpha(0.0f)
title.set_bool("sega_sound_ongoing", false)
title.set_bool("title_sound_ongoing", false)
title.set_float("sega_logo_duration", 8.0f)
title.set_float("team_logo_duration", 4.0f)
title.set_float("time_count", 0.0f)
title.set_int("phase", 0)
}
var deinit = fun[title](){
title.unload_actor("sega_logo")
title.unload_actor("team_logo")
}
var logic = fun[title](delta){
var time := title.get_float("time_count")
time += delta
var phase := title.get_int("phase")
if(phase == 0){
var sega_logo_duration := title.get_float("sega_logo_duration")
var sega_sound_ongoing := title.get_bool("sega_sound_ongoing")
if(time <= sega_logo_duration){
if(time <= 1.0f){
var blending = sin(radians(time / 2.0f * 90.0f));
title.get_actor("sega_logo").set_alpha(blending)
} else if(!sega_sound_ongoing) {
sega_sound_ongoing = true
core.mixer.play_music("logo_bgm", 0)
} else if(time >= 3.0f && time <= 4.0f){
var time_range = 1.0f - (4.0f - time)
var blending = sin(radians((time_range * 90.0f) + 90.0f));
title.get_actor("sega_logo").set_alpha(blending);
core.video.window.set_clear_color(vec4(blending, blending, blending, 1.0f));
}
} else {
time = 0.0f;
++phase
}
} else if(phase == 1){
var team_logo_duration := title.get_float("team_logo_duration")
if(time <= team_logo_duration){
auto blending = sin(radians(time / team_logo_duration * 180.0f))
title.get_actor("team_logo").set_alpha(blending);
} else {
time = 0.0f;
++phase
}
} else {
auto title_logo := title.get_actor("title_logo")
if(time <= 1.0f) {
title_logo.get_model("title_sonic").change_animation("title_sonic_a", true)
title_logo.get_model("title_sonic").set_origin(vec3(-2000.0f, -41.0f, 0.0f))
title_logo.get_model("title_logo_a").set_origin(vec3(0.0f, 0.0f, 0.0f))
title_logo.get_model("title_logo_b").set_origin(vec3(0.0f, 0.0f, 0.0f))
var blending = sin(radians(time * 90.0f))
title_logo.set_alpha(blending)
} else if(time >= 1.0f && time <= 2.0f){
} else if(time >= 2.0f && time <= 2.5f ) {
auto sonic_y = title_logo.get_model("title_sonic").get_origin().y
auto movement_time = 4.05f; //3.0f - (4.0f - time)
auto movement = clamp(sonic_y + movement_time, -41.0f, 82.0f)
title_logo.get_model("title_sonic").set_origin(vec3(0.0f, movement, 0.0f))
} else if(time >= 2.5f && time <= 9.0f) {
if(time - 3.0f < 0.9f){
title_logo.get_model("title_sonic").change_animation("title_sonic_b", true);
} else {
title_logo.get_model("title_sonic").change_animation("title_sonic_c", true);
}
auto sonic_x = title_logo.get_model("title_sonic").get_origin().x + 2.2;
title_logo.get_model("title_logo_a").set_origin(vec3(sonic_x, 0.0f, 0.0f))
title_logo.get_model("title_sonic").set_origin(vec3(sonic_x, 82.0f, 0.0f))
title_logo.get_model("title_logo_b").set_origin(vec3(sonic_x, 0.0f, 0.0f))
} else if(time >= 9.0f && time <= 10.0f){
title_logo.get_model("title_sonic").change_animation("title_sonic_d", true)
auto time_range = 2.0f - (10.0f - time)
auto blending = sin(radians((time / 2 * 90.0f) + 90.0f))
title_logo.set_alpha(blending)
core.video.window.set_clear_color(vec4(blending, blending, blending, 1.0f))
} else if(time >= 10.0f && time <= 12.0f){
} else{
title.get_actor("sega_logo").set_alpha(0.0f)
title.get_actor("team_logo").set_alpha(0.0f)
title.get_actor("title_logo").set_alpha(0.0f)
title.set_bool("sega_sound_ongoing", false)
title.set_bool("title_sound_ongoing", false)
title.set_float("sega_logo_duration", 8.0f)
title.set_float("team_logo_duration", 8.0f)
title.set_float("time_count", 0.0f)
title.set_int("phase", 0)
}
var title_sound_ongoing := title.get_bool("title_sound_ongoing")
if(!title_sound_ongoing && time >= 1.0f) {
title_sound_ongoing = true;
core.mixer.play_music("title_bgm", 0);
}
if(time >= 3.0f){
auto sonic_x = title_logo.get_model("title_sonic").get_origin().x
title.get_camera("main_camera").set_position(vec3(sonic_x, 0.0f, 0.0f))
}
}
}
title.construct(init, deinit, logic)
stage.add_scene("title", title)
stage.load_scene("title")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.