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];
47 sprintf(filename, "screen%02d.png", num++);
54 /*---------------------------------------------------------------------------*/
56 static void toggle_wire(void)
62 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
63 glEnable(GL_TEXTURE_2D);
64 glEnable(GL_LIGHTING);
69 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
70 glDisable(GL_TEXTURE_2D);
71 glDisable(GL_LIGHTING);
75 /*---------------------------------------------------------------------------*/
83 while (d && SDL_PollEvent(&e))
85 if (e.type == SDL_QUIT)
92 -e.motion.y + config_get_d(CONFIG_HEIGHT),
97 case SDL_MOUSEBUTTONDOWN:
98 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
101 case SDL_MOUSEBUTTONUP:
102 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
107 c = e.key.keysym.sym;
109 if (config_tst_d(CONFIG_KEY_FORWARD, c))
110 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
112 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
113 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
115 else if (config_tst_d(CONFIG_KEY_LEFT, c))
116 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
118 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
119 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
123 case SDLK_F10: d = shot(); break;
124 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
125 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
126 case SDLK_F7: toggle_wire(); break;
129 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
132 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
136 d = st_keybd(e.key.keysym.sym, 1);
142 c = e.key.keysym.sym;
144 /* gui_stick needs a non-null value, so we use 1 instead of 0. */
146 if (config_tst_d(CONFIG_KEY_FORWARD, c))
147 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
149 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
150 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
152 else if (config_tst_d(CONFIG_KEY_LEFT, c))
153 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
155 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
156 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
161 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
164 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
168 d = st_keybd(e.key.keysym.sym, 0);
171 case SDL_ACTIVEEVENT:
172 if (e.active.state == SDL_APPINPUTFOCUS)
174 if (e.active.gain == 0)
175 goto_pause(&st_over, 0);
179 case SDL_JOYAXISMOTION:
180 st_stick(e.jaxis.axis, e.jaxis.value);
183 case SDL_JOYBUTTONDOWN:
184 d = st_buttn(e.jbutton.button, 1);
187 case SDL_JOYBUTTONUP:
188 d = st_buttn(e.jbutton.button, 0);
195 int main(int argc, char *argv[])
201 SDL_Joystick *joy = NULL;
203 srand((int) time(NULL));
205 lang_init("neverball", CONFIG_LOCALE);
207 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
209 if (config_user_path(NULL))
211 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
216 /* Cache Neverball's camera setting. */
218 camera = config_get_d(CONFIG_CAMERA);
220 /* Initialize the joystick. */
222 if (SDL_NumJoysticks() > 0)
224 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
227 SDL_JoystickEventState(SDL_ENABLE);
232 /* Initialize the audio. */
236 /* Require 16-bit double buffer with 16-bit depth buffer. */
238 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
239 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
240 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
241 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
242 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
245 if ((icon = load_surface("icon/neverputt.png")))
247 SDL_WM_SetIcon(icon, NULL);
249 SDL_FreeSurface(icon);
251 #endif /* __APPLE__ */
253 /* Initialize the video. */
255 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
256 config_get_d(CONFIG_WIDTH),
257 config_get_d(CONFIG_HEIGHT)))
259 int t1, t0 = SDL_GetTicks();
261 SDL_WM_SetCaption(TITLE, TITLE);
263 /* Run the main game loop. */
265 init_state(&st_null);
266 goto_state(&st_title);
269 if ((t1 = SDL_GetTicks()) > t0)
271 st_timer((t1 - t0) / 1000.f);
273 SDL_GL_SwapBuffers();
277 if (config_get_d(CONFIG_NICE))
281 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
283 /* Restore Neverball's camera setting. */
285 config_set_d(CONFIG_CAMERA, camera);
290 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
292 else fprintf(stderr, L_("Failure to establish config directory\n"));
294 else fprintf(stderr, L_("Failure to establish game data directory\n"));
299 /*---------------------------------------------------------------------------*/