X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=ball%2Fst_title.c;h=cb581b25d3f517ebe00cf64b940945c59c75a70e;hb=1745b6a90dfd9e626e5c40d20c6aa595ec41d888;hp=f8913036662568135eafa4b2cc6c3f69bc4b3883;hpb=96c448fe3b4f1837f19a50ce48a81afe9ab7baf0;p=neverball diff --git a/ball/st_title.c b/ball/st_title.c index f891303..cb581b2 100644 --- a/ball/st_title.c +++ b/ball/st_title.c @@ -12,6 +12,8 @@ * General Public License for more details. */ +#include + #include "gui.h" #include "vec3.h" #include "demo.h" @@ -30,9 +32,10 @@ /*---------------------------------------------------------------------------*/ static float real_time = 0.0f; -static float demo_time = 0.0f; static int mode = 0; +static int play_id = 0; + #define TITLE_PLAY 1 #define TITLE_HELP 2 #define TITLE_DEMO 3 @@ -41,7 +44,13 @@ static int mode = 0; static int title_action(int i) { + static const char keyphrase[] = "CHEAT"; + static char queue[sizeof (keyphrase)] = ""; + + size_t queue_len = strlen(queue); + char player[MAXNAM]; + audio_play(AUD_MENU, 1.0f); switch (i) @@ -50,7 +59,7 @@ static int title_action(int i) config_get_s(CONFIG_PLAYER, player, MAXNAM); if (strlen(player) == 0) - return goto_name(&st_set, &st_title); + return goto_name(&st_set, &st_title, 0); else return goto_state(&st_set); @@ -60,12 +69,47 @@ static int title_action(int i) case TITLE_DEMO: return goto_state(&st_demo); break; case TITLE_CONF: return goto_state(&st_conf); break; case TITLE_EXIT: return 0; break; + + default: + + /* Let the queue fill up. */ + + if (queue_len < sizeof (queue) - 1) + { + queue[queue_len] = (char) i; + queue[queue_len + 1] = '\0'; + } + + /* Advance the queue before adding the new element. */ + + else + { + int k; + + for (k = 1; k < queue_len; k++) + queue[k - 1] = queue[k]; + + queue[queue_len - 1] = (char) i; + } + + if (strcmp(queue, keyphrase) == 0) + { + config_set_cheat(); + gui_set_label(play_id, sgettext("menu^Cheat")); + gui_pulse(play_id, 1.2f); + } + else if (config_cheat()) + { + config_clr_cheat(); + gui_set_label(play_id, sgettext("menu^Play")); + gui_pulse(play_id, 1.2f); + } + + break; } return 1; } -static struct level title_level; - static int title_enter(void) { int id, jd, kd; @@ -75,6 +119,7 @@ static int title_enter(void) if ((id = gui_vstack(0))) { gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0); + gui_space(id); if ((jd = gui_harray(id))) @@ -83,7 +128,13 @@ static int title_enter(void) if ((kd = gui_varray(jd))) { - gui_start(kd, sgettext("menu^Play"), GUI_MED, TITLE_PLAY, 1); + if (config_cheat()) + play_id = gui_start(kd, sgettext("menu^Cheat"), + GUI_MED, TITLE_PLAY, 1); + else + play_id = gui_start(kd, sgettext("menu^Play"), + GUI_MED, TITLE_PLAY, 1); + gui_state(kd, sgettext("menu^Replay"), GUI_MED, TITLE_DEMO, 0); gui_state(kd, sgettext("menu^Help"), GUI_MED, TITLE_HELP, 0); gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0); @@ -100,18 +151,20 @@ static int title_enter(void) audio_music_fade_to(0.5f, "bgm/title.ogg"); /* Initialize the title level for display. */ - level_load("map-medium/title.sol", &title_level); - game_init(&title_level, 0, 0); + + game_init("map-medium/title.sol", 0, 1); real_time = 0.0f; - demo_time = 0.0f; mode = 0; + SDL_EnableUNICODE(1); + return id; } static void title_leave(int id) { + SDL_EnableUNICODE(0); demo_replay_stop(0); gui_delete(id); } @@ -119,7 +172,6 @@ static void title_leave(int id) static void title_timer(int id, float dt) { static const char *demo = NULL; - float t; real_time += dt; @@ -143,8 +195,8 @@ static void title_timer(int id, float dt) { if ((demo = demo_pick())) { - demo_replay_init(demo, NULL); - demo_time = 0.0f; + demo_replay_init(demo, NULL, NULL, NULL, NULL, NULL); + game_set_fly(0.0f); real_time = 0.0f; mode = 2; } @@ -159,23 +211,21 @@ static void title_timer(int id, float dt) case 2: /* Mode 2: Run demo. */ - while (demo_time < real_time) - if (demo_replay_step(&t)) - demo_time += t; - else - { - demo_replay_stop(0); - game_fade(+1.0f); - real_time = 0.0f; - mode = 3; - } + if (!demo_replay_step(dt)) + { + demo_replay_stop(0); + game_fade(+1.0f); + real_time = 0.0f; + mode = 3; + } break; case 3: /* Mode 3: Fade out. Load title level. */ if (real_time > 1.0f) { - game_init(&title_level, 0, 0); + game_init("map-medium/title.sol", 0, 1); + real_time = 0.0f; mode = 0; } @@ -183,14 +233,13 @@ static void title_timer(int id, float dt) } gui_timer(id, dt); - audio_timer(dt); game_step_fade(dt); } static int title_keybd(int c, int d) { - if (d && c == SDLK_c && ALLOW_CHEAT) - config_tgl_d(CONFIG_CHEAT); + if (d && (c & 0xFF80) == 0 && c > ' ') + return title_action(c); return 1; } @@ -215,6 +264,7 @@ struct state st_title = { title_timer, shared_point, shared_stick, + shared_angle, shared_click, title_keybd, title_buttn,