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.
28 /*---------------------------------------------------------------------------*/
30 static int view_rotate
;
32 /*---------------------------------------------------------------------------*/
34 static int play_ready_enter(void)
38 if ((id
= gui_label(0, "Ready?", GUI_LRG
, GUI_ALL
, 0, 0)))
44 audio_play(AUD_READY
, 1.0f
);
50 static void play_ready_leave(int id
)
55 static void play_ready_paint(int id
, float st
)
61 static void play_ready_timer(int id
, float dt
)
63 float t
= time_state();
65 game_set_fly(1.0f
- 0.5f
* t
);
67 if (dt
> 0.0f
&& t
> 1.0f
)
68 goto_state(&st_play_set
);
75 static int play_ready_click(int b
, int d
)
77 return (b
< 0 && d
== 1) ? goto_state(&st_play_loop
) : 1;
80 static int play_ready_keybd(int c
, int d
)
82 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
85 static int play_ready_buttn(int b
, int d
)
89 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A
, b
))
90 return goto_state(&st_play_loop
);
91 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
92 return goto_state(&st_over
);
97 /*---------------------------------------------------------------------------*/
99 static int play_set_enter(void)
103 if ((id
= gui_label(0, "Set?", GUI_LRG
, GUI_ALL
, 0, 0)))
105 gui_layout(id
, 0, 0);
109 audio_play(AUD_SET
, 1.f
);
114 static void play_set_leave(int id
)
119 static void play_set_paint(int id
, float st
)
125 static void play_set_timer(int id
, float dt
)
127 float t
= time_state();
129 game_set_fly(0.5f
- 0.5f
* t
);
131 if (dt
> 0.0f
&& t
> 1.0f
)
132 goto_state(&st_play_loop
);
138 static int play_set_click(int b
, int d
)
143 return goto_state(&st_play_loop
);
148 static int play_set_keybd(int c
, int d
)
150 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
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 goto_state(&st_over
);
165 /*---------------------------------------------------------------------------*/
167 static int play_loop_enter(void)
171 if ((id
= gui_label(0, "GO!", GUI_LRG
, GUI_ALL
, gui_blu
, gui_grn
)))
173 gui_layout(id
, 0, 0);
177 audio_play(AUD_GO
, 1.f
);
185 static void play_loop_leave(int id
)
190 static void play_loop_paint(int id
, float st
)
195 if (time_state() < 1.f
)
199 static void play_loop_timer(int id
, float dt
)
201 float k
= (((SDL_GetModState() & KMOD_LSHIFT
) ||
202 (SDL_GetModState() & KMOD_RSHIFT
)) ?
203 (float) config_get_d(CONFIG_ROTATE_FAST
) / 100.f
:
204 (float) config_get_d(CONFIG_ROTATE_SLOW
) / 100.f
);
208 float g
[3] = { 0.0f
, -9.8f
, 0.0f
};
210 at
= (7 * at
+ dt
) / 8;
214 game_set_rot(view_rotate
* k
);
216 switch (game_step(g
, at
, 1))
218 case GAME_TIME
: level_stat(GAME_TIME
); goto_state(&st_time_out
); break;
219 case GAME_FALL
: level_stat(GAME_FALL
); goto_state(&st_fall_out
); break;
220 case GAME_GOAL
: level_stat(GAME_GOAL
); goto_state(&st_goal
); break;
228 static void play_loop_point(int id
, int x
, int y
, int dx
, int dy
)
230 game_set_pos(dx
, dy
);
233 static void play_loop_stick(int id
, int a
, int k
)
235 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X
, a
))
237 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y
, a
))
241 static int play_loop_click(int b
, int d
)
243 view_rotate
= d
? b
: 0;
247 static int play_loop_keybd(int c
, int d
)
251 if (config_tst_d(CONFIG_KEY_CAMERA_R
, c
))
253 if (config_tst_d(CONFIG_KEY_CAMERA_L
, c
))
256 if (config_tst_d(CONFIG_KEY_CAMERA_1
, c
))
258 config_set_d(CONFIG_CAMERA
, 0);
261 if (config_tst_d(CONFIG_KEY_CAMERA_2
, c
))
263 config_set_d(CONFIG_CAMERA
, 1);
266 if (config_tst_d(CONFIG_KEY_CAMERA_3
, c
))
268 config_set_d(CONFIG_CAMERA
, 2);
274 if (config_tst_d(CONFIG_KEY_CAMERA_R
, c
))
276 if (config_tst_d(CONFIG_KEY_CAMERA_L
, c
))
280 if (d
&& c
== SDLK_ESCAPE
)
281 goto_state(&st_over
);
282 if (d
&& c
== SDLK_F12
)
283 goto_state(&st_look
);
287 static int play_loop_buttn(int b
, int d
)
291 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
292 return goto_state(&st_over
);
294 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R
, b
))
296 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L
, b
))
299 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_1
, b
))
301 config_set_d(CONFIG_CAMERA
, 0);
304 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_2
, b
))
306 config_set_d(CONFIG_CAMERA
, 1);
309 if (config_tst_d(CONFIG_JOYSTICK_CAMERA_3
, b
))
311 config_set_d(CONFIG_CAMERA
, 2);
317 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_R
, b
))
319 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_L
, b
))
325 /*---------------------------------------------------------------------------*/
330 static int look_enter(void)
337 static void look_leave(int id
)
341 static void look_paint(int id
, float st
)
346 static void look_point(int id
, int x
, int y
, int dx
, int dy
)
348 phi
+= 90.0f
* dy
/ config_get_d(CONFIG_HEIGHT
);
349 theta
+= 180.0f
* dx
/ config_get_d(CONFIG_WIDTH
);
351 if (phi
> +90.0f
) phi
= +90.0f
;
352 if (phi
< -90.0f
) phi
= -90.0f
;
354 if (theta
> +180.0f
) theta
-= 360.0f
;
355 if (theta
< -180.0f
) theta
+= 360.0f
;
357 game_look(phi
, theta
);
360 static int look_keybd(int c
, int d
)
362 if (d
&& c
== SDLK_ESCAPE
) goto_state(&st_play_loop
);
363 if (d
&& c
== SDLK_F12
) goto_state(&st_play_loop
);
368 /*---------------------------------------------------------------------------*/
370 struct state st_play_ready
= {
383 struct state st_play_set
= {
396 struct state st_play_loop
= {
409 struct state st_look
= {