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, sgettext("menu^Play"), GUI_MED, TITLE_PLAY, 1);
183 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
184 gui_state(kd, sgettext("menu^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 /*---------------------------------------------------------------------------*/
240 static int course_action(int i)
242 if (course_exists(i))
245 goto_state(&st_party);
248 goto_state(&st_title);
253 static int course_enter(void)
255 int w = config_get_d(CONFIG_WIDTH);
256 int h = config_get_d(CONFIG_HEIGHT);
258 int id, jd, kd, ld, i = 0, j, n = course_count();
259 int m = (int)(sqrt(n/2.0)*2);
261 if ((id = gui_vstack(0)))
263 gui_label(id, _("Select Course"), GUI_MED, GUI_ALL, 0, 0);
266 if ((jd = gui_hstack(id)))
268 shot_id = gui_image(jd, course_shot(0), w / 3, h / 3);
270 if ((kd = gui_varray(jd)))
272 for(i = 0; i < n; i += m)
274 if ((ld = gui_harray(kd)))
276 for (j = (m-1); j >= 0; j--)
279 gui_active(gui_image(ld, course_shot(i+j), w / 3 / m, h / 3 / m), i+j, 0);
289 desc_id = gui_multi(id, _(course_desc(0)), GUI_SML, GUI_ALL, gui_yel, gui_wht);
292 if ((jd = gui_hstack(id)))
295 gui_state(jd, _("Back"), GUI_SML, -1, 0);
298 gui_layout(id, 0, 0);
301 audio_music_fade_to(0.5f, "bgm/inter.ogg");
306 static void course_leave(int id)
311 static void course_paint(int id, float st)
317 static void course_timer(int id, float dt)
323 static void course_point(int id, int x, int y, int dx, int dy)
327 if ((jd = gui_point(id, x, y)))
329 int i = gui_token(jd);
330 if (course_exists(i))
332 gui_set_image(shot_id, course_shot(i));
333 gui_set_multi(desc_id, _(course_desc(i)));
339 static int course_click(int b, int d)
341 return (d && b < 0) ? course_action(gui_token(gui_click())) : 1;
344 static int course_keybd(int c, int d)
346 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
349 /*---------------------------------------------------------------------------*/
358 static int party_action(int i)
363 audio_play(AUD_MENU, 1.f);
365 goto_state(&st_next);
368 audio_play(AUD_MENU, 1.f);
370 goto_state(&st_next);
373 audio_play(AUD_MENU, 1.f);
375 goto_state(&st_next);
378 audio_play(AUD_MENU, 1.f);
380 goto_state(&st_next);
383 audio_play(AUD_MENU, 1.f);
384 goto_state(&st_course);
390 static int party_enter(void)
394 if ((id = gui_vstack(0)))
396 gui_label(id, _("Players?"), GUI_MED, GUI_ALL, 0, 0);
399 if ((jd = gui_harray(id)))
401 int p4 = gui_state(jd, "4", GUI_LRG, PARTY_4, 0);
402 int p3 = gui_state(jd, "3", GUI_LRG, PARTY_3, 0);
403 int p2 = gui_state(jd, "2", GUI_LRG, PARTY_2, 0);
404 int p1 = gui_state(jd, "1", GUI_LRG, PARTY_1, 0);
406 gui_set_color(p1, gui_red, gui_wht);
407 gui_set_color(p2, gui_grn, gui_wht);
408 gui_set_color(p3, gui_blu, gui_wht);
409 gui_set_color(p4, gui_yel, gui_wht);
414 if ((jd = gui_hstack(id)))
417 gui_state(jd, _("Back"), GUI_SML, PARTY_B, 0);
420 gui_layout(id, 0, 0);
426 static void party_leave(int id)
431 static void party_paint(int id, float st)
437 static void party_timer(int id, float dt)
443 static void party_point(int id, int x, int y, int dx, int dy)
445 gui_pulse(gui_point(id, x, y), 1.2f);
448 static int party_click(int b, int d)
450 return (d && b < 0) ? party_action(gui_token(gui_click())) : 1;
453 static int party_keybd(int c, int d)
455 return (d && c == SDLK_ESCAPE) ? goto_state(&st_course) : 1;
458 /*---------------------------------------------------------------------------*/
462 static int next_enter(void)
467 sprintf(str, _("Hole %02d"), curr_hole());
469 if ((id = gui_vstack(0)))
471 gui_label(id, str, GUI_MED, GUI_ALL, 0, 0);
474 gui_label(id, _("Player"), GUI_SML, GUI_TOP, 0, 0);
476 switch (curr_player())
479 gui_label(id, "1", GUI_LRG, GUI_BOT, gui_red, gui_wht);
480 if (curr_party() > 1) audio_play(AUD_PLAYER1, 1.f);
483 gui_label(id, "2", GUI_LRG, GUI_BOT, gui_grn, gui_wht);
484 if (curr_party() > 1) audio_play(AUD_PLAYER2, 1.f);
487 gui_label(id, "3", GUI_LRG, GUI_BOT, gui_blu, gui_wht);
488 if (curr_party() > 1) audio_play(AUD_PLAYER3, 1.f);
491 gui_label(id, "4", GUI_LRG, GUI_BOT, gui_yel, gui_wht);
492 if (curr_party() > 1) audio_play(AUD_PLAYER4, 1.f);
495 gui_layout(id, 0, 0);
504 static void next_leave(int id)
510 static void next_paint(int id, float st)
517 static void next_timer(int id, float dt)
523 static void next_point(int id, int x, int y, int dx, int dy)
525 gui_pulse(gui_point(id, x, y), 1.2f);
528 static int next_click(int b, int d)
530 return (d && b < 0) ? goto_state(&st_flyby) : 1;
533 static int next_keybd(int c, int d)
538 return goto_state(&st_poser);
539 if (c == SDLK_ESCAPE)
540 return goto_state(&st_over);
541 if (c == SDLK_RETURN)
545 return goto_state(&st_next);
547 if ('0' <= c && c <= '9')
548 num = num * 10 + c - '0';
553 /*---------------------------------------------------------------------------*/
555 static int poser_enter(void)
561 static void poser_paint(int id, float st)
566 static int poser_keybd(int c, int d)
568 return (d && c == SDLK_ESCAPE) ? goto_state(&st_next) : 1;
571 /*---------------------------------------------------------------------------*/
573 static int flyby_enter(void)
579 static void flyby_leave(int id)
584 static void flyby_paint(int id, float st)
590 static void flyby_timer(int id, float dt)
592 float t = time_state();
594 if (dt > 0.f && t > 1.f)
595 goto_state(&st_stroke);
597 game_set_fly(1.f - t);
603 static int flyby_click(int b, int d)
608 return goto_state(&st_stroke);
613 static int flyby_keybd(int c, int d)
615 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
618 /*---------------------------------------------------------------------------*/
620 static int stroke_enter(void)
624 config_set_d(CONFIG_CAMERA, 2);
629 static void stroke_leave(int id)
633 config_set_d(CONFIG_CAMERA, 0);
636 static void stroke_paint(int id, float st)
642 static void stroke_timer(int id, float dt)
644 float g[3] = { 0.f, 0.f, 0.f };
646 game_update_view(dt);
651 static void stroke_point(int id, int x, int y, int dx, int dy)
657 static int stroke_click(int b, int d)
659 return (d && b < 0) ? goto_state(&st_roll) : 1;
662 static int stroke_keybd(int c, int d)
664 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
667 /*---------------------------------------------------------------------------*/
669 static int roll_enter(void)
676 static void roll_leave(int id)
681 static void roll_paint(int id, float st)
687 static void roll_timer(int id, float dt)
689 float g[3] = { 0.0f, -9.8f, 0.0f };
691 switch (game_step(g, dt))
693 case GAME_STOP: goto_state(&st_stop); break;
694 case GAME_GOAL: goto_state(&st_goal); break;
695 case GAME_FALL: goto_state(&st_fall); break;
700 static int roll_keybd(int c, int d)
702 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
705 /*---------------------------------------------------------------------------*/
707 static int goal_enter(void)
711 if ((id = gui_label(0, _("It's In!"), GUI_MED, GUI_ALL, gui_grn, gui_grn)))
712 gui_layout(id, 0, 0);
720 static void goal_leave(int id)
726 static void goal_paint(int id, float st)
733 static void goal_timer(int id, float dt)
735 if (time_state() > 3)
738 goto_state(&st_next);
740 goto_state(&st_score);
745 static int goal_click(int b, int d)
750 goto_state(&st_next);
752 goto_state(&st_score);
757 static int goal_keybd(int c, int d)
759 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
762 /*---------------------------------------------------------------------------*/
764 static int stop_enter(void)
771 static void stop_leave(int id)
776 static void stop_paint(int id, float st)
782 static void stop_timer(int id, float dt)
784 float g[3] = { 0.f, 0.f, 0.f };
786 game_update_view(dt);
790 if (time_state() > 1)
793 goto_state(&st_next);
795 goto_state(&st_score);
799 static int stop_click(int b, int d)
804 goto_state(&st_next);
806 goto_state(&st_score);
811 static int stop_keybd(int c, int d)
813 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
816 /*---------------------------------------------------------------------------*/
818 static int fall_enter(void)
822 if ((id = gui_label(0, _("1 Stroke Penalty"), GUI_MED, GUI_ALL, gui_blk, gui_red)))
823 gui_layout(id, 0, 0);
831 static void fall_leave(int id)
837 static void fall_paint(int id, float st)
844 static void fall_timer(int id, float dt)
846 if (time_state() > 3)
849 goto_state(&st_next);
851 goto_state(&st_score);
856 static int fall_click(int b, int d)
861 goto_state(&st_next);
863 goto_state(&st_score);
868 static int fall_keybd(int c, int d)
870 return (d && c == SDLK_ESCAPE) ? goto_state(&st_over) : 1;
873 /*---------------------------------------------------------------------------*/
875 static int score_enter(void)
877 audio_music_fade_out(2.f);
878 return score_card(_("Scores"), gui_yel, gui_red);
881 static void score_leave(int id)
886 static void score_paint(int id, float st)
892 static void score_timer(int id, float dt)
898 static int score_click(int b, int d)
903 return goto_state(&st_next);
905 return goto_state(&st_title);
910 static int score_keybd(int c, int d)
912 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
915 /*---------------------------------------------------------------------------*/
917 static int over_enter(void)
919 audio_music_fade_out(2.f);
920 return score_card(_("Final Scores"), gui_yel, gui_red);
923 static void over_leave(int id)
928 static void over_paint(int id, float st)
934 static void over_timer(int id, float dt)
940 static int over_click(int b, int d)
942 return (d && b < 0) ? goto_state(&st_title) : 1;
945 static int over_keybd(int c, int d)
947 return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
950 /*---------------------------------------------------------------------------*/
952 struct state st_title = {
965 struct state st_course = {
978 struct state st_party = {
991 struct state st_next = {
1004 struct state st_poser = {
1017 struct state st_flyby = {
1030 struct state st_stroke = {
1043 struct state st_roll = {
1056 struct state st_goal = {
1069 struct state st_stop = {
1082 struct state st_fall = {
1095 struct state st_score = {
1108 struct state st_over = {