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));
51 /*---------------------------------------------------------------------------*/
53 static void toggle_wire(void)
59 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
60 glEnable(GL_TEXTURE_2D);
61 glEnable(GL_LIGHTING);
66 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
67 glDisable(GL_TEXTURE_2D);
68 glDisable(GL_LIGHTING);
72 /*---------------------------------------------------------------------------*/
80 while (d && SDL_PollEvent(&e))
82 if (e.type == SDL_QUIT)
89 -e.motion.y + config_get_d(CONFIG_HEIGHT),
94 case SDL_MOUSEBUTTONDOWN:
95 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
98 case SDL_MOUSEBUTTONUP:
99 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
104 c = e.key.keysym.sym;
106 if (config_tst_d(CONFIG_KEY_FORWARD, c))
107 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
109 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
110 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
112 else if (config_tst_d(CONFIG_KEY_LEFT, c))
113 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
115 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
116 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
120 case SDLK_F10: d = shot(); break;
121 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
122 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
123 case SDLK_F7: toggle_wire(); break;
126 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
129 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
133 d = st_keybd(e.key.keysym.sym, 1);
139 c = e.key.keysym.sym;
141 /* gui_stick needs a non-null value, so we use 1 instead of 0. */
143 if (config_tst_d(CONFIG_KEY_FORWARD, c))
144 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
146 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
147 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
149 else if (config_tst_d(CONFIG_KEY_LEFT, c))
150 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
152 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
153 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
158 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
161 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
165 d = st_keybd(e.key.keysym.sym, 0);
168 case SDL_ACTIVEEVENT:
169 if (e.active.state == SDL_APPINPUTFOCUS)
170 if (e.active.gain == 0 && config_get_grab())
171 goto_pause(&st_over, 0);
174 case SDL_JOYAXISMOTION:
175 st_stick(e.jaxis.axis, e.jaxis.value);
178 case SDL_JOYBUTTONDOWN:
179 d = st_buttn(e.jbutton.button, 1);
182 case SDL_JOYBUTTONUP:
183 d = st_buttn(e.jbutton.button, 0);
190 int main(int argc, char *argv[])
196 SDL_Joystick *joy = NULL;
198 srand((int) time(NULL));
200 lang_init("neverball", CONFIG_LOCALE);
202 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
204 if (config_user_path(NULL))
206 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
211 /* Cache Neverball's camera setting. */
213 camera = config_get_d(CONFIG_CAMERA);
215 /* Initialize the joystick. */
217 if (SDL_NumJoysticks() > 0)
219 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
222 SDL_JoystickEventState(SDL_ENABLE);
227 /* Initialize the audio. */
231 /* Require 16-bit double buffer with 16-bit depth buffer. */
233 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
234 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
235 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
236 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
237 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
240 if ((icon = load_surface("icon/neverputt.png")))
242 SDL_WM_SetIcon(icon, NULL);
244 SDL_FreeSurface(icon);
246 #endif /* __APPLE__ */
248 /* Initialize the video. */
250 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
251 config_get_d(CONFIG_WIDTH),
252 config_get_d(CONFIG_HEIGHT)))
254 int t1, t0 = SDL_GetTicks();
256 SDL_WM_SetCaption(TITLE, TITLE);
258 /* Run the main game loop. */
260 init_state(&st_null);
261 goto_state(&st_title);
264 if ((t1 = SDL_GetTicks()) > t0)
266 st_timer((t1 - t0) / 1000.f);
267 st_paint(0.001f * t1);
268 SDL_GL_SwapBuffers();
272 if (config_get_d(CONFIG_NICE))
276 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
278 /* Restore Neverball's camera setting. */
280 config_set_d(CONFIG_CAMERA, camera);
285 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
287 else fprintf(stderr, L_("Failure to establish config directory\n"));
289 else fprintf(stderr, L_("Failure to establish game data directory\n"));
294 /*---------------------------------------------------------------------------*/