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);
177 static void play_loop_leave(int id)
182 static void play_loop_paint(int id, float st)
187 if (time_state() < 1.f)
191 static void play_loop_timer(int id, float dt)
193 float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
194 (SDL_GetModState() & KMOD_RSHIFT)) ?
195 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
196 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
200 float g[3] = { 0.0f, -9.8f, 0.0f };
202 at = (7 * at + dt) / 8;
206 game_set_rot(view_rotate * k);
208 switch (game_step(g, at, 1))
210 case GAME_TIME: level_stop(GAME_TIME); goto_state(&st_time_out); break;
211 case GAME_FALL: level_stop(GAME_FALL); goto_state(&st_fall_out); break;
212 case GAME_GOAL: level_stop(GAME_GOAL); goto_state(&st_goal); break;
220 static void play_loop_point(int id, int x, int y, int dx, int dy)
222 game_set_pos(dx, dy);
225 static void play_loop_stick(int id, int a, int k)
227 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
229 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
233 static int play_loop_click(int b, int d)
235 view_rotate = d ? b : 0;
239 static int play_loop_keybd(int c, int d)
243 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
245 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
248 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
250 config_set_d(CONFIG_CAMERA, 0);
253 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
255 config_set_d(CONFIG_CAMERA, 1);
258 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
260 config_set_d(CONFIG_CAMERA, 2);
266 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
268 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
272 if (d && c == SDLK_F12)
273 return goto_state(&st_look);
276 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
278 level_stop(GAME_GOAL);
279 return goto_state(&st_goal);
284 static int play_loop_buttn(int b, int d)
288 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
290 level_stop(GAME_NONE);
291 return goto_state(&st_over);
294 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
296 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
299 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
301 config_set_d(CONFIG_CAMERA, 0);
304 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
306 config_set_d(CONFIG_CAMERA, 1);
309 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
311 config_set_d(CONFIG_CAMERA, 2);
317 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
319 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
325 /*---------------------------------------------------------------------------*/
330 static int look_enter(void)
337 static void look_leave(int id)
341 static void look_paint(int id, float st)
346 static void look_point(int id, int x, int y, int dx, int dy)
348 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
349 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
351 if (phi > +90.0f) phi = +90.0f;
352 if (phi < -90.0f) phi = -90.0f;
354 if (theta > +180.0f) theta -= 360.0f;
355 if (theta < -180.0f) theta += 360.0f;
357 game_look(phi, theta);
360 static int look_keybd(int c, int d)
362 if (d && c == SDLK_F12)
363 return goto_state(&st_play_loop);
368 static int look_buttn(int b, int d)
370 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
371 return goto_state(&st_play_loop);
376 /*---------------------------------------------------------------------------*/
378 struct state st_play_ready = {
391 struct state st_play_set = {
404 struct state st_play_loop = {
417 struct state st_look = {