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 /*---------------------------------------------------------------------------*/
39 const char TITLE[] = "Neverputt " VERSION;
40 const char ICON[] = "icon/neverputt.png";
42 /*---------------------------------------------------------------------------*/
46 static char filename[MAXSTR];
48 sprintf(filename, "Screenshots/screen%05d.png", config_screenshot());
53 /*---------------------------------------------------------------------------*/
55 static void toggle_wire(void)
61 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
62 glEnable(GL_TEXTURE_2D);
63 glEnable(GL_LIGHTING);
68 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
69 glDisable(GL_TEXTURE_2D);
70 glDisable(GL_LIGHTING);
74 /*---------------------------------------------------------------------------*/
82 while (d && SDL_PollEvent(&e))
84 if (e.type == SDL_QUIT)
91 -e.motion.y + config_get_d(CONFIG_HEIGHT),
96 case SDL_MOUSEBUTTONDOWN:
97 d = st_click(e.button.button, 1);
100 case SDL_MOUSEBUTTONUP:
101 d = st_click(e.button.button, 0);
106 c = e.key.keysym.sym;
108 if (config_tst_d(CONFIG_KEY_FORWARD, c))
109 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
111 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
112 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
114 else if (config_tst_d(CONFIG_KEY_LEFT, c))
115 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
117 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
118 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
122 case SDLK_F10: d = shot(); break;
123 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
124 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
125 case SDLK_F7: toggle_wire(); break;
128 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
131 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
135 d = st_keybd(e.key.keysym.sym, 1);
141 c = e.key.keysym.sym;
143 /* gui_stick needs a non-null value, so we use 1 instead of 0. */
145 if (config_tst_d(CONFIG_KEY_FORWARD, c))
146 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
148 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
149 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
151 else if (config_tst_d(CONFIG_KEY_LEFT, c))
152 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
154 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
155 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
160 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
163 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
167 d = st_keybd(e.key.keysym.sym, 0);
170 case SDL_ACTIVEEVENT:
171 if (e.active.state == SDL_APPINPUTFOCUS)
172 if (e.active.gain == 0 && video_get_grab())
173 goto_pause(&st_over, 0);
176 case SDL_JOYAXISMOTION:
177 st_stick(e.jaxis.axis, e.jaxis.value);
180 case SDL_JOYBUTTONDOWN:
181 d = st_buttn(e.jbutton.button, 1);
184 case SDL_JOYBUTTONUP:
185 d = st_buttn(e.jbutton.button, 0);
192 int main(int argc, char *argv[])
195 SDL_Joystick *joy = NULL;
198 if (!fs_init(argv[0]))
200 fputs("Failure to initialize virtual file system\n", stderr);
204 srand((int) time(NULL));
206 lang_init("neverball");
207 config_paths(argc > 1 ? argv[1] : NULL);
208 fs_mkdir("Screenshots");
210 flags |= SDL_INIT_VIDEO;
211 flags |= SDL_INIT_AUDIO;
212 flags |= config_get_d(CONFIG_JOYSTICK) ? SDL_INIT_JOYSTICK : 0;
214 if (SDL_Init(flags) == 0)
219 /* Cache Neverball's camera setting. */
221 camera = config_get_d(CONFIG_CAMERA);
223 /* Initialize the joystick. */
225 if (SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_NumJoysticks() > 0)
227 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
230 SDL_JoystickEventState(SDL_ENABLE);
235 /* Initialize the audio. */
239 /* Initialize the video. */
241 if (video_init(TITLE, ICON))
243 int t1, t0 = SDL_GetTicks();
245 /* Run the main game loop. */
247 init_state(&st_null);
248 goto_state(&st_title);
251 if ((t1 = SDL_GetTicks()) > t0)
253 st_timer((t1 - t0) / 1000.f);
254 st_paint(0.001f * t1);
255 SDL_GL_SwapBuffers();
259 if (config_get_d(CONFIG_NICE))
264 /* Restore Neverball's camera setting. */
266 config_set_d(CONFIG_CAMERA, camera);
271 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
276 /*---------------------------------------------------------------------------*/