Import from neverball-1.4.0.tar.gz
[neverball-archive.git] / ball / st_start.c
blob886ec9b5d45bd0918866be5c767f3912f3e3247f
1 /*
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.
15 #include "gui.h"
16 #include "set.h"
17 #include "util.h"
18 #include "game.h"
19 #include "level.h"
20 #include "audio.h"
21 #include "config.h"
23 #include "st_set.h"
24 #include "st_over.h"
25 #include "st_level.h"
26 #include "st_title.h"
28 /*---------------------------------------------------------------------------*/
30 #define START_BACK 0
32 static int shot_id;
34 /*---------------------------------------------------------------------------*/
36 /* Create a level selector button based upon its existence and status. */
38 static void gui_level(int id, char *text, int i)
40 int o = level_opened(i);
41 int e = level_exists(i);
43 if (o) gui_state(id, text, GUI_SML, i, 0);
44 else if (e) gui_label(id, text, GUI_SML, GUI_ALL, gui_yel, gui_red);
45 else gui_label(id, text, GUI_SML, GUI_ALL, gui_blk, gui_blk);
48 /*---------------------------------------------------------------------------*/
50 static int start_action(int i)
52 audio_play(AUD_MENU, 1.0f);
54 if (i == START_BACK)
55 return goto_state(&st_set);
57 if (level_opened(i))
59 if (level_play(USER_REPLAY_FILE, i))
60 return goto_state(&st_level);
61 else
63 set_free();
64 return goto_state(&st_title);
67 return 1;
70 static int start_enter(void)
72 int w = config_get_d(CONFIG_WIDTH);
73 int h = config_get_d(CONFIG_HEIGHT);
75 int id, jd, kd, ld;
77 if ((id = gui_vstack(0)))
79 if ((jd = gui_harray(id)))
81 gui_label(jd, "Level", GUI_SML, GUI_ALL, gui_yel, gui_red);
82 gui_filler(jd);
83 gui_filler(jd);
84 gui_start(jd, "Back", GUI_SML, START_BACK, 0);
87 if ((jd = gui_harray(id)))
89 shot_id = gui_image(jd, "shot-rlk/easy.jpg", 7 * w / 16, 7 * h / 16);
91 if ((kd = gui_varray(jd)))
93 if ((ld = gui_harray(kd)))
95 gui_level(ld, "05", 5);
96 gui_level(ld, "04", 4);
97 gui_level(ld, "03", 3);
98 gui_level(ld, "02", 2);
99 gui_level(ld, "01", 1);
101 if ((ld = gui_harray(kd)))
103 gui_level(ld, "10", 10);
104 gui_level(ld, "09", 9);
105 gui_level(ld, "08", 8);
106 gui_level(ld, "07", 7);
107 gui_level(ld, "06", 6);
109 if ((ld = gui_harray(kd)))
111 gui_level(ld, "15", 15);
112 gui_level(ld, "14", 14);
113 gui_level(ld, "13", 13);
114 gui_level(ld, "12", 12);
115 gui_level(ld, "11", 11);
117 if ((ld = gui_harray(kd)))
119 gui_level(ld, "20", 20);
120 gui_level(ld, "19", 19);
121 gui_level(ld, "18", 18);
122 gui_level(ld, "17", 17);
123 gui_level(ld, "16", 16);
125 if ((ld = gui_harray(kd)))
127 gui_level(ld, "25", 25);
128 gui_level(ld, "24", 24);
129 gui_level(ld, "23", 23);
130 gui_level(ld, "22", 22);
131 gui_level(ld, "21", 21);
135 gui_space(id);
137 if ((jd = gui_harray(id)))
139 gui_most_coins(jd, 3, 4);
140 gui_best_times(jd, 3, 4);
143 gui_layout(id, 0, 0);
144 set_most_coins(0, 3);
145 set_best_times(0, 3);
148 return id;
151 static void start_leave(int id)
153 gui_delete(id);
156 static void start_paint(int id, float st)
158 game_draw(0, st);
159 config_pop_matrix();
160 gui_paint(id);
163 static void start_timer(int id, float dt)
165 gui_timer(id, dt);
166 audio_timer(dt);
169 static void start_point(int id, int x, int y, int dx, int dy)
171 int jd;
173 if ((jd = gui_point(id, x, y)))
175 int i = gui_token(jd);
177 gui_set_image(shot_id, level_shot(i));
179 set_most_coins(i, 3);
180 set_best_times(i, 3);
182 gui_pulse(jd, 1.2f);
186 static void start_stick(int id, int a, int v)
188 int jd;
190 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
191 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
193 if ((jd = gui_stick(id, x, y)))
195 int i = gui_token(jd);
197 gui_set_image(shot_id, level_shot(i));
199 set_most_coins(i, 3);
200 set_best_times(i, 3);
202 gui_pulse(jd, 1.2f);
206 static int start_click(int b, int d)
208 if (d && b < 0)
209 return start_action(gui_token(gui_click()));
210 return 1;
213 static int start_keybd(int c, int d)
215 if (d && c == SDLK_ESCAPE)
216 return goto_state(&st_title);
218 if (d && c == SDLK_F12)
220 int n = curr_count();
221 int i;
223 /* Iterate over all levels, taking a screenshot of each. */
225 for (i = 1; i < n; i++)
226 if (level_exists(i))
227 level_snap(i);
230 return 1;
233 static int start_buttn(int b, int d)
235 if (d)
237 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
238 return start_action(gui_token(gui_click()));
239 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
240 return goto_state(&st_title);
241 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
242 return goto_state(&st_title);
244 return 1;
247 /*---------------------------------------------------------------------------*/
249 struct state st_start = {
250 start_enter,
251 start_leave,
252 start_paint,
253 start_timer,
254 start_point,
255 start_stick,
256 start_click,
257 start_keybd,
258 start_buttn,
259 1, 0