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"
29 /*---------------------------------------------------------------------------*/
31 static int view_rotate;
33 /*---------------------------------------------------------------------------*/
35 static int abort_play(void)
37 if (curr_lg()->mode == MODE_SINGLE)
40 return goto_state(&st_over);
43 static int play_ready_enter(void)
47 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
53 audio_play(AUD_READY, 1.0f);
59 static void play_ready_timer(int id, float dt)
61 float t = time_state();
63 game_set_fly(1.0f - 0.5f * t);
65 if (dt > 0.0f && t > 1.0f)
66 goto_state(&st_play_set);
73 static int play_ready_click(int b, int d)
75 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
78 static int play_ready_buttn(int b, int d)
82 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
83 return goto_state(&st_play_loop);
84 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
90 /*---------------------------------------------------------------------------*/
92 static int play_set_enter(void)
96 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
102 audio_play(AUD_SET, 1.f);
107 static void play_set_timer(int id, float dt)
109 float t = time_state();
111 game_set_fly(0.5f - 0.5f * t);
113 if (dt > 0.0f && t > 1.0f)
114 goto_state(&st_play_loop);
120 static int play_set_click(int b, int d)
125 return goto_state(&st_play_loop);
130 static int play_set_buttn(int b, int d)
134 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
135 return goto_state(&st_play_loop);
136 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
142 /*---------------------------------------------------------------------------*/
144 static int play_loop_enter(void)
148 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
150 gui_layout(id, 0, 0);
154 audio_play(AUD_GO, 1.f);
164 static void play_loop_paint(int id, float st)
169 if (time_state() < 1.f)
173 static void play_loop_timer(int id, float dt)
175 float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
176 (SDL_GetModState() & KMOD_RSHIFT)) ?
177 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
178 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
182 float g[3] = { 0.0f, -9.8f, 0.0f };
184 int state, state_value;
186 at = (7 * at + dt) / 8;
190 game_set_rot(view_rotate * k);
192 state = game_step(g, at, &state_value);
195 level_stop(state, state_value, curr_clock(), curr_coins());
196 goto_state(&st_goal);
199 case GAME_TIME: goto_state(&st_time_out); break;
200 case GAME_FALL: goto_state(&st_fall_out); break;
202 case GAME_GOAL: goto_state(&st_goal); break;
211 static void play_loop_point(int id, int x, int y, int dx, int dy)
213 game_set_pos(dx, dy);
216 static void play_loop_stick(int id, int a, int k)
218 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
220 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
224 static int play_loop_click(int b, int d)
226 view_rotate = d ? b : 0;
230 static int play_loop_keybd(int c, int d)
234 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
236 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
239 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
241 config_set_d(CONFIG_CAMERA, 0);
244 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
246 config_set_d(CONFIG_CAMERA, 1);
249 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
251 config_set_d(CONFIG_CAMERA, 2);
257 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
259 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
263 if (d && c == SDLK_F12)
264 return goto_state(&st_look);
267 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
269 level_stop(GAME_GOAL, 0, curr_clock(), curr_coins());
270 return goto_state(&st_goal);
275 static int play_loop_buttn(int b, int d)
279 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
281 level_stop(GAME_NONE, 0, curr_clock(), curr_coins());
285 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
287 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
290 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
292 config_set_d(CONFIG_CAMERA, 0);
295 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
297 config_set_d(CONFIG_CAMERA, 1);
300 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
302 config_set_d(CONFIG_CAMERA, 2);
308 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
310 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
316 /*---------------------------------------------------------------------------*/
321 static int look_enter(void)
328 static void look_leave(int id)
332 static void look_paint(int id, float st)
337 static void look_point(int id, int x, int y, int dx, int dy)
339 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
340 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
342 if (phi > +90.0f) phi = +90.0f;
343 if (phi < -90.0f) phi = -90.0f;
345 if (theta > +180.0f) theta -= 360.0f;
346 if (theta < -180.0f) theta += 360.0f;
348 game_look(phi, theta);
351 static int look_keybd(int c, int d)
353 if (d && c == SDLK_F12)
354 return goto_state(&st_play_loop);
359 static int look_buttn(int b, int d)
361 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
362 return goto_state(&st_play_loop);
367 /*---------------------------------------------------------------------------*/
369 struct state st_play_ready = {
382 struct state st_play_set = {
395 struct state st_play_loop = {
408 struct state st_look = {