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.
15 /*---------------------------------------------------------------------------*/
19 #include <SDL_mixer.h>
20 #include <SDL_image.h>
41 #define TITLE "Neverputt"
43 /*---------------------------------------------------------------------------*/
47 static char filename[MAXSTR];
50 sprintf(filename, "screen%02d.png", num++);
57 /*---------------------------------------------------------------------------*/
59 static void toggle_wire(void)
65 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
66 glEnable(GL_TEXTURE_2D);
67 glEnable(GL_LIGHTING);
72 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
73 glDisable(GL_TEXTURE_2D);
74 glDisable(GL_LIGHTING);
78 /*---------------------------------------------------------------------------*/
86 while (d && SDL_PollEvent(&e))
88 if (e.type == SDL_QUIT)
95 -e.motion.y + config_get_d(CONFIG_HEIGHT),
100 case SDL_MOUSEBUTTONDOWN:
101 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
104 case SDL_MOUSEBUTTONUP:
105 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
110 c = e.key.keysym.sym;
112 if (config_tst_d(CONFIG_KEY_FORWARD, c))
113 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
115 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
116 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
118 else if (config_tst_d(CONFIG_KEY_LEFT, c))
119 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
121 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
122 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
126 case SDLK_F10: d = shot(); break;
127 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
128 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
129 case SDLK_F7: toggle_wire(); break;
132 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
135 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
139 d = st_keybd(e.key.keysym.sym, 1);
145 c = e.key.keysym.sym;
147 /* gui_stick needs a non-null value, so we use 1 instead of 0. */
149 if (config_tst_d(CONFIG_KEY_FORWARD, c))
150 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
152 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
153 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
155 else if (config_tst_d(CONFIG_KEY_LEFT, c))
156 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
158 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
159 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
164 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
167 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
171 d = st_keybd(e.key.keysym.sym, 0);
174 case SDL_ACTIVEEVENT:
175 if (e.active.state == SDL_APPINPUTFOCUS)
177 if (e.active.gain == 0)
178 goto_pause(&st_over, 0);
182 case SDL_JOYAXISMOTION:
183 st_stick(e.jaxis.axis, e.jaxis.value);
186 case SDL_JOYBUTTONDOWN:
187 d = st_buttn(e.jbutton.button, 1);
190 case SDL_JOYBUTTONUP:
191 d = st_buttn(e.jbutton.button, 0);
198 int main(int argc, char *argv[])
202 SDL_Joystick *joy = NULL;
204 srand((int) time(NULL));
206 lang_init("neverball", CONFIG_LOCALE);
208 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
210 if (config_user_path(NULL))
212 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
217 /* Cache Neverball's camera setting. */
219 camera = config_get_d(CONFIG_CAMERA);
221 /* Initialize the joystick. */
223 if (SDL_NumJoysticks() > 0)
225 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
228 SDL_JoystickEventState(SDL_ENABLE);
233 /* Initialize the audio. */
235 audio_bind(AUD_BIRDIE, 1, "snd/birdie.ogg");
236 audio_bind(AUD_BOGEY, 1, "snd/bogey.ogg");
237 audio_bind(AUD_BUMP, 1, "snd/bink.wav");
238 audio_bind(AUD_DOUBLE, 1, "snd/double.ogg");
239 audio_bind(AUD_EAGLE, 1, "snd/eagle.ogg");
240 audio_bind(AUD_JUMP, 2, "snd/jump.ogg");
241 audio_bind(AUD_MENU, 2, "snd/menu.wav");
242 audio_bind(AUD_ONE, 1, "snd/one.ogg");
243 audio_bind(AUD_PAR, 1, "snd/par.ogg");
244 audio_bind(AUD_PENALTY, 1, "snd/penalty.ogg");
245 audio_bind(AUD_PLAYER1, 1, "snd/player1.ogg");
246 audio_bind(AUD_PLAYER2, 1, "snd/player2.ogg");
247 audio_bind(AUD_PLAYER3, 1, "snd/player3.ogg");
248 audio_bind(AUD_PLAYER4, 1, "snd/player4.ogg");
249 audio_bind(AUD_SWITCH, 2, "snd/switch.wav");
250 audio_bind(AUD_SUCCESS, 1, "snd/success.ogg");
254 /* Require 16-bit double buffer with 16-bit depth buffer. */
256 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
257 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
258 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
259 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
260 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
263 icon = IMG_Load(config_data("icon/neverputt.png"));
267 SDL_WM_SetIcon(icon, NULL);
268 SDL_FreeSurface(icon);
270 #endif /* __APPLE__ */
272 /* Initialize the video. */
274 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
275 config_get_d(CONFIG_WIDTH),
276 config_get_d(CONFIG_HEIGHT)))
278 int t1, t0 = SDL_GetTicks();
280 SDL_WM_SetCaption(TITLE, TITLE);
282 /* Run the main game loop. */
284 init_state(&st_null);
285 goto_state(&st_title);
288 if ((t1 = SDL_GetTicks()) > t0)
290 st_timer((t1 - t0) / 1000.f);
292 SDL_GL_SwapBuffers();
296 if (config_get_d(CONFIG_NICE))
300 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
302 /* Restore Neverball's camera setting. */
304 config_set_d(CONFIG_CAMERA, camera);
309 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
311 else fprintf(stderr, L_("Failure to establish config directory\n"));
313 else fprintf(stderr, L_("Failure to establish game data directory\n"));
318 /*---------------------------------------------------------------------------*/