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_buttn(int b, int d)
84 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
85 return goto_state(&st_play_loop);
86 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
87 return goto_state(&st_over);
92 /*---------------------------------------------------------------------------*/
94 static int play_set_enter(void)
98 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
100 gui_layout(id, 0, 0);
104 audio_play(AUD_SET, 1.f);
109 static void play_set_leave(int id)
114 static void play_set_paint(int id, float st)
120 static void play_set_timer(int id, float dt)
122 float t = time_state();
124 game_set_fly(0.5f - 0.5f * t);
126 if (dt > 0.0f && t > 1.0f)
127 goto_state(&st_play_loop);
133 static int play_set_click(int b, int d)
138 return goto_state(&st_play_loop);
143 static int play_set_buttn(int b, int d)
147 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
148 return goto_state(&st_play_loop);
149 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
150 return goto_state(&st_over);
155 /*---------------------------------------------------------------------------*/
157 static int play_loop_enter(void)
161 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
163 gui_layout(id, 0, 0);
167 audio_play(AUD_GO, 1.f);
175 static void play_loop_leave(int id)
180 static void play_loop_paint(int id, float st)
185 if (time_state() < 1.f)
189 static void play_loop_timer(int id, float dt)
191 float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
192 (SDL_GetModState() & KMOD_RSHIFT)) ?
193 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
194 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
198 float g[3] = { 0.0f, -9.8f, 0.0f };
200 at = (7 * at + dt) / 8;
204 game_set_rot(view_rotate * k);
206 switch (game_step(g, at, 1))
208 case GAME_TIME: level_stop(GAME_TIME); goto_state(&st_time_out); break;
209 case GAME_FALL: level_stop(GAME_FALL); goto_state(&st_fall_out); break;
210 case GAME_GOAL: level_stop(GAME_GOAL); goto_state(&st_goal); break;
218 static void play_loop_point(int id, int x, int y, int dx, int dy)
220 game_set_pos(dx, dy);
223 static void play_loop_stick(int id, int a, int k)
225 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
227 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
231 static int play_loop_click(int b, int d)
233 view_rotate = d ? b : 0;
237 static int play_loop_keybd(int c, int d)
241 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
243 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
246 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
248 config_set_d(CONFIG_CAMERA, 0);
251 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
253 config_set_d(CONFIG_CAMERA, 1);
256 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
258 config_set_d(CONFIG_CAMERA, 2);
264 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
266 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
270 if (d && c == SDLK_F12)
271 return goto_state(&st_look);
274 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
276 level_stop(GAME_GOAL);
277 return goto_state(&st_goal);
282 static int play_loop_buttn(int b, int d)
286 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
288 level_stop(GAME_NONE);
289 return goto_state(&st_over);
292 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
294 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
297 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
299 config_set_d(CONFIG_CAMERA, 0);
302 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
304 config_set_d(CONFIG_CAMERA, 1);
307 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
309 config_set_d(CONFIG_CAMERA, 2);
315 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
317 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
323 /*---------------------------------------------------------------------------*/
328 static int look_enter(void)
335 static void look_leave(int id)
339 static void look_paint(int id, float st)
344 static void look_point(int id, int x, int y, int dx, int dy)
346 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
347 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
349 if (phi > +90.0f) phi = +90.0f;
350 if (phi < -90.0f) phi = -90.0f;
352 if (theta > +180.0f) theta -= 360.0f;
353 if (theta < -180.0f) theta += 360.0f;
355 game_look(phi, theta);
358 static int look_keybd(int c, int d)
360 if (d && c == SDLK_F12)
361 return goto_state(&st_play_loop);
366 static int look_buttn(int b, int d)
368 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
369 return goto_state(&st_play_loop);
374 /*---------------------------------------------------------------------------*/
376 struct state st_play_ready = {
389 struct state st_play_set = {
402 struct state st_play_loop = {
415 struct state st_look = {