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"
25 #include "st_play_end.h"
28 /*---------------------------------------------------------------------------*/
30 static int view_rotate;
32 /*---------------------------------------------------------------------------*/
34 static int abort_play(void)
36 if (curr_lg()->mode == MODE_SINGLE)
39 return goto_state(&st_over);
42 static int play_ready_enter(void)
46 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
52 audio_play(AUD_READY, 1.0f);
58 static void play_ready_timer(int id, float dt)
60 float t = time_state();
62 game_set_fly(1.0f - 0.5f * t);
64 if (dt > 0.0f && t > 1.0f)
65 goto_state(&st_play_set);
72 static int play_ready_click(int b, int d)
74 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
77 static int play_ready_buttn(int b, int d)
81 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
82 return goto_state(&st_play_loop);
83 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
89 /*---------------------------------------------------------------------------*/
91 static int play_set_enter(void)
95 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
101 audio_play(AUD_SET, 1.f);
106 static void play_set_timer(int id, float dt)
108 float t = time_state();
110 game_set_fly(0.5f - 0.5f * t);
112 if (dt > 0.0f && t > 1.0f)
113 goto_state(&st_play_loop);
119 static int play_set_click(int b, int d)
124 return goto_state(&st_play_loop);
129 static int play_set_buttn(int b, int d)
133 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
134 return goto_state(&st_play_loop);
135 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
141 /*---------------------------------------------------------------------------*/
143 static int nohud = 0;
145 static int play_loop_enter(void)
149 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
151 gui_layout(id, 0, 0);
155 audio_play(AUD_GO, 1.f);
160 hud_view_pulse(config_get_d(CONFIG_CAMERA));
169 static void play_loop_paint(int id, float st)
175 if (time_state() < 1.f)
179 static void play_loop_timer(int id, float dt)
181 float k = (((SDL_GetModState() & KMOD_LSHIFT) ||
182 (SDL_GetModState() & KMOD_RSHIFT)) ?
183 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
184 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
188 float g[3] = { 0.0f, -9.8f, 0.0f };
190 int state, state_value;
192 at = (7 * at + dt) / 8;
196 game_set_rot(view_rotate * k);
198 state = game_step(g, at, &state_value);
201 level_stop(state, state_value, curr_clock(), curr_coins());
202 goto_state(&st_play_end);
210 static void play_loop_point(int id, int x, int y, int dx, int dy)
212 game_set_pos(dx, dy);
215 static void play_loop_stick(int id, int a, int k)
217 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
219 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
223 static int play_loop_click(int b, int d)
225 view_rotate = d ? b : 0;
229 static int play_loop_keybd(int c, int d)
233 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
235 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
238 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
240 config_set_d(CONFIG_CAMERA, 0);
243 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
245 config_set_d(CONFIG_CAMERA, 1);
248 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
250 config_set_d(CONFIG_CAMERA, 2);
256 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
258 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
262 if (d && c == SDLK_F12)
263 return goto_state(&st_look);
265 if (d && c == SDLK_F6)
269 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
271 level_stop(GAME_GOAL, 0, curr_clock(), curr_coins());
272 return goto_state(&st_play_end);
277 static int play_loop_buttn(int b, int d)
281 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
283 level_stop(GAME_NONE, 0, curr_clock(), curr_coins());
287 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
289 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
292 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
294 config_set_d(CONFIG_CAMERA, 0);
297 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
299 config_set_d(CONFIG_CAMERA, 1);
302 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
304 config_set_d(CONFIG_CAMERA, 2);
310 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
312 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
318 /*---------------------------------------------------------------------------*/
323 static int look_enter(void)
330 static void look_leave(int id)
334 static void look_paint(int id, float st)
339 static void look_point(int id, int x, int y, int dx, int dy)
341 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
342 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
344 if (phi > +90.0f) phi = +90.0f;
345 if (phi < -90.0f) phi = -90.0f;
347 if (theta > +180.0f) theta -= 360.0f;
348 if (theta < -180.0f) theta += 360.0f;
350 game_look(phi, theta);
353 static int look_keybd(int c, int d)
355 if (d && c == SDLK_F12)
356 return goto_state(&st_play_loop);
361 static int look_buttn(int b, int d)
363 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
364 return goto_state(&st_play_loop);
369 /*---------------------------------------------------------------------------*/
371 struct state st_play_ready = {
384 struct state st_play_set = {
397 struct state st_play_loop = {
410 struct state st_look = {