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"
29 /*---------------------------------------------------------------------------*/
31 static int view_rotate;
33 static int pause_or_exit(void)
35 if (SDL_GetModState() & (KMOD_SHIFT | KMOD_CTRL | KMOD_ALT | KMOD_META))
37 level_stop(GAME_NONE, curr_clock(), curr_coins());
39 return goto_state(&st_start);
45 /*---------------------------------------------------------------------------*/
47 static int play_ready_enter(void)
51 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
57 audio_play(AUD_READY, 1.0f);
63 static void play_ready_timer(int id, float dt)
65 float t = time_state();
67 game_set_fly(1.0f - 0.5f * t);
69 if (dt > 0.0f && t > 1.0f)
70 goto_state(&st_play_set);
77 static int play_ready_click(int b, int d)
79 return (b < 0 && d == 1) ? goto_state(&st_play_loop) : 1;
82 static int play_ready_keybd(int c, int d)
85 if (config_tst_d(CONFIG_KEY_PAUSE, c))
90 static int play_ready_buttn(int b, int d)
94 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
95 return goto_state(&st_play_loop);
96 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
97 return pause_or_exit();
102 /*---------------------------------------------------------------------------*/
104 static int play_set_enter(void)
108 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
110 gui_layout(id, 0, 0);
114 audio_play(AUD_SET, 1.f);
121 static void play_set_timer(int id, float dt)
123 float t = time_state();
125 game_set_fly(0.5f - 0.5f * t);
127 if (dt > 0.0f && t > 1.0f)
128 goto_state(&st_play_loop);
135 static int play_set_click(int b, int d)
140 return goto_state(&st_play_loop);
145 static int play_set_keybd(int c, int d)
148 if (config_tst_d(CONFIG_KEY_PAUSE, c))
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 pause_or_exit();
165 /*---------------------------------------------------------------------------*/
167 static int nohud = 0;
169 static int play_loop_enter(void)
180 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
182 gui_layout(id, 0, 0);
186 audio_play(AUD_GO, 1.f);
191 hud_view_pulse(config_get_d(CONFIG_CAMERA));
200 static void play_loop_paint(int id, float st)
206 if (time_state() < 1.f)
210 #define CAMERA_MODIFIERS (KMOD_SHIFT | KMOD_CTRL | KMOD_ALT | KMOD_META)
212 static void play_loop_timer(int id, float dt)
214 float k = ((SDL_GetModState() & CAMERA_MODIFIERS) ?
215 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.f:
216 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.f);
220 float g[3] = { 0.0f, -9.8f, 0.0f };
224 at = (7 * at + dt) / 8;
228 game_set_rot(view_rotate * k);
230 state = game_step(g, at, 1);
238 level_stop(state, curr_clock(), curr_coins());
239 goto_state(&st_play_end);
243 static void play_loop_point(int id, int x, int y, int dx, int dy)
245 game_set_pos(dx, dy);
248 static void play_loop_stick(int id, int a, int k)
250 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
252 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
256 static int play_loop_click(int b, int d)
258 view_rotate = d ? b : 0;
262 static int play_loop_keybd(int c, int d)
266 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
268 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
271 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
273 config_set_d(CONFIG_CAMERA, 0);
276 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
278 config_set_d(CONFIG_CAMERA, 1);
281 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
283 config_set_d(CONFIG_CAMERA, 2);
286 if (config_tst_d(CONFIG_KEY_RESTART, c) &&
287 curr_lg()->mode != MODE_CHALLENGE)
289 level_stop(GAME_NONE, curr_clock(), curr_coins());
291 goto_state(&st_play_ready);
293 if (config_tst_d(CONFIG_KEY_PAUSE, c))
298 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
300 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
304 if (d && c == SDLK_F12 && config_get_d(CONFIG_CHEAT))
305 return goto_state(&st_look);
307 if (d && c == SDLK_F6)
311 if (d && c == SDLK_c && config_get_d(CONFIG_CHEAT))
313 level_stop(GAME_GOAL, curr_clock(), curr_coins());
314 return goto_state(&st_play_end);
319 static int play_loop_buttn(int b, int d)
323 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
326 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
328 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
331 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
333 config_set_d(CONFIG_CAMERA, 0);
336 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
338 config_set_d(CONFIG_CAMERA, 1);
341 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
343 config_set_d(CONFIG_CAMERA, 2);
349 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
351 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
357 /*---------------------------------------------------------------------------*/
362 static int look_enter(void)
369 static void look_leave(int id)
373 static void look_paint(int id, float st)
378 static void look_point(int id, int x, int y, int dx, int dy)
380 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
381 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
383 if (phi > +90.0f) phi = +90.0f;
384 if (phi < -90.0f) phi = -90.0f;
386 if (theta > +180.0f) theta -= 360.0f;
387 if (theta < -180.0f) theta += 360.0f;
389 game_look(phi, theta);
392 static int look_keybd(int c, int d)
394 if (d && c == SDLK_F12)
395 return goto_state(&st_play_loop);
400 static int look_buttn(int b, int d)
402 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
403 return goto_state(&st_play_loop);
408 /*---------------------------------------------------------------------------*/
410 struct state st_play_ready = {
423 struct state st_play_set = {
436 struct state st_play_loop = {
449 struct state st_look = {