2 * Copyright (C) 2007 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
23 #include "st_fall_out.h"
28 #include "st_shared.h"
30 /*---------------------------------------------------------------------------*/
32 #define FALL_OUT_NEXT 1
33 #define FALL_OUT_SAME 2
34 #define FALL_OUT_SAVE 3
35 #define FALL_OUT_BACK 4
36 #define FALL_OUT_OVER 5
38 static int be_back_soon;
40 static int fall_out_action(int i)
42 audio_play(AUD_MENU, 1.0f);
51 return goto_state(&st_over);
57 return goto_save(&st_fall_out, &st_fall_out);
61 return goto_state(&st_level);
65 return goto_state(&st_level);
71 static int fall_out_enter(void)
75 const struct level_game *lg = curr_lg();
80 if ((id = gui_vstack(0)))
82 kd = gui_label(id, _("Fall-out!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
86 if ((jd = gui_harray(id)))
88 int next_id = 0, retry_id = 0;
90 next_id = gui_maybe(jd, _("Next Level"), FALL_OUT_NEXT,
91 lg->next_level != NULL);
95 gui_start(jd, _("Game Over"), GUI_SML, FALL_OUT_OVER, 0);
99 retry_id = gui_state(jd, _("Retry Level"), GUI_SML,
103 gui_maybe(jd, _("Save Replay"), FALL_OUT_SAVE, demo_saved());
105 /* Default is next if the next level is newly unlocked. */
107 if (next_id && lg->unlock)
116 gui_layout(id, 0, 0);
119 audio_music_fade_out(2.0f);
120 /* audio_play(AUD_FALL, 1.0f); */
127 static void fall_out_timer(int id, float dt)
129 float g[3] = { 0.0f, -9.8f, 0.0f };
131 if (time_state() < 2.f)
140 static int fall_out_keybd(int c, int d)
144 if (config_tst_d(CONFIG_KEY_RESTART, c) && !curr_lg()->dead)
145 return fall_out_action(FALL_OUT_SAME);
150 static int fall_out_buttn(int b, int d)
154 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
155 return fall_out_action(gui_token(gui_click()));
156 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
157 return fall_out_action(FALL_OUT_BACK);
162 static void fall_out_leave(int id)
164 /* HACK: don't run animation if only "visiting" a state. */
165 st_fall_out.timer = be_back_soon ? shared_timer : fall_out_timer;
170 /*---------------------------------------------------------------------------*/
172 struct state st_fall_out = {