2 * Copyright (C) 2003 Robert Kooima
4 * NEVERPUTT 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.
36 /*---------------------------------------------------------------------------*/
38 static float state_time
= 0.f
;
39 static struct state
*state
= &st_null
;
41 float time_state(void)
46 int goto_state(struct state
*st
)
48 if (state
&& state
->leave
)
54 if (state
&& state
->enter
)
60 /*---------------------------------------------------------------------------*/
64 glClearColor(0.0f
, 0.8f
, 1.0f
, 1.0f
);
65 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
66 if (state
&& state
->paint
) state
->paint();
72 return (state
&& state
->timer
) ? state
->timer(t
) : 1;
75 int st_point(int x
, int y
, int dx
, int dy
)
77 return (state
&& state
->point
) ? state
->point(x
, y
, dx
, dy
) : 1;
80 int st_click(int b
, int d
)
82 return (state
&& state
->click
) ? state
->click(b
, d
) : 1;
87 return (state
&& state
->keybd
) ? state
->keybd(c
) : 1;
90 /*---------------------------------------------------------------------------*/
92 static void score_card(const char *title
,
96 const GLfloat
*c0
= c_yellow
;
97 const GLfloat
*c1
= c_white
;
98 const GLfloat
*c2
= c_red
;
99 const GLfloat
*c3
= c_white
;
103 text_size("0", TXT_SML
, &w
, &h
);
106 menu_item(0, 0, +(14 * h
) / 2, 12 * w
- 4, 2 * h
);
107 menu_item(1, 0, +(5 * h
) / 2, 12 * w
- 4, 6 * h
+ 8);
108 menu_item(2, 0, -(9 * h
) / 2, 12 * w
- 4, 6 * h
+ 8);
109 menu_item(3, +7 * w
, -(9 * h
) / 2, 2 * w
- 4, 6 * h
+ 8);
111 menu_text(k
++, 0, +7*h
, t0
, t1
, title
, TXT_MED
);
113 menu_text(k
++, -4*w
, +5*h
, c0
, c2
, "01", TXT_SML
);
114 menu_text(k
++, -3*w
, +5*h
, c0
, c2
, "02", TXT_SML
);
115 menu_text(k
++, -2*w
, +5*h
, c0
, c2
, "03", TXT_SML
);
116 menu_text(k
++, -1*w
, +5*h
, c0
, c2
, "04", TXT_SML
);
117 menu_text(k
++, 0*w
, +5*h
, c0
, c2
, "05", TXT_SML
);
118 menu_text(k
++, +1*w
, +5*h
, c0
, c2
, "06", TXT_SML
);
119 menu_text(k
++, +2*w
, +5*h
, c0
, c2
, "07", TXT_SML
);
120 menu_text(k
++, +3*w
, +5*h
, c0
, c2
, "08", TXT_SML
);
121 menu_text(k
++, +4*w
, +5*h
, c0
, c2
, "09", TXT_SML
);
122 menu_text(k
++, +5*w
, +5*h
, c0
, c2
, "Out", TXT_SML
);
124 for (i
= 0; i
<= 4; i
++)
128 menu_text(k
++, -5*w
, (+4-i
)*h
, c3
, c1
, hole_player(i
), TXT_SML
);
129 menu_text(k
++, -4*w
, (+4-i
)*h
, c3
, c1
, hole_score(1, i
), TXT_SML
);
130 menu_text(k
++, -3*w
, (+4-i
)*h
, c3
, c1
, hole_score(2, i
), TXT_SML
);
131 menu_text(k
++, -2*w
, (+4-i
)*h
, c3
, c1
, hole_score(3, i
), TXT_SML
);
132 menu_text(k
++, -1*w
, (+4-i
)*h
, c3
, c1
, hole_score(4, i
), TXT_SML
);
133 menu_text(k
++, 0*w
, (+4-i
)*h
, c3
, c1
, hole_score(5, i
), TXT_SML
);
134 menu_text(k
++, +1*w
, (+4-i
)*h
, c3
, c1
, hole_score(6, i
), TXT_SML
);
135 menu_text(k
++, +2*w
, (+4-i
)*h
, c3
, c1
, hole_score(7, i
), TXT_SML
);
136 menu_text(k
++, +3*w
, (+4-i
)*h
, c3
, c1
, hole_score(8, i
), TXT_SML
);
137 menu_text(k
++, +4*w
, (+4-i
)*h
, c3
, c1
, hole_score(9, i
), TXT_SML
);
138 menu_text(k
++, +5*w
, (+4-i
)*h
, c3
, c1
, hole_out(i
), TXT_SML
);
141 menu_text(k
++, -4*w
, -2*h
, c0
, c2
, "10", TXT_SML
);
142 menu_text(k
++, -3*w
, -2*h
, c0
, c2
, "11", TXT_SML
);
143 menu_text(k
++, -2*w
, -2*h
, c0
, c2
, "12", TXT_SML
);
144 menu_text(k
++, -1*w
, -2*h
, c0
, c2
, "13", TXT_SML
);
145 menu_text(k
++, 0*w
, -2*h
, c0
, c2
, "14", TXT_SML
);
146 menu_text(k
++, +1*w
, -2*h
, c0
, c2
, "15", TXT_SML
);
147 menu_text(k
++, +2*w
, -2*h
, c0
, c2
, "16", TXT_SML
);
148 menu_text(k
++, +3*w
, -2*h
, c0
, c2
, "17", TXT_SML
);
149 menu_text(k
++, +4*w
, -2*h
, c0
, c2
, "18", TXT_SML
);
150 menu_text(k
++, +5*w
, -2*h
, c0
, c2
, "In", TXT_SML
);
151 menu_text(k
++, +7*w
, -2*h
, c0
, c2
, "Tot", TXT_SML
);
153 for (i
= 0; i
<= 4; i
++)
157 menu_text(k
++, -5*w
, (-3-i
)*h
, c3
, c1
, hole_player(i
), TXT_SML
);
158 menu_text(k
++, -4*w
, (-3-i
)*h
, c3
, c1
, hole_score(10, i
), TXT_SML
);
159 menu_text(k
++, -3*w
, (-3-i
)*h
, c3
, c1
, hole_score(11, i
), TXT_SML
);
160 menu_text(k
++, -2*w
, (-3-i
)*h
, c3
, c1
, hole_score(12, i
), TXT_SML
);
161 menu_text(k
++, -1*w
, (-3-i
)*h
, c3
, c1
, hole_score(13, i
), TXT_SML
);
162 menu_text(k
++, 0*w
, (-3-i
)*h
, c3
, c1
, hole_score(14, i
), TXT_SML
);
163 menu_text(k
++, +1*w
, (-3-i
)*h
, c3
, c1
, hole_score(15, i
), TXT_SML
);
164 menu_text(k
++, +2*w
, (-3-i
)*h
, c3
, c1
, hole_score(16, i
), TXT_SML
);
165 menu_text(k
++, +3*w
, (-3-i
)*h
, c3
, c1
, hole_score(17, i
), TXT_SML
);
166 menu_text(k
++, +4*w
, (-3-i
)*h
, c3
, c1
, hole_score(18, i
), TXT_SML
);
167 menu_text(k
++, +5*w
, (-3-i
)*h
, c3
, c1
, hole_in(i
), TXT_SML
);
168 menu_text(k
++, +7*w
, (-3-i
)*h
, c3
, c1
, hole_tot(i
), TXT_SML
);
173 /*---------------------------------------------------------------------------*/
175 static void null_enter(void)
187 static void null_leave(void)
191 text_init(config_get_d(CONFIG_HEIGHT
));
192 ball_init(config_get_d(CONFIG_GEOMETRY
));
193 mark_init(config_get_d(CONFIG_GEOMETRY
));
194 flag_init(config_get_d(CONFIG_GEOMETRY
));
195 jump_init(config_get_d(CONFIG_GEOMETRY
));
196 swch_init(config_get_d(CONFIG_GEOMETRY
));
200 /*---------------------------------------------------------------------------*/
206 #define STR_TITLE " Neverputt "
207 #define STR_PLAY " Play "
208 #define STR_CONF " Options "
209 #define STR_EXIT " Exit "
211 static int title_action(int i
)
215 case TITLE_PLAY
: audio_play(AUD_MENU
, 1.f
); goto_state(&st_party
); break;
216 case TITLE_CONF
: audio_play(AUD_MENU
, 1.f
); goto_state(&st_conf
); break;
217 case TITLE_EXIT
: return 0;
222 static void title_enter(void)
227 text_size(STR_TITLE
, TXT_LRG
, &lw
, &lh
);
228 text_size(STR_CONF
, TXT_MED
, &mw
, &mh
);
232 menu_init(4, 4, TITLE_PLAY
);
234 menu_text(0, 0, mh
+ lm
, c_yellow
, c_red
, STR_TITLE
, TXT_LRG
);
235 menu_text(TITLE_PLAY
, 0, -0 * mh
, c_white
, c_white
, STR_PLAY
, TXT_MED
);
236 menu_text(TITLE_CONF
, 0, -1 * mh
, c_white
, c_white
, STR_CONF
, TXT_MED
);
237 menu_text(TITLE_EXIT
, 0, -2 * mh
, c_white
, c_white
, STR_EXIT
, TXT_MED
);
239 menu_item(0, 0, mh
+ lm
, lw
, lh
);
240 menu_item(TITLE_PLAY
, 0, -0 * mh
, mw
, mh
);
241 menu_item(TITLE_CONF
, 0, -1 * mh
, mw
, mh
);
242 menu_item(TITLE_EXIT
, 0, -2 * mh
, mw
, mh
);
245 menu_stat(TITLE_PLAY
, +1);
246 menu_stat(TITLE_CONF
, 0);
247 menu_stat(TITLE_EXIT
, 0);
250 hole_goto(rand() % curr_count(), 1);
253 static void title_leave(void)
259 static void title_paint(void)
265 static int title_timer(float dt
)
267 float g
[3] = { 0.f
, 0.f
, 0.f
};
270 game_set_fly(fcosf(time_state() / 10.f
));
275 static int title_point(int x
, int y
, int dx
, int dy
)
281 static int title_click(int b
, int d
)
283 return (b
< 0 && d
== 1) ? title_action(menu_click()) : 1;
286 static int title_keybd(int c
)
288 return (c
== SDLK_ESCAPE
) ? 0 : 1;
291 /*---------------------------------------------------------------------------*/
303 #define CONF_GEOLO 10
304 #define CONF_AUDHI 11
305 #define CONF_AUDLO 12
306 #define CONF_SNDDN 13
307 #define CONF_SNDUP 14
308 #define CONF_MUSDN 15
309 #define CONF_MUSUP 16
312 static int conf_action(int i
)
314 int f
= config_get_d(CONFIG_FULLSCREEN
);
315 int w
= config_get_d(CONFIG_WIDTH
);
316 int h
= config_get_d(CONFIG_HEIGHT
);
317 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
318 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
323 text_size("MMMMMMMMM", TXT_SML
, &w
, &h
);
329 goto_state(&st_null
);
330 r
= config_mode(1, w
, h
);
331 goto_state(&st_conf
);
335 goto_state(&st_null
);
336 r
= config_mode(0, w
, h
);
337 goto_state(&st_conf
);
341 goto_state(&st_null
);
342 r
= config_mode(f
, 1600, 1200);
343 goto_state(&st_conf
);
347 goto_state(&st_null
);
348 r
= config_mode(f
, 1280, 1024);
349 goto_state(&st_conf
);
353 goto_state(&st_null
);
354 r
= config_mode(f
, 1024, 768);
355 goto_state(&st_conf
);
359 goto_state(&st_null
);
360 r
= config_mode(f
, 800, 600);
361 goto_state(&st_conf
);
365 goto_state(&st_null
);
366 r
= config_mode(f
, 640, 480);
367 goto_state(&st_conf
);
371 goto_state(&st_null
);
372 config_set_d(CONFIG_TEXTURES
, 1);
373 goto_state(&st_conf
);
377 goto_state(&st_null
);
378 config_set_d(CONFIG_TEXTURES
, 2);
379 goto_state(&st_conf
);
383 goto_state(&st_null
);
384 config_set_d(CONFIG_GEOMETRY
, 1);
385 goto_state(&st_conf
);
389 goto_state(&st_null
);
390 config_set_d(CONFIG_GEOMETRY
, 0);
391 goto_state(&st_conf
);
396 config_set_d(CONFIG_AUDIO_RATE
, 44100);
397 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_HI
);
399 goto_state(&st_conf
);
404 config_set_d(CONFIG_AUDIO_RATE
, 22050);
405 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_LO
);
407 goto_state(&st_conf
);
411 config_set_d(CONFIG_SOUND_VOLUME
, s
- 1);
412 sprintf(str
, "%02d", s
- 1);
413 audio_volume(s
- 1, m
);
414 menu_text(33, +w2
, -3 * h
, c_yellow
, c_red
, str
, TXT_SML
);
415 audio_play(AUD_BUMP
, 1.f
);
419 config_set_d(CONFIG_SOUND_VOLUME
, s
+ 1);
420 sprintf(str
, "%02d", s
+ 1);
421 audio_volume(s
+ 1, m
);
422 menu_text(33, +w2
, -3 * h
, c_yellow
, c_red
, str
, TXT_SML
);
423 audio_play(AUD_BUMP
, 1.f
);
427 config_set_d(CONFIG_MUSIC_VOLUME
, m
- 1);
428 sprintf(str
, "%02d", m
- 1);
429 audio_volume(s
, m
- 1);
430 menu_text(34, +w2
, -4 * h
, c_yellow
, c_red
, str
, TXT_SML
);
434 config_set_d(CONFIG_MUSIC_VOLUME
, m
+ 1);
435 sprintf(str
, "%02d", m
+ 1);
436 audio_volume(s
, m
+ 1);
437 menu_text(34, +w2
, -4 * h
, c_yellow
, c_red
, str
, TXT_SML
);
441 goto_state(&st_title
);
447 static void conf_enter(void)
449 static int value
= CONF_FULL
;
456 /* Compute menu sizes from font sizes */
458 text_size("MMMMMMMMM", TXT_SML
, &w
, &h
);
463 sprintf(snds
, "%02d", config_get_d(CONFIG_SOUND_VOLUME
));
464 sprintf(muss
, "%02d", config_get_d(CONFIG_MUSIC_VOLUME
));
466 menu_init(36, 25, value
);
470 menu_text(0, -w2
, +h2
+ 4 * h
, c_yellow
, c_red
, "Options", TXT_MED
);
471 menu_text(1, -w2
, +3 * h
, c_white
, c_white
, "Fullscreen", TXT_SML
);
472 menu_text(2, -w2
, +2 * h
, c_white
, c_white
, "Window", TXT_SML
);
473 menu_text(3, +w2
- w4
, +5 * h
, c_white
, c_white
, "1600", TXT_SML
);
474 menu_text(4, +w2
- w4
, +4 * h
, c_white
, c_white
, "1280", TXT_SML
);
475 menu_text(5, +w2
- w4
, +3 * h
, c_white
, c_white
, "1024", TXT_SML
);
476 menu_text(6, +w2
- w4
, +2 * h
, c_white
, c_white
, "800", TXT_SML
);
477 menu_text(7, +w2
- w4
, 1 * h
, c_white
, c_white
, "640", TXT_SML
);
478 menu_text(8, +w2
, +5 * h
, c_white
, c_white
, "x", TXT_SML
);
479 menu_text(9, +w2
, +4 * h
, c_white
, c_white
, "x", TXT_SML
);
480 menu_text(10, +w2
, +3 * h
, c_white
, c_white
, "x", TXT_SML
);
481 menu_text(11, +w2
, +2 * h
, c_white
, c_white
, "x", TXT_SML
);
482 menu_text(12, +w2
, 1 * h
, c_white
, c_white
, "x", TXT_SML
);
483 menu_text(13, +w2
+ w4
, +5 * h
, c_white
, c_white
, "1200", TXT_SML
);
484 menu_text(14, +w2
+ w4
, +4 * h
, c_white
, c_white
, "1024", TXT_SML
);
485 menu_text(15, +w2
+ w4
, +3 * h
, c_white
, c_white
, "768", TXT_SML
);
486 menu_text(16, +w2
+ w4
, +2 * h
, c_white
, c_white
, "600", TXT_SML
);
487 menu_text(17, +w2
+ w4
, 1 * h
, c_white
, c_white
, "480", TXT_SML
);
488 menu_text(18, -w2
, 0 * h
, c_yellow
, c_red
, "Textures", TXT_SML
);
489 menu_text(19, -w2
, -1 * h
, c_yellow
, c_red
, "Geometry", TXT_SML
);
490 menu_text(20, -w2
, -2 * h
, c_yellow
, c_red
, "Audio", TXT_SML
);
491 menu_text(21, -w2
, -3 * h
, c_yellow
, c_red
, "Sound Vol", TXT_SML
);
492 menu_text(22, -w2
, -4 * h
, c_yellow
, c_red
, "Music Vol", TXT_SML
);
493 menu_text(23, +w2
- w4
, 0 * h
, c_white
, c_white
, "High", TXT_SML
);
494 menu_text(24, +w2
- w4
, -1 * h
, c_white
, c_white
, "High", TXT_SML
);
495 menu_text(25, +w2
- w4
, -2 * h
, c_white
, c_white
, "High", TXT_SML
);
496 menu_text(26, +w2
- w4
, -3 * h
, c_white
, c_white
, "<", TXT_SML
);
497 menu_text(27, +w2
- w4
, -4 * h
, c_white
, c_white
, "<", TXT_SML
);
498 menu_text(28, +w2
+ w4
, 0 * h
, c_white
, c_white
, "Low", TXT_SML
);
499 menu_text(29, +w2
+ w4
, -1 * h
, c_white
, c_white
, "Low", TXT_SML
);
500 menu_text(30, +w2
+ w4
, -2 * h
, c_white
, c_white
, "Low", TXT_SML
);
501 menu_text(31, +w2
+ w4
, -3 * h
, c_white
, c_white
, ">", TXT_SML
);
502 menu_text(32, +w2
+ w4
, -4 * h
, c_white
, c_white
, ">", TXT_SML
);
503 menu_text(33, +w2
, -3 * h
, c_yellow
, c_red
, snds
, TXT_SML
);
504 menu_text(34, +w2
, -4 * h
, c_yellow
, c_red
, muss
, TXT_SML
);
505 menu_text(35, +w2
, -5 * h
, c_white
, c_white
, "Back", TXT_SML
);
509 menu_item(CONF_FULL
, -w2
, +3 * h
, w
, h
);
510 menu_item(CONF_WIN
, -w2
, +2 * h
, w
, h
);
511 menu_item(CONF_16x12
, +w2
, +5 * h
, w
, h
);
512 menu_item(CONF_12x10
, +w2
, +4 * h
, w
, h
);
513 menu_item(CONF_10x7
, +w2
, +3 * h
, w
, h
);
514 menu_item(CONF_8x6
, +w2
, +2 * h
, w
, h
);
515 menu_item(CONF_6x4
, +w2
, +1 * h
, w
, h
);
516 menu_item(CONF_TEXHI
, +w2
- w4
, 0 * h
, w2
, h
);
517 menu_item(CONF_TEXLO
, +w2
+ w4
, 0 * h
, w2
, h
);
518 menu_item(CONF_GEOHI
, +w2
- w4
, -1 * h
, w2
, h
);
519 menu_item(CONF_GEOLO
, +w2
+ w4
, -1 * h
, w2
, h
);
520 menu_item(CONF_AUDHI
, +w2
- w4
, -2 * h
, w2
, h
);
521 menu_item(CONF_AUDLO
, +w2
+ w4
, -2 * h
, w2
, h
);
522 menu_item(CONF_SNDDN
, +w2
- w4
, -3 * h
, w2
, h
);
523 menu_item(CONF_SNDUP
, +w2
+ w4
, -3 * h
, w2
, h
);
524 menu_item(CONF_MUSDN
, +w2
- w4
, -4 * h
, w2
, h
);
525 menu_item(CONF_MUSUP
, +w2
+ w4
, -4 * h
, w2
, h
);
526 menu_item(CONF_BACK
, +w2
, -5 * h
, w
, h
);
528 /* Inactive label padding */
530 menu_item(18, -w2
, +5 * h
, w
, h
);
531 menu_item(19, -w2
, +4 * h
, w
, h
);
532 menu_item(20, -w2
, 0 * h
, w
, h
);
533 menu_item(21, -w2
, -1 * h
, w
, h
);
534 menu_item(22, -w2
, -2 * h
, w
, h
);
535 menu_item(23, -w2
, -3 * h
, w
, h
);
536 menu_item(24, -w2
, -4 * h
, w
, h
);
540 menu_stat(CONF_FULL
, (config_get_d(CONFIG_FULLSCREEN
)) ? 1 : 0);
541 menu_stat(CONF_WIN
, (config_get_d(CONFIG_FULLSCREEN
)) ? 0 : 1);
542 menu_stat(CONF_16x12
, (config_get_d(CONFIG_WIDTH
) == 1600) ? 1 : 0);
543 menu_stat(CONF_12x10
, (config_get_d(CONFIG_WIDTH
) == 1280) ? 1 : 0);
544 menu_stat(CONF_10x7
, (config_get_d(CONFIG_WIDTH
) == 1024) ? 1 : 0);
545 menu_stat(CONF_8x6
, (config_get_d(CONFIG_WIDTH
) == 800) ? 1 : 0);
546 menu_stat(CONF_6x4
, (config_get_d(CONFIG_WIDTH
) == 640) ? 1 : 0);
547 menu_stat(CONF_TEXHI
, (config_get_d(CONFIG_TEXTURES
) == 1) ? 1 : 0);
548 menu_stat(CONF_TEXLO
, (config_get_d(CONFIG_TEXTURES
) == 2) ? 1 : 0);
549 menu_stat(CONF_GEOHI
, (config_get_d(CONFIG_GEOMETRY
) == 1) ? 1 : 0);
550 menu_stat(CONF_GEOLO
, (config_get_d(CONFIG_GEOMETRY
) == 0) ? 1 : 0);
551 menu_stat(CONF_AUDHI
, (config_get_d(CONFIG_AUDIO_RATE
) == 44100) ? 1 : 0);
552 menu_stat(CONF_AUDLO
, (config_get_d(CONFIG_AUDIO_RATE
) == 22050) ? 1 : 0);
553 menu_stat(CONF_SNDDN
, 0);
554 menu_stat(CONF_SNDUP
, 0);
555 menu_stat(CONF_MUSDN
, 0);
556 menu_stat(CONF_MUSUP
, 0);
557 menu_stat(CONF_BACK
, 0);
559 /* Disable unsupported modes. */
561 if (!SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE
))
562 menu_stat(CONF_16x12
, -1);
563 if (!SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE
))
564 menu_stat(CONF_12x10
, -1);
565 if (!SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE
))
566 menu_stat(CONF_10x7
, -1);
567 if (!SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE
))
568 menu_stat(CONF_8x6
, -1);
569 if (!SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE
))
570 menu_stat(CONF_8x6
, -1);
575 static void conf_leave(void)
581 static void conf_paint(void)
586 static int conf_point(int x
, int y
, int dx
, int dy
)
592 static int conf_click(int b
, int d
)
594 return (b
< 0 && d
== 1) ? conf_action(menu_click()) : 1;
597 static int conf_keybd(int c
)
599 return (c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
602 /*---------------------------------------------------------------------------*/
611 static int party_action(int i
)
616 audio_play(AUD_MENU
, 1.f
);
619 goto_state(&st_next
);
622 audio_play(AUD_MENU
, 1.f
);
625 goto_state(&st_next
);
628 audio_play(AUD_MENU
, 1.f
);
631 goto_state(&st_next
);
634 audio_play(AUD_MENU
, 1.f
);
637 goto_state(&st_next
);
640 audio_play(AUD_MENU
, 1.f
);
641 goto_state(&st_title
);
647 static void party_enter(void)
650 int lw
, lh
, w
= config_get_d(CONFIG_WIDTH
) / 2;
652 text_size("0", TXT_MED
, &mw
, &mh
);
653 text_size("0", TXT_LRG
, &lw
, &lh
);
657 menu_text(PARTY_T
, 0, +1 * lh
, c_white
, c_white
, "Players?", TXT_MED
);
658 menu_text(PARTY_1
, -3 * lw
, 0, c_red
, c_white
, "1", TXT_LRG
);
659 menu_text(PARTY_2
, -1 * lw
, 0, c_green
, c_white
, "2", TXT_LRG
);
660 menu_text(PARTY_3
, +1 * lw
, 0, c_blue
, c_white
, "3", TXT_LRG
);
661 menu_text(PARTY_4
, +3 * lw
, 0, c_yellow
, c_white
, "4", TXT_LRG
);
662 menu_text(PARTY_B
, 0, -1 * lh
, c_yellow
, c_red
, "Back", TXT_MED
);
664 menu_item(PARTY_T
, 0, +1 * lh
, w
, mh
);
665 menu_item(PARTY_1
, -3 * lw
, 0, 2 * lw
, lh
);
666 menu_item(PARTY_2
, -1 * lw
, 0, 2 * lw
, lh
);
667 menu_item(PARTY_3
, +1 * lw
, 0, 2 * lw
, lh
);
668 menu_item(PARTY_4
, +3 * lw
, 0, 2 * lw
, lh
);
669 menu_item(PARTY_B
, 0, -1 * lh
, w
, mh
);
671 menu_stat(PARTY_T
, -1);
672 menu_stat(PARTY_1
, 0);
673 menu_stat(PARTY_2
, 0);
674 menu_stat(PARTY_3
, 0);
675 menu_stat(PARTY_4
, 0);
676 menu_stat(PARTY_B
, 0);
678 audio_music_fade(2.0f
);
681 static void party_leave(void)
686 static void party_paint(void)
691 static int party_timer(float dt
)
696 static int party_point(int x
, int y
, int dx
, int dy
)
702 static int party_click(int b
, int d
)
704 return (b
< 0 && d
== 1) ? party_action(menu_click()) : 1;
707 static int party_keybd(int c
)
709 return (c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
712 /*---------------------------------------------------------------------------*/
714 static void next_enter(void)
716 const GLfloat
*c0
= c_yellow
;
717 const GLfloat
*c1
= c_red
;
718 const GLfloat
*c2
= c_white
;
719 const GLfloat
*c3
= c_play
[curr_player()];
729 text_size("0", TXT_SML
, &sw
, &sh
);
730 text_size("0", TXT_MED
, &mw
, &mh
);
731 text_size("0", TXT_LRG
, &lw
, &lh
);
733 w
= config_get_d(CONFIG_WIDTH
) / 2;
736 sprintf(str1
, "Hole %02d", curr_hole());
737 sprintf(str2
, "%d", curr_player());
741 menu_text(0, 0, +mh
, c0
, c1
, str1
, TXT_MED
);
742 menu_text(1, 0, 0, c3
, c2
, "Player", TXT_SML
);
743 menu_text(2, 0, h
, c3
, c2
, str2
, TXT_LRG
);
745 menu_item(0, 0, +mh
, w
, mh
);
746 menu_item(1, 0, 0, lw
* 2, sh
);
747 menu_item(2, 0, h
, lw
* 2, lh
);
749 if (curr_party() > 1)
750 switch (curr_player())
752 case 1: audio_play(AUD_PLAYER1
, 1.0f
); break;
753 case 2: audio_play(AUD_PLAYER2
, 1.0f
); break;
754 case 3: audio_play(AUD_PLAYER3
, 1.0f
); break;
755 case 4: audio_play(AUD_PLAYER4
, 1.0f
); break;
761 static void next_leave(void)
766 static void next_paint(void)
772 static int next_click(int b
, int d
)
774 return (b
< 0 && d
== 1) ? goto_state(&st_flyby
) : 1;
777 static int next_keybd(int c
)
779 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
782 /*---------------------------------------------------------------------------*/
784 static void flyby_enter(void)
788 static void flyby_leave(void)
792 static void flyby_paint(void)
798 static int flyby_timer(float dt
)
800 float t
= time_state();
802 if (dt
> 0.f
&& t
> 1.f
)
803 return goto_state(&st_stroke
);
805 game_set_fly(1.f
- t
);
810 static int flyby_click(int b
, int d
)
815 return goto_state(&st_stroke
);
820 static int flyby_keybd(int c
)
822 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
825 /*---------------------------------------------------------------------------*/
827 static void stroke_enter(void)
830 config_set_d(CONFIG_CAMERA
, 2);
831 SDL_ShowCursor(SDL_DISABLE
);
832 SDL_WM_GrabInput(SDL_GRAB_ON
);
835 static void stroke_leave(void)
837 SDL_WM_GrabInput(SDL_GRAB_OFF
);
838 SDL_ShowCursor(SDL_ENABLE
);
839 config_set_d(CONFIG_CAMERA
, 0);
842 static void stroke_paint(void)
848 static int stroke_point(int x
, int y
, int dx
, int dy
)
855 static int stroke_timer(float dt
)
857 float g
[3] = { 0.f
, 0.f
, 0.f
};
859 game_update_view(dt
);
864 static int stroke_click(int b
, int d
)
867 return goto_state(&st_roll
);
872 static int stroke_keybd(int c
)
874 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
877 /*---------------------------------------------------------------------------*/
879 static void roll_enter(void)
884 static void roll_leave(void)
888 static void roll_paint(void)
894 static int roll_timer(float dt
)
896 float g
[3] = { 0.0f
, -9.8f
, 0.0f
};
898 switch (game_step(g
, dt
))
900 case GAME_STOP
: goto_state(&st_stop
); break;
901 case GAME_GOAL
: goto_state(&st_goal
); break;
902 case GAME_FALL
: goto_state(&st_fall
); break;
908 static int roll_keybd(int c
)
910 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
913 /*---------------------------------------------------------------------------*/
915 static void goal_enter(void)
918 menu_init(137, 4, 150);
919 score_card("It's In!", c_green
, c_green
);
922 static void goal_leave(void)
927 static void goal_paint(void)
933 static int goal_click(int b
, int d
)
938 return goto_state(&st_next
);
940 return goto_state(&st_over
);
945 static int goal_keybd(int c
)
947 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
950 /*---------------------------------------------------------------------------*/
952 static void stop_enter(void)
955 menu_init(137, 4, 150);
956 score_card("Score Card", c_white
, c_white
);
959 static void stop_leave(void)
964 static void stop_paint(void)
970 static int stop_click(int b
, int d
)
975 return goto_state(&st_next
);
977 return goto_state(&st_over
);
982 static int stop_keybd(int c
)
984 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
987 /*---------------------------------------------------------------------------*/
989 static void fall_enter(void)
992 menu_init(137, 4, 150);
993 score_card("1 Stroke Penalty", c_black
, c_red
);
996 static void fall_leave(void)
1001 static void fall_paint(void)
1007 static int fall_click(int b
, int d
)
1009 if (b
< 0 && d
== 1)
1012 return goto_state(&st_next
);
1014 return goto_state(&st_over
);
1019 static int fall_keybd(int c
)
1021 return (c
== SDLK_ESCAPE
) ? goto_state(&st_over
) : 1;
1024 /*---------------------------------------------------------------------------*/
1026 static void over_enter(void)
1028 audio_music_fade(2.f
);
1030 menu_init(137, 4, 150);
1031 score_card("Final Score", c_yellow
, c_red
);
1034 static void over_leave(void)
1042 static void over_paint(void)
1044 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
1048 static int over_keybd(int c
)
1050 return (c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
1053 static int over_click(int b
, int d
)
1055 return (b
< 0 && d
== 1) ? goto_state(&st_title
) : 1;
1058 /*---------------------------------------------------------------------------*/
1060 struct state st_null
= {
1070 struct state st_title
= {
1080 struct state st_conf
= {
1090 struct state st_party
= {
1100 struct state st_next
= {
1110 struct state st_flyby
= {
1120 struct state st_stroke
= {
1130 struct state st_roll
= {
1140 struct state st_goal
= {
1150 struct state st_stop
= {
1160 struct state st_fall
= {
1170 struct state st_over
= {