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.
31 /*---------------------------------------------------------------------------*/
33 static SDL_Joystick *joystick = NULL;
35 void set_joystick(SDL_Joystick *j)
40 /*---------------------------------------------------------------------------*/
42 static char *number(int i)
44 static char str[MAXSTR];
46 sprintf(str, "%02d", i);
51 static int score_card(const char *title,
57 int p1 = (curr_party() >= 1) ? 1 : 0, l1 = (curr_party() == 1) ? 1 : 0;
58 int p2 = (curr_party() >= 2) ? 1 : 0, l2 = (curr_party() == 2) ? 1 : 0;
59 int p3 = (curr_party() >= 3) ? 1 : 0, l3 = (curr_party() == 3) ? 1 : 0;
60 int p4 = (curr_party() >= 4) ? 1 : 0, l4 = (curr_party() == 4) ? 1 : 0;
63 int n = curr_count() - 1;
64 int m = curr_count() / 2;
66 if ((id = gui_vstack(0)))
68 gui_label(id, title, GUI_MED, GUI_ALL, c0, c1);
71 if ((jd = gui_hstack(id)))
73 if ((kd = gui_varray(jd)))
75 if (p1) gui_label(kd, _("O"), 0, GUI_NE, 0, 0);
76 if (p1) gui_label(kd, hole_out(0), 0, 0, gui_wht, gui_wht);
77 if (p1) gui_label(kd, hole_out(1), 0, GUI_SE * l1, gui_red, gui_wht);
78 if (p2) gui_label(kd, hole_out(2), 0, GUI_SE * l2, gui_grn, gui_wht);
79 if (p3) gui_label(kd, hole_out(3), 0, GUI_SE * l3, gui_blu, gui_wht);
80 if (p4) gui_label(kd, hole_out(4), 0, GUI_SE * l4, gui_yel, gui_wht);
83 if ((kd = gui_harray(jd)))
84 for (i = m; i > 0; i--)
85 if ((ld = gui_varray(kd)))
87 if (p1) gui_label(ld, number(i), 0, (i == 1) ? GUI_NW : 0, 0, 0);
88 if (p1) gui_label(ld, hole_score(i, 0), 0, 0, gui_wht, gui_wht);
89 if (p1) gui_label(ld, hole_score(i, 1), 0, 0, gui_red, gui_wht);
90 if (p2) gui_label(ld, hole_score(i, 2), 0, 0, gui_grn, gui_wht);
91 if (p3) gui_label(ld, hole_score(i, 3), 0, 0, gui_blu, gui_wht);
92 if (p4) gui_label(ld, hole_score(i, 4), 0, 0, gui_yel, gui_wht);
94 if ((kd = gui_varray(jd)))
97 if (p1) gui_label(kd, _("Par"), 0, GUI_NW, gui_wht, gui_wht);
98 if (p1) gui_label(kd, _("P1"), 0, GUI_SW * l1, gui_red, gui_wht);
99 if (p2) gui_label(kd, _("P2"), 0, GUI_SW * l2, gui_grn, gui_wht);
100 if (p3) gui_label(kd, _("P3"), 0, GUI_SW * l3, gui_blu, gui_wht);
101 if (p4) gui_label(kd, _("P4"), 0, GUI_SW * l4, gui_yel, gui_wht);
107 if ((jd = gui_hstack(id)))
109 if ((kd = gui_varray(jd)))
111 if (p1) gui_label(kd, _("Tot"), 0, GUI_TOP, 0, 0);
112 if (p1) gui_label(kd, hole_tot(0), 0, 0, gui_wht, gui_wht);
113 if (p1) gui_label(kd, hole_tot(1), 0, GUI_BOT * l1, gui_red, gui_wht);
114 if (p2) gui_label(kd, hole_tot(2), 0, GUI_BOT * l2, gui_grn, gui_wht);
115 if (p3) gui_label(kd, hole_tot(3), 0, GUI_BOT * l3, gui_blu, gui_wht);
116 if (p4) gui_label(kd, hole_tot(4), 0, GUI_BOT * l4, gui_yel, gui_wht);
118 if ((kd = gui_varray(jd)))
120 if (p1) gui_label(kd, _("I"), 0, GUI_NE, 0, 0);
121 if (p1) gui_label(kd, hole_in(0), 0, 0, gui_wht, gui_wht);
122 if (p1) gui_label(kd, hole_in(1), 0, GUI_SE * l1, gui_red, gui_wht);
123 if (p2) gui_label(kd, hole_in(2), 0, GUI_SE * l2, gui_grn, gui_wht);
124 if (p3) gui_label(kd, hole_in(3), 0, GUI_SE * l3, gui_blu, gui_wht);
125 if (p4) gui_label(kd, hole_in(4), 0, GUI_SE * l4, gui_yel, gui_wht);
127 if ((kd = gui_harray(jd)))
128 for (i = n; i > m; i--)
129 if ((ld = gui_varray(kd)))
131 if (p1) gui_label(ld, number(i), 0, (i == m+1) ? GUI_NW : 0, 0, 0);
132 if (p1) gui_label(ld, hole_score(i, 0), 0, 0, gui_wht, gui_wht);
133 if (p1) gui_label(ld, hole_score(i, 1), 0, 0, gui_red, gui_wht);
134 if (p2) gui_label(ld, hole_score(i, 2), 0, 0, gui_grn, gui_wht);
135 if (p3) gui_label(ld, hole_score(i, 3), 0, 0, gui_blu, gui_wht);
136 if (p4) gui_label(ld, hole_score(i, 4), 0, 0, gui_yel, gui_wht);
138 if ((kd = gui_varray(jd)))
141 if (p1) gui_label(kd, _("Par"), 0, GUI_NW, gui_wht, gui_wht);
142 if (p1) gui_label(kd, _("P1"), 0, GUI_SW * l1, gui_red, gui_wht);
143 if (p2) gui_label(kd, _("P2"), 0, GUI_SW * l2, gui_grn, gui_wht);
144 if (p3) gui_label(kd, _("P3"), 0, GUI_SW * l3, gui_blu, gui_wht);
145 if (p4) gui_label(kd, _("P4"), 0, GUI_SW * l4, gui_yel, gui_wht);
149 gui_layout(id, 0, 0);
155 /*---------------------------------------------------------------------------*/
157 static int shared_stick_basic(int id, int a, float v, int bump)
161 if ((jd = gui_stick(id, a, v, bump)))
167 static void shared_stick(int id, int a, float v, int bump)
169 shared_stick_basic(id, a, v, bump);
172 /*---------------------------------------------------------------------------*/
178 static int title_action(int i)
180 audio_play(AUD_MENU, 1.0f);
184 case TITLE_PLAY: return goto_state(&st_course);
185 case TITLE_CONF: return goto_state(&st_conf);
186 case TITLE_EXIT: return 0;
191 static int title_enter(struct state *st, struct state *prev)
195 /* Build the title GUI. */
197 if ((id = gui_vstack(0)))
199 gui_label(id, "Neverputt", GUI_LRG, GUI_ALL, 0, 0);
202 if ((jd = gui_harray(id)))
206 if ((kd = gui_varray(jd)))
208 gui_start(kd, sgettext("menu^Play"), GUI_MED, TITLE_PLAY, 1);
209 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
210 gui_state(kd, sgettext("menu^Exit"), GUI_MED, TITLE_EXIT, 0);
215 gui_layout(id, 0, 0);
224 static void title_leave(struct state *st, struct state *next, int id)
229 static void title_paint(int id, float t)
235 static void title_timer(int id, float dt)
237 float g[3] = { 0.f, 0.f, 0.f };
240 game_set_fly(fcosf(time_state() / 10.f));
245 static void title_point(int id, int x, int y, int dx, int dy)
247 gui_pulse(gui_point(id, x, y), 1.2f);
250 static int title_click(int b, int d)
252 return d && b == SDL_BUTTON_LEFT ? title_action(gui_token(gui_click())) : 1;
255 static int title_buttn(int b, int d)
259 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
260 return title_action(gui_token(gui_click()));
261 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
262 return title_action(TITLE_EXIT);
267 /*---------------------------------------------------------------------------*/
272 #define COURSE_BACK -1
274 static int course_action(int i)
276 if (course_exists(i))
279 goto_state(&st_party);
281 if (i == COURSE_BACK)
282 goto_state(&st_title);
287 static int comp_size(int n, int s)
289 return n <= s * s ? s : comp_size(n, s + 1);
292 static int comp_cols(int n)
294 return comp_size(n, 1);
297 static int comp_rows(int n)
299 int s = comp_size(n, 1);
301 return n <= s * (s - 1) ? s - 1 : s;
304 static int course_enter(struct state *st, struct state *prev)
306 int w = config_get_d(CONFIG_WIDTH);
307 int h = config_get_d(CONFIG_HEIGHT);
309 int id, jd, kd, ld, md;
318 if ((id = gui_vstack(0)))
320 gui_label(id, _("Select Course"), GUI_MED, GUI_ALL, 0, 0);
323 if ((jd = gui_hstack(id)))
325 shot_id = gui_image(jd, course_shot(0), w / 3, h / 3);
329 if ((kd = gui_varray(jd)))
331 for(i = 0; i < r; i++)
333 if ((ld = gui_harray(kd)))
335 for (j = c - 1; j >= 0; j--)
341 md = gui_image(ld, course_shot(k),
342 w / 3 / c, h / 3 / r);
343 gui_active(md, k, 0);
357 desc_id = gui_multi(id, _(course_desc(0)), GUI_SML, GUI_ALL, gui_yel, gui_wht);
360 if ((jd = gui_hstack(id)))
363 gui_state(jd, _("Back"), GUI_SML, COURSE_BACK, 0);
366 gui_layout(id, 0, 0);
369 audio_music_fade_to(0.5f, "bgm/inter.ogg");
374 static void course_leave(struct state *st, struct state *next, int id)
379 static void course_paint(int id, float t)
385 static void course_timer(int id, float dt)
390 static void course_point(int id, int x, int y, int dx, int dy)
394 if ((jd = gui_point(id, x, y)))
396 int i = gui_token(jd);
398 if (course_exists(i))
400 gui_set_image(shot_id, course_shot(i));
401 gui_set_multi(desc_id, _(course_desc(i)));
407 static void course_stick(int id, int a, float v, int bump)
411 if ((jd = shared_stick_basic(id, a, v, bump)))
413 int i = gui_token(jd);
415 if (course_exists(i))
417 gui_set_image(shot_id, course_shot(i));
418 gui_set_multi(desc_id, _(course_desc(i)));
424 static int course_click(int b, int d)
426 return d && b == SDL_BUTTON_LEFT ? course_action(gui_token(gui_click())) : 1;
429 static int course_buttn(int b, int d)
433 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
434 return course_action(gui_token(gui_click()));
435 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
436 return course_action(COURSE_BACK);
441 /*---------------------------------------------------------------------------*/
450 static int party_action(int i)
455 audio_play(AUD_MENU, 1.f);
457 goto_state(&st_next);
460 audio_play(AUD_MENU, 1.f);
462 goto_state(&st_next);
465 audio_play(AUD_MENU, 1.f);
467 goto_state(&st_next);
470 audio_play(AUD_MENU, 1.f);
472 goto_state(&st_next);
475 audio_play(AUD_MENU, 1.f);
476 goto_state(&st_course);
482 static int party_enter(struct state *st, struct state *prev)
486 if ((id = gui_vstack(0)))
488 gui_label(id, _("Players?"), GUI_MED, GUI_ALL, 0, 0);
491 if ((jd = gui_harray(id)))
493 int p4 = gui_state(jd, "4", GUI_LRG, PARTY_4, 0);
494 int p3 = gui_state(jd, "3", GUI_LRG, PARTY_3, 0);
495 int p2 = gui_state(jd, "2", GUI_LRG, PARTY_2, 0);
496 int p1 = gui_state(jd, "1", GUI_LRG, PARTY_1, 0);
498 gui_set_color(p1, gui_red, gui_wht);
499 gui_set_color(p2, gui_grn, gui_wht);
500 gui_set_color(p3, gui_blu, gui_wht);
501 gui_set_color(p4, gui_yel, gui_wht);
508 if ((jd = gui_hstack(id)))
511 gui_state(jd, _("Back"), GUI_SML, PARTY_B, 0);
514 gui_layout(id, 0, 0);
520 static void party_leave(struct state *st, struct state *next, int id)
525 static void party_paint(int id, float t)
531 static void party_timer(int id, float dt)
536 static void party_point(int id, int x, int y, int dx, int dy)
538 gui_pulse(gui_point(id, x, y), 1.2f);
541 static int party_click(int b, int d)
543 return d && b == SDL_BUTTON_LEFT ? party_action(gui_token(gui_click())) : 1;
546 static int party_buttn(int b, int d)
550 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
551 return party_action(gui_token(gui_click()));
552 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
553 return party_action(PARTY_B);
558 /*---------------------------------------------------------------------------*/
560 static int paused = 0;
562 static struct state *st_continue;
563 static struct state *st_quit;
565 #define PAUSE_CONTINUE 1
568 int goto_pause(struct state *s, int e)
570 if (curr_state() == &st_pause)
573 if (e && !config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
574 return goto_state(s);
576 st_continue = curr_state();
580 return goto_state(&st_pause);
583 static int pause_action(int i)
586 audio_play(AUD_MENU, 1.0f);
591 return goto_state(st_continue ? st_continue : &st_title);
594 return goto_state(st_quit);
599 static int pause_enter(struct state *st, struct state *prev)
603 audio_music_fade_out(0.2f);
605 if ((id = gui_vstack(0)))
607 td = gui_label(id, _("Paused"), GUI_LRG, GUI_ALL, 0, 0);
610 if ((jd = gui_harray(id)))
612 gui_state(jd, _("Quit"), GUI_SML, PAUSE_QUIT, 0);
613 gui_start(jd, _("Continue"), GUI_SML, PAUSE_CONTINUE, 1);
617 gui_layout(id, 0, 0);
625 static void pause_leave(struct state *st, struct state *next, int id)
629 audio_music_fade_in(0.5f);
632 static void pause_paint(int id, float t)
639 static void pause_timer(int id, float dt)
644 static void pause_point(int id, int x, int y, int dx, int dy)
646 gui_pulse(gui_point(id, x, y), 1.2f);
649 static int pause_click(int b, int d)
651 return d && b == SDL_BUTTON_LEFT ? pause_action(gui_token(gui_click())) : 1;
654 static int pause_keybd(int c, int d)
656 if (d && config_tst_d(CONFIG_KEY_PAUSE, c))
657 return pause_action(PAUSE_CONTINUE);
661 static int pause_buttn(int b, int d)
665 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
666 return pause_action(gui_token(gui_click()));
667 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
668 return pause_action(PAUSE_CONTINUE);
673 /*---------------------------------------------------------------------------*/
675 static int shared_keybd(int c, int d)
679 if (config_tst_d(CONFIG_KEY_PAUSE, c))
680 return goto_pause(&st_over, 0);
685 /*---------------------------------------------------------------------------*/
689 static int next_enter(struct state *st, struct state *prev)
694 sprintf(str, _("Hole %02d"), curr_hole());
696 if ((id = gui_vstack(0)))
698 gui_label(id, str, GUI_MED, GUI_ALL, 0, 0);
701 gui_label(id, _("Player"), GUI_SML, GUI_TOP, 0, 0);
703 switch (curr_player())
706 gui_label(id, "1", GUI_LRG, GUI_BOT, gui_red, gui_wht);
707 if (curr_party() > 1) audio_play(AUD_PLAYER1, 1.f);
710 gui_label(id, "2", GUI_LRG, GUI_BOT, gui_grn, gui_wht);
711 if (curr_party() > 1) audio_play(AUD_PLAYER2, 1.f);
714 gui_label(id, "3", GUI_LRG, GUI_BOT, gui_blu, gui_wht);
715 if (curr_party() > 1) audio_play(AUD_PLAYER3, 1.f);
718 gui_label(id, "4", GUI_LRG, GUI_BOT, gui_yel, gui_wht);
719 if (curr_party() > 1) audio_play(AUD_PLAYER4, 1.f);
722 gui_layout(id, 0, 0);
734 static void next_leave(struct state *st, struct state *next, int id)
740 static void next_paint(int id, float t)
747 static void next_timer(int id, float dt)
752 static void next_point(int id, int x, int y, int dx, int dy)
754 gui_pulse(gui_point(id, x, y), 1.2f);
757 static int next_click(int b, int d)
759 return (d && b == SDL_BUTTON_LEFT) ? goto_state(&st_flyby) : 1;
762 static int next_keybd(int c, int d)
767 return goto_state(&st_poser);
768 if (config_tst_d(CONFIG_KEY_PAUSE, c))
769 return goto_pause(&st_over, 0);
770 if ('0' <= c && c <= '9')
771 num = num * 10 + c - '0';
776 static int next_buttn(int b, int d)
780 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
782 if (num > 0 && hole_goto(num, -1))
785 return goto_state(&st_next);
787 return goto_state(&st_flyby);
789 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
790 return goto_pause(&st_over, 1);
795 /*---------------------------------------------------------------------------*/
797 static int poser_enter(struct state *st, struct state *prev)
803 static void poser_paint(int id, float t)
808 static int poser_buttn(int b, int d)
812 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
813 return goto_state(&st_next);
814 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
815 return goto_state(&st_next);
820 /*---------------------------------------------------------------------------*/
822 static int flyby_enter(struct state *st, struct state *prev)
832 static void flyby_leave(struct state *st, struct state *next, int id)
837 static void flyby_paint(int id, float t)
843 static void flyby_timer(int id, float dt)
845 float t = time_state();
847 if (dt > 0.f && t > 1.f)
848 goto_state(&st_stroke);
850 game_set_fly(1.f - t);
855 static int flyby_click(int b, int d)
857 if (d && b == SDL_BUTTON_LEFT)
860 return goto_state(&st_stroke);
865 static int flyby_buttn(int b, int d)
869 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
872 return goto_state(&st_stroke);
874 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
875 return goto_pause(&st_over, 1);
880 /*---------------------------------------------------------------------------*/
882 #define TOUCH_SENSITIVITY 20
883 #define LONG_PRESS_TIME 1000 /* one second */
884 #define DOUBLE_TAP_TIME 500
891 } button_state = BTN_CLEAR;
892 static int button_pressed_x = 0;
893 static int button_pressed_y = 0;
894 static Uint32 button_time = 0;
896 static int stroke_rotate = 0;
897 static int stroke_mag = 0;
899 static int stroke_enter(struct state *st, struct state *prev)
903 config_set_d(CONFIG_CAMERA, 2);
904 video_set_grab(!paused);
912 static void stroke_leave(struct state *st, struct state *next, int id)
916 config_set_d(CONFIG_CAMERA, 0);
919 static void stroke_paint(int id, float t)
925 static void stroke_timer(int id, float dt)
927 float g[3] = { 0.f, 0.f, 0.f };
931 if (button_state == BTN_CLICKED)
933 int elapsed = SDL_GetTicks() - button_time;
934 if (elapsed > DOUBLE_TAP_TIME)
936 /* it was a single click: start the simulation */
937 goto_state(&st_roll);
938 button_state = BTN_CLEAR;
943 if (SDL_GetModState() & KMOD_SHIFT ||
944 (joystick && SDL_JoystickGetButton(joystick,
945 config_get_d(CONFIG_JOYSTICK_BUTTON_B))))
950 game_set_rot(stroke_rotate * k);
951 game_set_mag(stroke_mag * k);
953 game_update_view(dt);
957 static void stroke_point(int id, int x, int y, int dx, int dy)
959 if (button_state == BTN_PRESS1 ||
960 button_state == BTN_PRESS2)
962 int duration = SDL_GetTicks() - button_time;
963 /* check how much we've moved */
964 if (abs(x - button_pressed_x) > TOUCH_SENSITIVITY ||
965 abs(y - button_pressed_y) > TOUCH_SENSITIVITY ||
966 duration > LONG_PRESS_TIME)
967 button_state = BTN_DRAGGING;
969 if (button_state != BTN_DRAGGING) return;
975 static void stroke_stick(int id, int a, float v, int bump)
977 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
978 stroke_rotate = 6 * v;
979 else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
983 static int stroke_click(int b, int d)
988 current_time = SDL_GetTicks();
992 SDL_GetMouseState(&button_pressed_x, &y);
993 button_pressed_y = -y + config_get_d(CONFIG_HEIGHT);
994 button_time = current_time;
995 button_state = (button_state == BTN_CLICKED) ? BTN_PRESS2 : BTN_PRESS1;
999 /* is it a double click? */
1000 int duration = current_time - button_time;
1001 if (button_state == BTN_PRESS2)
1003 button_state = BTN_CLEAR;
1004 if (duration < DOUBLE_TAP_TIME)
1005 ret = goto_pause(&st_over, 1);
1009 if (button_state == BTN_PRESS1 && duration < LONG_PRESS_TIME)
1010 button_state = BTN_CLICKED;
1012 button_state = BTN_CLEAR;
1018 static int stroke_buttn(int b, int d)
1022 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1023 return goto_state(&st_roll);
1024 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1025 return goto_pause(&st_over, 1);
1030 /*---------------------------------------------------------------------------*/
1032 static int roll_enter(struct state *st, struct state *prev)
1044 static void roll_leave(struct state *st, struct state *next, int id)
1049 static void roll_paint(int id, float t)
1055 static void roll_timer(int id, float dt)
1057 float g[3] = { 0.0f, -9.8f, 0.0f };
1059 switch (game_step(g, dt))
1061 case GAME_STOP: goto_state(&st_stop); break;
1062 case GAME_GOAL: goto_state(&st_goal); break;
1063 case GAME_FALL: goto_state(&st_fall); break;
1067 static int roll_buttn(int b, int d)
1071 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1072 return goto_pause(&st_over, 1);
1077 /*---------------------------------------------------------------------------*/
1079 static int goal_enter(struct state *st, struct state *prev)
1083 if ((id = gui_label(0, _("It's In!"), GUI_MED, GUI_ALL, gui_grn, gui_grn)))
1084 gui_layout(id, 0, 0);
1096 static void goal_leave(struct state *st, struct state *next, int id)
1102 static void goal_paint(int id, float t)
1109 static void goal_timer(int id, float dt)
1111 if (time_state() > 3)
1114 goto_state(&st_next);
1116 goto_state(&st_score);
1120 static int goal_click(int b, int d)
1122 if (b == SDL_BUTTON_LEFT && d == 1)
1125 goto_state(&st_next);
1127 goto_state(&st_score);
1132 static int goal_buttn(int b, int d)
1136 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1139 goto_state(&st_next);
1141 goto_state(&st_score);
1143 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1144 return goto_pause(&st_over, 1);
1149 /*---------------------------------------------------------------------------*/
1151 static int stop_enter(struct state *st, struct state *prev)
1163 static void stop_leave(struct state *st, struct state *next, int id)
1168 static void stop_paint(int id, float t)
1174 static void stop_timer(int id, float dt)
1176 float g[3] = { 0.f, 0.f, 0.f };
1178 game_update_view(dt);
1181 if (time_state() > 1)
1184 goto_state(&st_next);
1186 goto_state(&st_score);
1190 static int stop_click(int b, int d)
1192 if (b == SDL_BUTTON_LEFT && d == 1)
1195 goto_state(&st_next);
1197 goto_state(&st_score);
1202 static int stop_buttn(int b, int d)
1206 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1209 goto_state(&st_next);
1211 goto_state(&st_score);
1213 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1214 return goto_pause(&st_over, 1);
1219 /*---------------------------------------------------------------------------*/
1221 static int fall_enter(struct state *st, struct state *prev)
1225 if ((id = gui_label(0, _("1 Stroke Penalty"), GUI_MED, GUI_ALL, gui_blk, gui_red)))
1226 gui_layout(id, 0, 0);
1233 /* game_draw(0);*/ /*TODO: is this call ok? */ /* No, it's not. */
1241 static void fall_leave(struct state *st, struct state *next, int id)
1247 static void fall_paint(int id, float t)
1254 static void fall_timer(int id, float dt)
1256 if (time_state() > 3)
1259 goto_state(&st_next);
1261 goto_state(&st_score);
1265 static int fall_click(int b, int d)
1267 if (b == SDL_BUTTON_LEFT && d == 1)
1270 goto_state(&st_next);
1272 goto_state(&st_score);
1277 static int fall_buttn(int b, int d)
1281 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1284 goto_state(&st_next);
1286 goto_state(&st_score);
1288 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1289 return goto_pause(&st_over, 1);
1294 /*---------------------------------------------------------------------------*/
1296 static int score_enter(struct state *st, struct state *prev)
1298 audio_music_fade_out(2.f);
1303 return score_card(_("Scores"), gui_yel, gui_red);
1306 static void score_leave(struct state *st, struct state *next, int id)
1311 static void score_paint(int id, float t)
1317 static void score_timer(int id, float dt)
1322 static int score_click(int b, int d)
1324 if (b == SDL_BUTTON_LEFT && d == 1)
1327 return goto_state(&st_next);
1329 return goto_state(&st_title);
1334 static int score_buttn(int b, int d)
1338 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1341 goto_state(&st_next);
1343 goto_state(&st_score);
1345 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1346 return goto_pause(&st_over, 1);
1351 /*---------------------------------------------------------------------------*/
1353 static int over_enter(struct state *st, struct state *prev)
1355 audio_music_fade_out(2.f);
1356 return score_card(_("Final Scores"), gui_yel, gui_red);
1359 static void over_leave(struct state *st, struct state *next, int id)
1364 static void over_paint(int id, float t)
1370 static void over_timer(int id, float dt)
1375 static int over_click(int b, int d)
1377 return (d && b == SDL_BUTTON_LEFT) ? goto_state(&st_title) : 1;
1380 static int over_buttn(int b, int d)
1384 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
1385 return goto_state(&st_title);
1386 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
1387 return goto_state(&st_title);
1392 /*---------------------------------------------------------------------------*/
1394 struct state st_title = {
1408 struct state st_course = {
1422 struct state st_party = {
1436 struct state st_next = {
1450 struct state st_poser = {
1464 struct state st_flyby = {
1478 struct state st_stroke = {
1492 struct state st_roll = {
1506 struct state st_goal = {
1520 struct state st_stop = {
1534 struct state st_fall = {
1548 struct state st_score = {
1562 struct state st_over = {
1576 struct state st_pause = {