Import from neverball-1.4.0.tar.gz
[neverball-archive.git] / ball / st_fail.c
blob1281f1f88e62e7539ea708ec0198c2943c81b83d
1 /*
2 * Copyright (C) 2003 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.
15 #include "gui.h"
16 #include "game.h"
17 #include "demo.h"
18 #include "level.h"
19 #include "audio.h"
20 #include "config.h"
22 #include "st_fail.h"
23 #include "st_over.h"
24 #include "st_save.h"
25 #include "st_level.h"
27 /*---------------------------------------------------------------------------*/
29 #define FAIL_RETRY 0
30 #define FAIL_SAVE 1
32 static int fail_action(int i)
34 switch (i)
36 case FAIL_RETRY:
37 if (level_exit(NULL, 0))
38 return goto_state(&st_level);
39 else
40 return goto_state(&st_over);
42 case FAIL_SAVE:
43 return goto_state(&st_save);
45 return 1;
48 static int fall_out_enter(void)
50 int id, jd, kd;
52 if ((id = gui_vstack(0)))
54 kd = gui_label(id, "Fall-out!", GUI_LRG, GUI_ALL, gui_gry, gui_red);
56 if ((jd = gui_harray(id)))
58 gui_state(jd, "Save Replay", GUI_SML, FAIL_SAVE, 0);
60 if (level_dead())
61 gui_start(jd, "Main Menu", GUI_SML, FAIL_RETRY, 0);
62 else
63 gui_start(jd, "Retry Level", GUI_SML, FAIL_RETRY, 0);
66 gui_pulse(kd, 1.2f);
67 gui_layout(id, 0, 0);
70 audio_music_fade_out(2.0f);
71 audio_play(AUD_FALL, 1.0f);
73 config_clr_grab();
75 return id;
78 static void fall_out_leave(int id)
80 gui_delete(id);
83 static void fall_out_paint(int id, float st)
85 game_draw(0, st);
86 gui_paint(id);
89 static void fall_out_point(int id, int x, int y, int dx, int dy)
91 gui_pulse(gui_point(id, x, y), 1.2f);
94 static void fall_out_stick(int id, int a, int v)
96 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
97 gui_pulse(gui_stick(id, v, 0), 1.2f);
98 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
99 gui_pulse(gui_stick(id, 0, v), 1.2f);
102 static int fall_out_click(int b, int d)
104 if (b <= 0 && d == 1)
105 return fail_action(gui_token(gui_click()));
106 return 1;
109 static void fall_out_timer(int id, float dt)
111 float g[3] = { 0.0f, -9.8f, 0.0f };
113 if (time_state() < 2.f)
115 game_step(g, dt, 0);
116 demo_play_step(dt);
119 gui_timer(id, dt);
120 audio_timer(dt);
123 static int fall_out_keybd(int c, int d)
125 if (d && c == SDLK_ESCAPE)
126 goto_state(&st_over);
127 return 1;
130 static int fall_out_buttn(int b, int d)
132 if (d)
134 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
135 return fall_out_click(0, 1);
136 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
137 return goto_state(&st_over);
139 return 1;
142 /*---------------------------------------------------------------------------*/
144 static int time_out_enter(void)
146 int id, jd, kd;
148 if ((id = gui_vstack(0)))
150 kd = gui_label(id, "Time's Up!", GUI_LRG, GUI_ALL, gui_gry, gui_red);
152 if ((jd = gui_harray(id)))
154 gui_state(jd, "Save Replay", GUI_SML, FAIL_SAVE, 0);
156 if (level_dead())
157 gui_start(jd, "Main Menu", GUI_SML, FAIL_RETRY, 0);
158 else
159 gui_start(jd, "Retry Level", GUI_SML, FAIL_RETRY, 0);
162 gui_pulse(kd, 1.2f);
163 gui_layout(id, 0, 0);
166 audio_music_fade_out(2.0f);
167 audio_play(AUD_TIME, 1.0f);
169 config_clr_grab();
171 return id;
174 static void time_out_leave(int id)
176 gui_delete(id);
179 static void time_out_paint(int id, float st)
181 game_draw(0, st);
182 gui_paint(id);
185 static void time_out_point(int id, int x, int y, int dx, int dy)
187 gui_pulse(gui_point(id, x, y), 1.2f);
190 static void time_out_stick(int id, int a, int v)
192 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
193 gui_pulse(gui_stick(id, v, 0), 1.2f);
194 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
195 gui_pulse(gui_stick(id, 0, v), 1.2f);
198 static int time_out_click(int b, int d)
200 if (b <= 0 && d == 1)
201 return fail_action(gui_token(gui_click()));
202 return 1;
205 static void time_out_timer(int id, float dt)
207 gui_timer(id, dt);
208 audio_timer(dt);
211 static int time_out_keybd(int c, int d)
213 if (d && c == SDLK_ESCAPE)
214 goto_state(&st_over);
215 return 1;
218 static int time_out_buttn(int b, int d)
220 if (d)
222 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
223 return time_out_click(0, 1);
224 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
225 return goto_state(&st_over);
227 return 1;
230 /*---------------------------------------------------------------------------*/
232 struct state st_fall_out = {
233 fall_out_enter,
234 fall_out_leave,
235 fall_out_paint,
236 fall_out_timer,
237 fall_out_point,
238 fall_out_stick,
239 fall_out_click,
240 fall_out_keybd,
241 fall_out_buttn,
242 1, 0
245 struct state st_time_out = {
246 time_out_enter,
247 time_out_leave,
248 time_out_paint,
249 time_out_timer,
250 time_out_point,
251 time_out_stick,
252 time_out_click,
253 time_out_keybd,
254 time_out_buttn,
255 1, 0