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.
22 #include "st_shared.h"
26 #include "st_fall_out.h"
27 #include "st_time_out.h"
31 /*---------------------------------------------------------------------------*/
33 static int view_rotate;
35 static int pause_or_exit(void)
37 if (config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
43 progress_stat(GAME_NONE);
48 return goto_state(&st_over);
52 /*---------------------------------------------------------------------------*/
54 static int play_ready_enter(void)
58 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
64 audio_play(AUD_READY, 1.0f);
70 static void play_ready_timer(int id, float dt)
72 float t = time_state();
74 game_set_fly(1.0f - 0.5f * t);
76 if (dt > 0.0f && t > 1.0f)
77 goto_state(&st_play_set);
83 static int play_ready_click(int b, int d)
85 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
88 static int play_ready_keybd(int c, int d)
91 if (config_tst_d(CONFIG_KEY_PAUSE, c))
96 static int play_ready_buttn(int b, int d)
100 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
101 return goto_state(&st_play_loop);
102 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
103 return pause_or_exit();
108 /*---------------------------------------------------------------------------*/
110 static int play_set_enter(void)
114 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
116 gui_layout(id, 0, 0);
120 audio_play(AUD_SET, 1.f);
127 static void play_set_timer(int id, float dt)
129 float t = time_state();
131 game_set_fly(0.5f - 0.5f * t);
133 if (dt > 0.0f && t > 1.0f)
134 goto_state(&st_play_loop);
140 static int play_set_click(int b, int d)
145 return goto_state(&st_play_loop);
150 static int play_set_keybd(int c, int d)
153 if (config_tst_d(CONFIG_KEY_PAUSE, c))
158 static int play_set_buttn(int b, int d)
162 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
163 return goto_state(&st_play_loop);
164 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
165 return pause_or_exit();
170 /*---------------------------------------------------------------------------*/
174 static int play_loop_enter(void)
185 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
187 gui_layout(id, 0, 0);
191 audio_play(AUD_GO, 1.f);
196 hud_view_pulse(config_get_d(CONFIG_CAMERA));
205 static void play_loop_paint(int id, float t)
212 if (time_state() < 1.f)
216 static void play_loop_timer(int id, float dt)
218 float k = ((SDL_GetModState() & KMOD_SHIFT) ?
219 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.0f :
220 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.0f);
222 float g[3] = { 0.0f, -9.8f, 0.0f };
226 game_set_rot(view_rotate * k);
227 game_set_cam(config_get_d(CONFIG_CAMERA));
232 switch (game_step(g, dt, 1))
235 progress_stat(GAME_GOAL);
237 goto_state(&st_goal);
241 progress_stat(GAME_FALL);
243 goto_state(&st_fall_out);
247 progress_stat(GAME_TIME);
249 goto_state(&st_time_out);
258 static void play_loop_point(int id, int x, int y, int dx, int dy)
260 game_set_pos(dx, dy);
263 static void play_loop_stick(int id, int a, int k)
265 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
267 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
271 static int play_loop_click(int b, int d)
273 view_rotate = d ? b : 0;
277 static int play_loop_keybd(int c, int d)
281 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
283 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
286 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
288 config_set_d(CONFIG_CAMERA, 0);
291 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
293 config_set_d(CONFIG_CAMERA, 1);
296 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
298 config_set_d(CONFIG_CAMERA, 2);
301 if (config_tst_d(CONFIG_KEY_RESTART, c) &&
302 progress_same_avail())
305 goto_state(&st_play_ready);
307 if (config_tst_d(CONFIG_KEY_PAUSE, c))
312 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
314 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
318 if (d && c == SDLK_F12 && config_cheat())
319 return goto_state(&st_look);
321 if (d && c == SDLK_F6)
322 show_hud = !show_hud;
324 if (d && c == SDLK_c && config_cheat())
326 progress_stat(GAME_GOAL);
327 return goto_state(&st_goal);
332 static int play_loop_buttn(int b, int d)
336 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
339 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
341 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
344 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
346 config_set_d(CONFIG_CAMERA, 0);
349 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
351 config_set_d(CONFIG_CAMERA, 1);
354 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
356 config_set_d(CONFIG_CAMERA, 2);
362 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
364 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
370 /*---------------------------------------------------------------------------*/
375 static int look_enter(void)
382 static void look_leave(int id)
386 static void look_paint(int id, float t)
391 static void look_point(int id, int x, int y, int dx, int dy)
393 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
394 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
396 if (phi > +90.0f) phi = +90.0f;
397 if (phi < -90.0f) phi = -90.0f;
399 if (theta > +180.0f) theta -= 360.0f;
400 if (theta < -180.0f) theta += 360.0f;
402 game_look(phi, theta);
405 static int look_keybd(int c, int d)
407 if (d && c == SDLK_F12)
408 return goto_state(&st_play_loop);
413 static int look_buttn(int b, int d)
415 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
416 return goto_state(&st_play_loop);
421 /*---------------------------------------------------------------------------*/
423 struct state st_play_ready = {
437 struct state st_play_set = {
451 struct state st_play_loop = {
465 struct state st_look = {