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.
28 /*---------------------------------------------------------------------------*/
30 static int view_rotate;
32 /*---------------------------------------------------------------------------*/
34 static int play_ready_enter(void)
38 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
44 audio_play(AUD_READY, 1.0f);
50 static void play_ready_leave(int id)
55 static void play_ready_paint(int id, float st)
61 static void play_ready_timer(int id, float dt)
63 float t = time_state();
65 game_set_fly(1.0f - 0.5f * t);
67 if (dt > 0.0f && t > 1.0f)
68 goto_state(&st_play_set);
75 static int play_ready_click(int b, int d)
77 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
80 static int play_ready_keybd(int c, int d)
82 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
85 static int play_ready_buttn(int b, int d)
89 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
90 return goto_state(&st_play_loop);
91 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
92 return goto_state(&st_over);
97 /*---------------------------------------------------------------------------*/
99 static int play_set_enter(void)
103 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
105 gui_layout(id, 0, 0);
109 audio_play(AUD_SET, 1.f);
114 static void play_set_leave(int id)
119 static void play_set_paint(int id, float st)
125 static void play_set_timer(int id, float dt)
127 float t = time_state();
129 game_set_fly(0.5f - 0.5f * t);
131 if (dt > 0.0f && t > 1.0f)
132 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)
150 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
153 static int play_set_buttn(int b, int d)
157 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
158 return goto_state(&st_play_loop);
159 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
160 return goto_state(&st_over);
165 /*---------------------------------------------------------------------------*/
167 static int play_loop_enter(void)
171 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
173 gui_layout(id, 0, 0);
177 audio_play(AUD_GO, 1.f);
185 static void play_loop_leave(int id)
190 static void play_loop_paint(int id, float st)
195 if (time_state() < 1.f)
199 static void play_loop_timer(int id, float dt)
201 float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
202 (SDL_GetModState() & KMOD_RSHIFT)) ?
203 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
204 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
208 float g[3] = { 0.0f, -9.8f, 0.0f };
210 at = (7 * at + dt) / 8;
214 game_set_rot(view_rotate * k);
216 switch (game_step(g, at, 1))
218 case GAME_TIME: level_stop(GAME_TIME); goto_state(&st_time_out); break;
219 case GAME_FALL: level_stop(GAME_FALL); goto_state(&st_fall_out); break;
220 case GAME_GOAL: level_stop(GAME_GOAL); goto_state(&st_goal); break;
228 static void play_loop_point(int id, int x, int y, int dx, int dy)
230 game_set_pos(dx, dy);
233 static void play_loop_stick(int id, int a, int k)
235 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
237 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
241 static int play_loop_click(int b, int d)
243 view_rotate = d ? b : 0;
247 static int play_loop_keybd(int c, int d)
251 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
253 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
256 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
258 config_set_d(CONFIG_CAMERA, 0);
261 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
263 config_set_d(CONFIG_CAMERA, 1);
266 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
268 config_set_d(CONFIG_CAMERA, 2);
274 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
276 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
280 if (d && c == SDLK_ESCAPE)
282 level_stop(GAME_NONE);
283 goto_state(&st_over);
285 if (d && c == SDLK_F12)
286 goto_state(&st_look);
289 if (d && c == SDLK_c)
291 level_stop(GAME_GOAL);
292 goto_state(&st_goal);
297 static int play_loop_buttn(int b, int d)
301 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
302 return goto_state(&st_over);
304 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
306 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
309 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
311 config_set_d(CONFIG_CAMERA, 0);
314 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
316 config_set_d(CONFIG_CAMERA, 1);
319 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
321 config_set_d(CONFIG_CAMERA, 2);
327 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
329 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
335 /*---------------------------------------------------------------------------*/
340 static int look_enter(void)
347 static void look_leave(int id)
351 static void look_paint(int id, float st)
356 static void look_point(int id, int x, int y, int dx, int dy)
358 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
359 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
361 if (phi > +90.0f) phi = +90.0f;
362 if (phi < -90.0f) phi = -90.0f;
364 if (theta > +180.0f) theta -= 360.0f;
365 if (theta < -180.0f) theta += 360.0f;
367 game_look(phi, theta);
370 static int look_keybd(int c, int d)
372 if (d && c == SDLK_ESCAPE) goto_state(&st_play_loop);
373 if (d && c == SDLK_F12) goto_state(&st_play_loop);
378 /*---------------------------------------------------------------------------*/
380 struct state st_play_ready = {
393 struct state st_play_set = {
406 struct state st_play_loop = {
419 struct state st_look = {