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 (SDL_GetModState() & KMOD_SHIFT)
39 level_stat(GAME_NONE, curr_clock(), curr_coins());
43 return goto_state(&st_over);
48 /*---------------------------------------------------------------------------*/
50 static int play_ready_enter(void)
54 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
60 audio_play(AUD_READY, 1.0f);
66 static void play_ready_timer(int id, float dt)
68 float t = time_state();
70 game_set_fly(1.0f - 0.5f * t);
72 if (dt > 0.0f && t > 1.0f)
73 goto_state(&st_play_set);
80 static int play_ready_click(int b, int d)
82 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
85 static int play_ready_keybd(int c, int d)
88 if (config_tst_d(CONFIG_KEY_PAUSE, c))
93 static int play_ready_buttn(int b, int d)
97 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
98 return goto_state(&st_play_loop);
99 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
100 return pause_or_exit();
105 /*---------------------------------------------------------------------------*/
107 static int play_set_enter(void)
111 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
113 gui_layout(id, 0, 0);
117 audio_play(AUD_SET, 1.f);
124 static void play_set_timer(int id, float dt)
126 float t = time_state();
128 game_set_fly(0.5f - 0.5f * t);
130 if (dt > 0.0f && t > 1.0f)
131 goto_state(&st_play_loop);
138 static int play_set_click(int b, int d)
143 return goto_state(&st_play_loop);
148 static int play_set_keybd(int c, int d)
151 if (config_tst_d(CONFIG_KEY_PAUSE, c))
156 static int play_set_buttn(int b, int d)
160 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
161 return goto_state(&st_play_loop);
162 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
163 return pause_or_exit();
168 /*---------------------------------------------------------------------------*/
170 static int nohud = 0;
172 static int play_loop_enter(void)
183 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
185 gui_layout(id, 0, 0);
189 audio_play(AUD_GO, 1.f);
194 hud_view_pulse(config_get_d(CONFIG_CAMERA));
203 static void play_loop_paint(int id, float st)
210 if (time_state() < 1.f)
214 static void play_loop_timer(int id, float dt)
216 float k = ((SDL_GetModState() & KMOD_SHIFT) ?
217 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
218 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
222 float g[3] = { 0.0f, -9.8f, 0.0f };
224 at = (7 * at + dt) / 8;
228 game_set_rot(view_rotate * k);
230 switch (game_step(g, at, 1))
233 level_stat(GAME_GOAL, curr_clock(), curr_coins());
235 goto_state(&st_goal);
239 level_stat(GAME_FALL, curr_clock(), curr_coins());
241 goto_state(&st_fall_out);
245 level_stat(GAME_TIME, curr_clock(), curr_coins());
247 goto_state(&st_time_out);
259 static void play_loop_point(int id, int x, int y, int dx, int dy)
261 game_set_pos(dx, dy);
264 static void play_loop_stick(int id, int a, int k)
266 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
268 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
272 static int play_loop_click(int b, int d)
274 view_rotate = d ? b : 0;
278 static int play_loop_keybd(int c, int d)
282 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
284 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
287 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
289 config_set_d(CONFIG_CAMERA, 0);
292 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
294 config_set_d(CONFIG_CAMERA, 1);
297 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
299 config_set_d(CONFIG_CAMERA, 2);
302 if (config_tst_d(CONFIG_KEY_RESTART, c) &&
303 curr_lg()->mode != MODE_CHALLENGE)
306 goto_state(&st_play_ready);
308 if (config_tst_d(CONFIG_KEY_PAUSE, c))
313 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
315 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
319 if (d && c == SDLK_F12 && config_cheat())
320 return goto_state(&st_look);
322 if (d && c == SDLK_F6)
325 if (d && c == SDLK_c && config_cheat())
327 level_stat(GAME_GOAL, curr_clock(), curr_coins());
328 return goto_state(&st_goal);
333 static int play_loop_buttn(int b, int d)
337 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
340 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
342 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
345 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
347 config_set_d(CONFIG_CAMERA, 0);
350 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
352 config_set_d(CONFIG_CAMERA, 1);
355 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
357 config_set_d(CONFIG_CAMERA, 2);
363 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
365 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
371 /*---------------------------------------------------------------------------*/
376 static int look_enter(void)
383 static void look_leave(int id)
387 static void look_paint(int id, float st)
392 static void look_point(int id, int x, int y, int dx, int dy)
394 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
395 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
397 if (phi > +90.0f) phi = +90.0f;
398 if (phi < -90.0f) phi = -90.0f;
400 if (theta > +180.0f) theta -= 360.0f;
401 if (theta < -180.0f) theta += 360.0f;
403 game_look(phi, theta);
406 static int look_keybd(int c, int d)
408 if (d && c == SDLK_F12)
409 return goto_state(&st_play_loop);
414 static int look_buttn(int b, int d)
416 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
417 return goto_state(&st_play_loop);
422 /*---------------------------------------------------------------------------*/
424 struct state st_play_ready = {
437 struct state st_play_set = {
450 struct state st_play_loop = {
463 struct state st_look = {