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"
24 #include "game_common.h"
25 #include "game_server.h"
26 #include "game_client.h"
30 #include "st_fall_out.h"
31 #include "st_time_out.h"
35 /*---------------------------------------------------------------------------*/
37 static float view_rotate;
38 static int fast_rotate;
40 static int pause_or_exit(void)
42 if (config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
48 progress_stat(GAME_NONE);
53 return goto_state(&st_over);
57 /*---------------------------------------------------------------------------*/
59 static int play_ready_enter(void)
63 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
69 audio_play(AUD_READY, 1.0f);
75 static void play_ready_timer(int id, float dt)
77 float t = time_state();
79 game_set_fly(1.0f - 0.5f * t, NULL);
80 game_client_step(NULL);
82 if (dt > 0.0f && t > 1.0f)
83 goto_state(&st_play_set);
89 static int play_ready_click(int b, int d)
91 return (b == SDL_BUTTON_LEFT && d == 1) ? goto_state(&st_play_loop) : 1;
94 static int play_ready_keybd(int c, int d)
97 if (config_tst_d(CONFIG_KEY_PAUSE, c))
102 static int play_ready_buttn(int b, int d)
106 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
107 return goto_state(&st_play_loop);
108 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
109 return pause_or_exit();
114 /*---------------------------------------------------------------------------*/
116 static int play_set_enter(void)
120 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
122 gui_layout(id, 0, 0);
126 audio_play(AUD_SET, 1.f);
133 static void play_set_timer(int id, float dt)
135 float t = time_state();
137 game_set_fly(0.5f - 0.5f * t, NULL);
138 game_client_step(NULL);
140 if (dt > 0.0f && t > 1.0f)
141 goto_state(&st_play_loop);
147 static int play_set_click(int b, int d)
149 if (b == SDL_BUTTON_LEFT && d == 1)
151 game_set_fly(0.0f, NULL);
152 game_client_step(NULL);
153 return goto_state(&st_play_loop);
158 static int play_set_keybd(int c, int d)
161 if (config_tst_d(CONFIG_KEY_PAUSE, c))
166 static int play_set_buttn(int b, int d)
170 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
171 return goto_state(&st_play_loop);
172 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
173 return pause_or_exit();
178 /*---------------------------------------------------------------------------*/
182 static int play_loop_enter(void)
194 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
196 gui_layout(id, 0, 0);
200 audio_play(AUD_GO, 1.f);
202 game_set_fly(0.f, NULL);
203 game_client_step(NULL);
208 hud_view_pulse(config_get_d(CONFIG_CAMERA));
217 static void play_loop_paint(int id, float t)
224 if (time_state() < 1.f)
228 static void play_loop_timer(int id, float dt)
230 float k = (fast_rotate ?
231 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.0f :
232 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.0f);
236 game_set_rot(view_rotate * k);
237 game_set_cam(config_get_d(CONFIG_CAMERA));
241 game_server_step(dt);
242 game_client_step(demo_file());
244 switch (curr_status())
247 progress_stat(GAME_GOAL);
249 goto_state(&st_goal);
253 progress_stat(GAME_FALL);
255 goto_state(&st_fall_out);
259 progress_stat(GAME_TIME);
261 goto_state(&st_time_out);
270 static void play_loop_point(int id, int x, int y, int dx, int dy)
272 game_set_pos(dx, dy);
275 static void play_loop_stick(int id, int a, int k)
277 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
279 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
281 if (config_tst_d(CONFIG_JOYSTICK_AXIS_U, a))
282 view_rotate = (float) -k / 32768.0f;
285 static int play_loop_click(int b, int d)
289 if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
291 if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
294 if (config_tst_d(CONFIG_MOUSE_CAMERA_1, b))
296 config_set_d(CONFIG_CAMERA, 0);
299 if (config_tst_d(CONFIG_MOUSE_CAMERA_2, b))
301 config_set_d(CONFIG_CAMERA, 1);
304 if (config_tst_d(CONFIG_MOUSE_CAMERA_3, b))
306 config_set_d(CONFIG_CAMERA, 2);
310 if (config_tst_d(CONFIG_MOUSE_CAMERA_TOGGLE, b))
311 return st_buttn(config_get_d(CONFIG_JOYSTICK_CAMERA_TOGGLE), 1);
315 if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
317 if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
324 static int play_loop_keybd(int c, int d)
328 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
330 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
332 if (config_tst_d(CONFIG_KEY_ROTATE_FAST, c))
335 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
337 config_set_d(CONFIG_CAMERA, 0);
340 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
342 config_set_d(CONFIG_CAMERA, 1);
345 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
347 config_set_d(CONFIG_CAMERA, 2);
350 if (c == SDLK_F4 && config_cheat())
352 config_set_d(CONFIG_CAMERA, 3);
355 if (config_tst_d(CONFIG_KEY_RESTART, c) &&
356 progress_same_avail())
359 goto_state(&st_play_ready);
361 if (config_tst_d(CONFIG_KEY_CAMERA_TOGGLE, c))
363 int m = config_tst_d(CONFIG_CAMERA, 2) ? 0 : 2;
364 config_set_d(CONFIG_CAMERA, m);
367 if (config_tst_d(CONFIG_KEY_PAUSE, c))
372 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
374 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
376 if (config_tst_d(CONFIG_KEY_ROTATE_FAST, c))
380 if (d && c == SDLK_F12 && config_cheat())
381 return goto_state(&st_look);
383 if (d && c == SDLK_F6)
384 show_hud = !show_hud;
386 if (d && c == SDLK_c && config_cheat())
388 progress_stat(GAME_GOAL);
389 return goto_state(&st_goal);
394 static int play_loop_buttn(int b, int d)
398 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
401 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
403 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
405 if (config_tst_d(CONFIG_JOYSTICK_ROTATE_FAST, b))
408 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
410 config_set_d(CONFIG_CAMERA, 0);
413 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
415 config_set_d(CONFIG_CAMERA, 1);
418 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
420 config_set_d(CONFIG_CAMERA, 2);
423 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_TOGGLE, b))
425 int m = config_tst_d(CONFIG_CAMERA, 2) ? 0 : 2;
426 config_set_d(CONFIG_CAMERA, m);
432 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
434 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
436 if (config_tst_d(CONFIG_JOYSTICK_ROTATE_FAST, b))
442 /*---------------------------------------------------------------------------*/
447 static int look_enter(void)
454 static void look_leave(int id)
458 static void look_paint(int id, float t)
463 static void look_point(int id, int x, int y, int dx, int dy)
465 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
466 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
468 if (phi > +90.0f) phi = +90.0f;
469 if (phi < -90.0f) phi = -90.0f;
471 if (theta > +180.0f) theta -= 360.0f;
472 if (theta < -180.0f) theta += 360.0f;
474 game_look(phi, theta);
477 static int look_keybd(int c, int d)
479 if (d && c == SDLK_F12)
480 return goto_state(&st_play_loop);
485 static int look_buttn(int b, int d)
487 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
488 return goto_state(&st_play_loop);
493 /*---------------------------------------------------------------------------*/
495 struct state st_play_ready = {
509 struct state st_play_set = {
523 struct state st_play_loop = {
537 struct state st_look = {