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.
24 #include "game_common.h"
25 #include "game_server.h"
26 #include "game_proxy.h"
27 #include "game_client.h"
34 #include "st_shared.h"
36 /*---------------------------------------------------------------------------*/
38 static int pause_or_exit(void)
40 if (config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
42 return goto_state(&st_pause);
46 progress_stat(GAME_NONE);
51 return goto_state(&st_exit);
55 /*---------------------------------------------------------------------------*/
57 static void set_camera(int c)
59 config_set_d(CONFIG_CAMERA, c);
63 static void toggle_camera(void)
65 int cam = (config_tst_d(CONFIG_CAMERA, VIEW_MANUAL) ?
66 VIEW_CHASE : VIEW_MANUAL);
71 static void keybd_camera(int c)
73 if (config_tst_d(CONFIG_KEY_CAMERA_1, c))
74 set_camera(VIEW_CHASE);
75 if (config_tst_d(CONFIG_KEY_CAMERA_2, c))
76 set_camera(VIEW_LAZY);
77 if (config_tst_d(CONFIG_KEY_CAMERA_3, c))
78 set_camera(VIEW_MANUAL);
80 if (config_tst_d(CONFIG_KEY_CAMERA_TOGGLE, c))
84 static void click_camera(int b)
86 if (config_tst_d(CONFIG_MOUSE_CAMERA_1, b))
87 set_camera(VIEW_CHASE);
88 if (config_tst_d(CONFIG_MOUSE_CAMERA_2, b))
89 set_camera(VIEW_LAZY);
90 if (config_tst_d(CONFIG_MOUSE_CAMERA_3, b))
91 set_camera(VIEW_MANUAL);
93 if (config_tst_d(CONFIG_MOUSE_CAMERA_TOGGLE, b))
97 static void buttn_camera(int b)
99 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1, b))
100 set_camera(VIEW_CHASE);
101 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2, b))
102 set_camera(VIEW_LAZY);
103 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3, b))
104 set_camera(VIEW_MANUAL);
106 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_TOGGLE, b))
110 /*---------------------------------------------------------------------------*/
112 static int play_ready_gui(void)
116 if ((id = gui_label(0, _("Ready?"), GUI_LRG, GUI_ALL, 0, 0)))
118 gui_layout(id, 0, 0);
125 static int play_ready_enter(struct state *st, struct state *prev)
127 audio_play(AUD_READY, 1.0f);
130 hud_view_pulse(config_get_d(CONFIG_CAMERA));
132 return play_ready_gui();
135 static void play_ready_paint(int id, float t)
137 game_client_draw(0, t);
142 static void play_ready_timer(int id, float dt)
144 float t = time_state();
146 game_client_fly(1.0f - 0.5f * t);
148 if (dt > 0.0f && t > 1.0f)
149 goto_state(&st_play_set);
156 static int play_ready_click(int b, int d)
162 if (b == SDL_BUTTON_LEFT)
163 goto_state(&st_play_loop);
168 static int play_ready_keybd(int c, int d)
174 if (config_tst_d(CONFIG_KEY_PAUSE, c))
175 goto_state(&st_pause);
180 static int play_ready_buttn(int b, int d)
186 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
187 return goto_state(&st_play_loop);
188 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
189 return pause_or_exit();
194 /*---------------------------------------------------------------------------*/
196 static int play_set_gui(void)
200 if ((id = gui_label(0, _("Set?"), GUI_LRG, GUI_ALL, 0, 0)))
202 gui_layout(id, 0, 0);
209 static int play_set_enter(struct state *st, struct state *prev)
211 audio_play(AUD_SET, 1.f);
213 return play_set_gui();
216 static void play_set_paint(int id, float t)
218 game_client_draw(0, t);
223 static void play_set_timer(int id, float dt)
225 float t = time_state();
227 game_client_fly(0.5f - 0.5f * t);
229 if (dt > 0.0f && t > 1.0f)
230 goto_state(&st_play_loop);
237 static int play_set_click(int b, int d)
243 if (b == SDL_BUTTON_LEFT)
244 goto_state(&st_play_loop);
249 static int play_set_keybd(int c, int d)
255 if (config_tst_d(CONFIG_KEY_PAUSE, c))
256 goto_state(&st_pause);
261 static int play_set_buttn(int b, int d)
267 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
268 return goto_state(&st_play_loop);
269 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
270 return pause_or_exit();
275 /*---------------------------------------------------------------------------*/
289 #define VIEWR_SET_R(v) do { \
290 view_rotate.R = (v); \
291 view_rotate.d = (v) ? DIR_R : (view_rotate.L ? DIR_L : 0); \
294 #define VIEWR_SET_L(v) do { \
295 view_rotate.L = (v); \
296 view_rotate.d = (v) ? DIR_L : (view_rotate.R ? DIR_R : 0); \
299 static int fast_rotate;
302 static int play_loop_gui(void)
306 if ((id = gui_label(0, _("GO!"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
308 gui_layout(id, 0, 0);
315 static int play_loop_enter(struct state *st, struct state *prev)
321 if (prev == &st_pause)
324 audio_play(AUD_GO, 1.f);
326 game_client_fly(0.0f);
331 return play_loop_gui();
334 static void play_loop_paint(int id, float t)
336 game_client_draw(0, t);
341 if (time_state() < 1.f)
345 static void play_loop_timer(int id, float dt)
347 float k = (fast_rotate ?
348 (float) config_get_d(CONFIG_ROTATE_FAST) / 100.0f :
349 (float) config_get_d(CONFIG_ROTATE_SLOW) / 100.0f);
353 game_set_rot(view_rotate.d == DIR_R ?
356 game_set_cam(config_get_d(CONFIG_CAMERA));
360 game_server_step(dt);
361 game_client_sync(demo_fp);
362 game_client_blend(game_server_blend());
364 switch (curr_status())
367 progress_stat(GAME_GOAL);
368 goto_state(&st_goal);
372 progress_stat(GAME_FALL);
373 goto_state(&st_fail);
377 progress_stat(GAME_TIME);
378 goto_state(&st_fail);
387 static void play_loop_point(int id, int x, int y, int dx, int dy)
389 game_set_pos(dx, dy);
392 static void play_loop_stick(int id, int a, float v, int bump)
394 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
396 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
398 if (config_tst_d(CONFIG_JOYSTICK_AXIS_U, a))
403 if (v > 0) VIEWR_SET_R(v);
404 if (v < 0) VIEWR_SET_L(v);
408 static int play_loop_click(int b, int d)
412 if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
414 if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
421 if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
423 if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
430 static int play_loop_keybd(int c, int d)
434 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
436 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
438 if (config_tst_d(CONFIG_KEY_ROTATE_FAST, c))
443 if (config_tst_d(CONFIG_KEY_RESTART, c) &&
444 progress_same_avail())
447 goto_state(&st_play_ready);
449 if (config_tst_d(CONFIG_KEY_PAUSE, c))
450 goto_state(&st_pause);
454 if (config_tst_d(CONFIG_KEY_CAMERA_R, c))
456 if (config_tst_d(CONFIG_KEY_CAMERA_L, c))
458 if (config_tst_d(CONFIG_KEY_ROTATE_FAST, c))
462 if (d && c == SDLK_F12 && config_cheat())
463 return goto_state(&st_look);
465 if (d && c == SDLK_F6)
466 show_hud = !show_hud;
468 if (d && c == SDLK_c && config_cheat())
470 progress_stat(GAME_GOAL);
471 return goto_state(&st_goal);
476 static int play_loop_buttn(int b, int d)
480 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
483 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
485 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
487 if (config_tst_d(CONFIG_JOYSTICK_ROTATE_FAST, b))
494 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R, b))
496 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L, b))
498 if (config_tst_d(CONFIG_JOYSTICK_ROTATE_FAST, b))
504 /*---------------------------------------------------------------------------*/
509 static int look_enter(struct state *st, struct state *prev)
516 static void look_leave(struct state *st, struct state *next, int id)
520 static void look_paint(int id, float t)
522 game_client_draw(0, t);
525 static void look_point(int id, int x, int y, int dx, int dy)
527 phi += 90.0f * dy / config_get_d(CONFIG_HEIGHT);
528 theta += 180.0f * dx / config_get_d(CONFIG_WIDTH);
530 if (phi > +90.0f) phi = +90.0f;
531 if (phi < -90.0f) phi = -90.0f;
533 if (theta > +180.0f) theta -= 360.0f;
534 if (theta < -180.0f) theta += 360.0f;
536 game_look(phi, theta);
539 static int look_keybd(int c, int d)
541 if (d && c == SDLK_F12)
542 return goto_state(&st_play_loop);
547 static int look_buttn(int b, int d)
549 if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
550 return goto_state(&st_play_loop);
555 /*---------------------------------------------------------------------------*/
557 struct state st_play_ready = {
570 struct state st_play_set = {
583 struct state st_play_loop = {
596 struct state st_look = {