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 /*---------------------------------------------------------------------------*/
38 #define TITLE "Neverputt"
40 /*---------------------------------------------------------------------------*/
44 static char filename[MAXSTR];
46 sprintf(filename, "screen%05d.png", config_screenshot());
47 image_snap(config_user(filename));
52 /*---------------------------------------------------------------------------*/
54 static void toggle_wire(void)
60 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
61 glEnable(GL_TEXTURE_2D);
62 glEnable(GL_LIGHTING);
67 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
68 glDisable(GL_TEXTURE_2D);
69 glDisable(GL_LIGHTING);
73 /*---------------------------------------------------------------------------*/
81 while (d && SDL_PollEvent(&e))
83 if (e.type == SDL_QUIT)
90 -e.motion.y + config_get_d(CONFIG_HEIGHT),
95 case SDL_MOUSEBUTTONDOWN:
96 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
99 case SDL_MOUSEBUTTONUP:
100 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
105 c = e.key.keysym.sym;
107 if (config_tst_d(CONFIG_KEY_FORWARD, c))
108 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
110 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
111 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
113 else if (config_tst_d(CONFIG_KEY_LEFT, c))
114 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
116 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
117 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
121 case SDLK_F10: d = shot(); break;
122 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
123 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
124 case SDLK_F7: toggle_wire(); break;
127 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
130 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
134 d = st_keybd(e.key.keysym.sym, 1);
140 c = e.key.keysym.sym;
142 /* gui_stick needs a non-null value, so we use 1 instead of 0. */
144 if (config_tst_d(CONFIG_KEY_FORWARD, c))
145 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
147 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
148 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
150 else if (config_tst_d(CONFIG_KEY_LEFT, c))
151 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
153 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
154 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
159 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
162 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
166 d = st_keybd(e.key.keysym.sym, 0);
169 case SDL_ACTIVEEVENT:
170 if (e.active.state == SDL_APPINPUTFOCUS)
172 if (e.active.gain == 0)
173 goto_pause(&st_over, 0);
177 case SDL_JOYAXISMOTION:
178 st_stick(e.jaxis.axis, e.jaxis.value);
181 case SDL_JOYBUTTONDOWN:
182 d = st_buttn(e.jbutton.button, 1);
185 case SDL_JOYBUTTONUP:
186 d = st_buttn(e.jbutton.button, 0);
193 int main(int argc, char *argv[])
199 SDL_Joystick *joy = NULL;
201 srand((int) time(NULL));
203 lang_init("neverball", CONFIG_LOCALE);
205 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
207 if (config_user_path(NULL))
209 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
214 /* Cache Neverball's camera setting. */
216 camera = config_get_d(CONFIG_CAMERA);
218 /* Initialize the joystick. */
220 if (SDL_NumJoysticks() > 0)
222 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
225 SDL_JoystickEventState(SDL_ENABLE);
230 /* Initialize the audio. */
234 /* Require 16-bit double buffer with 16-bit depth buffer. */
236 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
237 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
238 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
239 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
240 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
243 if ((icon = load_surface("icon/neverputt.png")))
245 SDL_WM_SetIcon(icon, NULL);
247 SDL_FreeSurface(icon);
249 #endif /* __APPLE__ */
251 /* Initialize the video. */
253 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
254 config_get_d(CONFIG_WIDTH),
255 config_get_d(CONFIG_HEIGHT)))
257 int t1, t0 = SDL_GetTicks();
259 SDL_WM_SetCaption(TITLE, TITLE);
261 /* Run the main game loop. */
263 init_state(&st_null);
264 goto_state(&st_title);
267 if ((t1 = SDL_GetTicks()) > t0)
269 st_timer((t1 - t0) / 1000.f);
270 st_paint(0.001f * t1);
271 SDL_GL_SwapBuffers();
275 if (config_get_d(CONFIG_NICE))
279 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
281 /* Restore Neverball's camera setting. */
283 config_set_d(CONFIG_CAMERA, camera);
288 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
290 else fprintf(stderr, L_("Failure to establish config directory\n"));
292 else fprintf(stderr, L_("Failure to establish game data directory\n"));
297 /*---------------------------------------------------------------------------*/