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 char *number(int i)
35 static char str[MAXSTR];
37 sprintf(str, "%02d", i);
42 static int score_card(const char *title,
48 int p1 = (curr_party() >= 1) ? 1 : 0, l1 = (curr_party() == 1) ? 1 : 0;
49 int p2 = (curr_party() >= 2) ? 1 : 0, l2 = (curr_party() == 2) ? 1 : 0;
50 int p3 = (curr_party() >= 3) ? 1 : 0, l3 = (curr_party() == 3) ? 1 : 0;
51 int p4 = (curr_party() >= 4) ? 1 : 0, l4 = (curr_party() == 4) ? 1 : 0;
54 int n = curr_count() - 1;
55 int m = curr_count() / 2;
57 if ((id = gui_vstack(0)))
59 gui_label(id, title, GUI_MED, GUI_ALL, c0, c1);
62 if ((jd = gui_hstack(id)))
64 if ((kd = gui_varray(jd)))
66 if (p1) gui_label(kd, _("O"), 0, GUI_NE, 0, 0);
67 if (p1) gui_label(kd, hole_out(0), 0, 0, gui_wht, gui_wht);
68 if (p1) gui_label(kd, hole_out(1), 0, GUI_SE * l1, gui_red, gui_wht);
69 if (p2) gui_label(kd, hole_out(2), 0, GUI_SE * l2, gui_grn, gui_wht);
70 if (p3) gui_label(kd, hole_out(3), 0, GUI_SE * l3, gui_blu, gui_wht);
71 if (p4) gui_label(kd, hole_out(4), 0, GUI_SE * l4, gui_yel, gui_wht);
74 if ((kd = gui_harray(jd)))
75 for (i = m; i > 0; i--)
76 if ((ld = gui_varray(kd)))
78 if (p1) gui_label(ld, number(i), 0, (i == 1) ? GUI_NW : 0, 0, 0);
79 if (p1) gui_label(ld, hole_score(i, 0), 0, 0, gui_wht, gui_wht);
80 if (p1) gui_label(ld, hole_score(i, 1), 0, 0, gui_red, gui_wht);
81 if (p2) gui_label(ld, hole_score(i, 2), 0, 0, gui_grn, gui_wht);
82 if (p3) gui_label(ld, hole_score(i, 3), 0, 0, gui_blu, gui_wht);
83 if (p4) gui_label(ld, hole_score(i, 4), 0, 0, gui_yel, gui_wht);
85 if ((kd = gui_varray(jd)))
88 if (p1) gui_label(kd, _("Par"), 0, GUI_NW, gui_wht, gui_wht);
89 if (p1) gui_label(kd, _("P1"), 0, GUI_SW * l1, gui_red, gui_wht);
90 if (p2) gui_label(kd, _("P2"), 0, GUI_SW * l2, gui_grn, gui_wht);
91 if (p3) gui_label(kd, _("P3"), 0, GUI_SW * l3, gui_blu, gui_wht);
92 if (p4) gui_label(kd, _("P4"), 0, GUI_SW * l4, gui_yel, gui_wht);
98 if ((jd = gui_hstack(id)))
100 if ((kd = gui_varray(jd)))
102 if (p1) gui_label(kd, _("Tot"), 0, GUI_TOP, 0, 0);
103 if (p1) gui_label(kd, hole_tot(0), 0, 0, gui_wht, gui_wht);
104 if (p1) gui_label(kd, hole_tot(1), 0, GUI_BOT * l1, gui_red, gui_wht);
105 if (p2) gui_label(kd, hole_tot(2), 0, GUI_BOT * l2, gui_grn, gui_wht);
106 if (p3) gui_label(kd, hole_tot(3), 0, GUI_BOT * l3, gui_blu, gui_wht);
107 if (p4) gui_label(kd, hole_tot(4), 0, GUI_BOT * l4, gui_yel, gui_wht);
109 if ((kd = gui_varray(jd)))
111 if (p1) gui_label(kd, _("I"), 0, GUI_NE, 0, 0);
112 if (p1) gui_label(kd, hole_in(0), 0, 0, gui_wht, gui_wht);
113 if (p1) gui_label(kd, hole_in(1), 0, GUI_SE * l1, gui_red, gui_wht);
114 if (p2) gui_label(kd, hole_in(2), 0, GUI_SE * l2, gui_grn, gui_wht);
115 if (p3) gui_label(kd, hole_in(3), 0, GUI_SE * l3, gui_blu, gui_wht);
116 if (p4) gui_label(kd, hole_in(4), 0, GUI_SE * l4, gui_yel, gui_wht);
118 if ((kd = gui_harray(jd)))
119 for (i = n; i > m; i--)
120 if ((ld = gui_varray(kd)))
122 if (p1) gui_label(ld, number(i), 0, (i == m+1) ? GUI_NW : 0, 0, 0);
123 if (p1) gui_label(ld, hole_score(i, 0), 0, 0, gui_wht, gui_wht);
124 if (p1) gui_label(ld, hole_score(i, 1), 0, 0, gui_red, gui_wht);
125 if (p2) gui_label(ld, hole_score(i, 2), 0, 0, gui_grn, gui_wht);
126 if (p3) gui_label(ld, hole_score(i, 3), 0, 0, gui_blu, gui_wht);
127 if (p4) gui_label(ld, hole_score(i, 4), 0, 0, gui_yel, gui_wht);
129 if ((kd = gui_varray(jd)))
132 if (p1) gui_label(kd, _("Par"), 0, GUI_NW, gui_wht, gui_wht);
133 if (p1) gui_label(kd, _("P1"), 0, GUI_SW * l1, gui_red, gui_wht);
134 if (p2) gui_label(kd, _("P2"), 0, GUI_SW * l2, gui_grn, gui_wht);
135 if (p3) gui_label(kd, _("P3"), 0, GUI_SW * l3, gui_blu, gui_wht);
136 if (p4) gui_label(kd, _("P4"), 0, GUI_SW * l4, gui_yel, gui_wht);
140 gui_layout(id, 0, 0);
146 /*---------------------------------------------------------------------------*/
152 static int title_action(int i)
154 audio_play(AUD_MENU, 1.0f);
158 case TITLE_PLAY: return goto_state(&st_course);
159 case TITLE_CONF: return goto_state(&st_conf);
160 case TITLE_EXIT: return 0;
165 static int title_enter(void)
169 /* Build the title GUI. */
171 if ((id = gui_vstack(0)))
173 gui_label(id, _("Neverputt"), GUI_LRG, GUI_ALL, 0, 0);
176 if ((jd = gui_harray(id)))
180 if ((kd = gui_varray(jd)))
182 gui_start(kd, _("Play"), GUI_MED, TITLE_PLAY, 1);
183 gui_state(kd, _("Options"), GUI_MED, TITLE_CONF, 0);
184 gui_state(kd, _("Exit"), GUI_MED, TITLE_EXIT, 0);
189 gui_layout(id, 0, 0);
198 static void title_leave(int id)
203 static void title_paint(int id, float st)
209 static void title_timer(int id, float dt)
211 float g[3] = { 0.f, 0.f, 0.f };
214 game_set_fly(fcosf(time_state() / 10.f));
220 static void title_point(int id, int x, int y, int dx, int dy)
222 gui_pulse(gui_point(id, x, y), 1.2f);
225 static int title_click(int b, int d)
227 return (d && b < 0) ? title_action(gui_token(gui_click())) : 1;
230 static int title_keybd(int c, int d)
232 return (d && c == SDLK_ESCAPE) ? 0 : 1;
235 /*---------------------------------------------------------------------------*/
239 static int course_action(int i)
241 if (course_exists(i))
244 goto_state(&st_party);
247 goto_state(&st_title);
252 static int course_enter(void)
254 int w = config_get_d(CONFIG_WIDTH);
255 int h = config_get_d(CONFIG_HEIGHT);
257 int id, jd, i, n = course_count(), m = n + 2;
259 if ((id = gui_vstack(0)))
261 gui_label(id, _("Select Course"), GUI_MED, GUI_ALL, 0, 0);
264 if ((jd = gui_hstack(id)))
267 for (i = n - 1; i >= 0; i--)
268 gui_active(gui_image(jd, course_shot(i), w / m, h / m), i, 0);
273 desc_id = gui_multi(id, _(course_desc(0)), GUI_SML, GUI_ALL, gui_yel, gui_wht);
276 if ((jd = gui_hstack(id)))
279 gui_state(jd, _("Back"), GUI_SML, -1, 0);
282 gui_layout(id, 0, 0);
285 audio_music_fade_to(0.5f, "bgm/inter.ogg");
290 static void course_leave(int id)
295 static void course_paint(int id, float st)
301 static void course_timer(int id, float dt)
307 static void course_point(int id, int x, int y, int dx, int dy)
311 if ((jd = gui_point(id, x, y)))
313 int i = gui_token(jd);
314 if (course_exists(i))
315 gui_set_multi(desc_id, _(course_desc(i)));
320 static int course_click(int b, int d)
322 return (d && b < 0) ? course_action(gui_token(gui_click())) : 1;
325 static int course_keybd(int c, int d)
327 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
330 /*---------------------------------------------------------------------------*/
339 static int party_action(int i)
344 audio_play(AUD_MENU, 1.f);
346 goto_state(&st_next);
349 audio_play(AUD_MENU, 1.f);
351 goto_state(&st_next);
354 audio_play(AUD_MENU, 1.f);
356 goto_state(&st_next);
359 audio_play(AUD_MENU, 1.f);
361 goto_state(&st_next);
364 audio_play(AUD_MENU, 1.f);
365 goto_state(&st_course);
371 static int party_enter(void)
375 if ((id = gui_vstack(0)))
377 gui_label(id, _("Players?"), GUI_MED, GUI_ALL, 0, 0);
380 if ((jd = gui_harray(id)))
382 int p4 = gui_state(jd, "4", GUI_LRG, PARTY_4, 0);
383 int p3 = gui_state(jd, "3", GUI_LRG, PARTY_3, 0);
384 int p2 = gui_state(jd, "2", GUI_LRG, PARTY_2, 0);
385 int p1 = gui_state(jd, "1", GUI_LRG, PARTY_1, 0);
387 gui_set_color(p1, gui_red, gui_wht);
388 gui_set_color(p2, gui_grn, gui_wht);
389 gui_set_color(p3, gui_blu, gui_wht);
390 gui_set_color(p4, gui_yel, gui_wht);
395 if ((jd = gui_hstack(id)))
398 gui_state(jd, _("Back"), GUI_SML, PARTY_B, 0);
401 gui_layout(id, 0, 0);
407 static void party_leave(int id)
412 static void party_paint(int id, float st)
418 static void party_timer(int id, float dt)
424 static void party_point(int id, int x, int y, int dx, int dy)
426 gui_pulse(gui_point(id, x, y), 1.2f);
429 static int party_click(int b, int d)
431 return (d && b < 0) ? party_action(gui_token(gui_click())) : 1;
434 static int party_keybd(int c, int d)
436 return (d && c == SDLK_ESCAPE) ? goto_state(&st_course) : 1;
439 /*---------------------------------------------------------------------------*/
443 static int next_enter(void)
448 sprintf(str, _("Hole %02d"), curr_hole());
450 if ((id = gui_vstack(0)))
452 gui_label(id, str, GUI_MED, GUI_ALL, 0, 0);
455 gui_label(id, _("Player"), GUI_SML, GUI_TOP, 0, 0);
457 switch (curr_player())
460 gui_label(id, "1", GUI_LRG, GUI_BOT, gui_red, gui_wht);
461 if (curr_party() > 1) audio_play(AUD_PLAYER1, 1.f);
464 gui_label(id, "2", GUI_LRG, GUI_BOT, gui_grn, gui_wht);
465 if (curr_party() > 1) audio_play(AUD_PLAYER2, 1.f);
468 gui_label(id, "3", GUI_LRG, GUI_BOT, gui_blu, gui_wht);
469 if (curr_party() > 1) audio_play(AUD_PLAYER3, 1.f);
472 gui_label(id, "4", GUI_LRG, GUI_BOT, gui_yel, gui_wht);
473 if (curr_party() > 1) audio_play(AUD_PLAYER4, 1.f);
476 gui_layout(id, 0, 0);
485 static void next_leave(int id)
491 static void next_paint(int id, float st)
498 static void next_timer(int id, float dt)
504 static void next_point(int id, int x, int y, int dx, int dy)
506 gui_pulse(gui_point(id, x, y), 1.2f);
509 static int next_click(int b, int d)
511 return (d && b < 0) ? goto_state(&st_flyby) : 1;
514 static int next_keybd(int c, int d)
519 return goto_state(&st_poser);
520 if (c == SDLK_ESCAPE)
521 return goto_state(&st_over);
522 if (c == SDLK_RETURN)
526 return goto_state(&st_next);
528 if ('0' <= c && c <= '9')
529 num = num * 10 + c - '0';
534 /*---------------------------------------------------------------------------*/
536 static int poser_enter(void)
542 static void poser_paint(int id, float st)
547 static int poser_keybd(int c, int d)
549 return (d && c == SDLK_ESCAPE) ? goto_state(&st_next) : 1;
552 /*---------------------------------------------------------------------------*/
554 static int flyby_enter(void)
560 static void flyby_leave(int id)
565 static void flyby_paint(int id, float st)
571 static void flyby_timer(int id, float dt)
573 float t = time_state();
575 if (dt > 0.f && t > 1.f)
576 goto_state(&st_stroke);
578 game_set_fly(1.f - t);
584 static int flyby_click(int b, int d)
589 return goto_state(&st_stroke);
594 static int flyby_keybd(int c, int d)
596 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
599 /*---------------------------------------------------------------------------*/
601 static int stroke_enter(void)
605 config_set_d(CONFIG_CAMERA, 2);
610 static void stroke_leave(int id)
614 config_set_d(CONFIG_CAMERA, 0);
617 static void stroke_paint(int id, float st)
623 static void stroke_timer(int id, float dt)
625 float g[3] = { 0.f, 0.f, 0.f };
627 game_update_view(dt);
632 static void stroke_point(int id, int x, int y, int dx, int dy)
638 static int stroke_click(int b, int d)
640 return (d && b < 0) ? goto_state(&st_roll) : 1;
643 static int stroke_keybd(int c, int d)
645 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
648 /*---------------------------------------------------------------------------*/
650 static int roll_enter(void)
657 static void roll_leave(int id)
662 static void roll_paint(int id, float st)
668 static void roll_timer(int id, float dt)
670 float g[3] = { 0.0f, -9.8f, 0.0f };
672 switch (game_step(g, dt))
674 case GAME_STOP: goto_state(&st_stop); break;
675 case GAME_GOAL: goto_state(&st_goal); break;
676 case GAME_FALL: goto_state(&st_fall); break;
681 static int roll_keybd(int c, int d)
683 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
686 /*---------------------------------------------------------------------------*/
688 static int goal_enter(void)
692 if ((id = gui_label(0, _("It's In!"), GUI_MED, GUI_ALL, gui_grn, gui_grn)))
693 gui_layout(id, 0, 0);
701 static void goal_leave(int id)
707 static void goal_paint(int id, float st)
714 static void goal_timer(int id, float dt)
716 if (time_state() > 3)
719 goto_state(&st_next);
721 goto_state(&st_score);
726 static int goal_click(int b, int d)
731 goto_state(&st_next);
733 goto_state(&st_score);
738 static int goal_keybd(int c, int d)
740 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
743 /*---------------------------------------------------------------------------*/
745 static int stop_enter(void)
752 static void stop_leave(int id)
757 static void stop_paint(int id, float st)
763 static void stop_timer(int id, float dt)
765 float g[3] = { 0.f, 0.f, 0.f };
767 game_update_view(dt);
771 if (time_state() > 1)
774 goto_state(&st_next);
776 goto_state(&st_score);
780 static int stop_click(int b, int d)
785 goto_state(&st_next);
787 goto_state(&st_score);
792 static int stop_keybd(int c, int d)
794 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
797 /*---------------------------------------------------------------------------*/
799 static int fall_enter(void)
803 if ((id = gui_label(0, _("1 Stroke Penalty"), GUI_MED, GUI_ALL, gui_blk, gui_red)))
804 gui_layout(id, 0, 0);
812 static void fall_leave(int id)
818 static void fall_paint(int id, float st)
825 static void fall_timer(int id, float dt)
827 if (time_state() > 3)
830 goto_state(&st_next);
832 goto_state(&st_score);
837 static int fall_click(int b, int d)
842 goto_state(&st_next);
844 goto_state(&st_score);
849 static int fall_keybd(int c, int d)
851 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
854 /*---------------------------------------------------------------------------*/
856 static int score_enter(void)
858 audio_music_fade_out(2.f);
859 return score_card(_("Scores"), gui_yel, gui_red);
862 static void score_leave(int id)
867 static void score_paint(int id, float st)
873 static void score_timer(int id, float dt)
879 static int score_click(int b, int d)
884 return goto_state(&st_next);
886 return goto_state(&st_title);
891 static int score_keybd(int c, int d)
893 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
896 /*---------------------------------------------------------------------------*/
898 static int over_enter(void)
900 audio_music_fade_out(2.f);
901 return score_card(_("Final Scores"), gui_yel, gui_red);
904 static void over_leave(int id)
909 static void over_paint(int id, float st)
915 static void over_timer(int id, float dt)
921 static int over_click(int b, int d)
923 return (d && b < 0) ? goto_state(&st_title) : 1;
926 static int over_keybd(int c, int d)
928 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
931 /*---------------------------------------------------------------------------*/
933 struct state st_title = {
946 struct state st_course = {
959 struct state st_party = {
972 struct state st_next = {
985 struct state st_poser = {
998 struct state st_flyby = {
1011 struct state st_stroke = {
1024 struct state st_roll = {
1037 struct state st_goal = {
1050 struct state st_stop = {
1063 struct state st_fall = {
1076 struct state st_score = {
1089 struct state st_over = {