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 /*---------------------------------------------------------------------------*/
44 static int shot_pending;
46 static void shot_prep(void)
51 static void shot_take(void)
53 static char filename[MAXSTR];
57 sprintf(filename, "Screenshots/screen%05d.png", config_screenshot());
63 /*---------------------------------------------------------------------------*/
65 static void toggle_wire(void)
72 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
73 glEnable(GL_TEXTURE_2D);
74 glEnable(GL_LIGHTING);
79 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
80 glDisable(GL_TEXTURE_2D);
81 glDisable(GL_LIGHTING);
86 /*---------------------------------------------------------------------------*/
94 while (d && SDL_PollEvent(&e))
96 if (e.type == SDL_QUIT)
101 case SDL_MOUSEMOTION:
102 st_point(+e.motion.x,
103 -e.motion.y + config_get_d(CONFIG_HEIGHT),
108 case SDL_MOUSEBUTTONDOWN:
109 d = st_click(e.button.button, 1);
112 case SDL_MOUSEBUTTONUP:
113 d = st_click(e.button.button, 0);
118 c = e.key.keysym.sym;
120 if (config_tst_d(CONFIG_KEY_FORWARD, c))
121 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -1.0f);
123 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
124 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +1.0f);
126 else if (config_tst_d(CONFIG_KEY_LEFT, c))
127 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -1.0f);
129 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
130 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +1.0f);
134 case SDLK_F10: shot_prep(); break;
135 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
136 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
137 case SDLK_F7: toggle_wire(); break;
140 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
143 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1);
147 d = st_keybd(e.key.keysym.sym, 1);
153 c = e.key.keysym.sym;
155 if (config_tst_d(CONFIG_KEY_FORWARD, c))
156 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
158 else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
159 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 0.0f);
161 else if (config_tst_d(CONFIG_KEY_LEFT, c))
162 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
164 else if (config_tst_d(CONFIG_KEY_RIGHT, c))
165 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 0.0f);
170 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
173 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0);
177 d = st_keybd(e.key.keysym.sym, 0);
181 case SDL_ACTIVEEVENT:
182 if (e.active.state == SDL_APPINPUTFOCUS)
183 if (e.active.gain == 0 && video_get_grab())
184 goto_pause(&st_over, 0);
187 case SDL_JOYAXISMOTION:
188 st_stick(e.jaxis.axis, JOY_VALUE(e.jaxis.value));
191 case SDL_JOYBUTTONDOWN:
192 d = st_buttn(e.jbutton.button, 1);
195 case SDL_JOYBUTTONUP:
196 d = st_buttn(e.jbutton.button, 0);
203 int main(int argc, char *argv[])
206 SDL_Joystick *joy = NULL;
208 if (!fs_init(argv[0]))
210 fprintf(stderr, "Failure to initialize virtual file system: %s\n",
215 srand((int) time(NULL));
217 lang_init("neverball");
218 config_paths(argc > 1 ? argv[1] : NULL);
219 fs_mkdir("Screenshots");
221 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
226 /* Cache Neverball's camera setting. */
228 camera = config_get_d(CONFIG_CAMERA);
230 /* Initialize the joystick. */
232 if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
234 joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
237 SDL_JoystickEventState(SDL_ENABLE);
242 /* Initialize the audio. */
246 /* Initialize the video. */
248 if (video_init(TITLE, ICON))
250 int t1, t0 = SDL_GetTicks();
252 /* Run the main game loop. */
254 init_state(&st_null);
255 goto_state(&st_title);
258 if ((t1 = SDL_GetTicks()) > t0)
260 st_timer((t1 - t0) / 1000.f);
261 st_paint(0.001f * t1);
263 SDL_GL_SwapBuffers();
267 if (config_get_d(CONFIG_NICE))
272 /* Restore Neverball's camera setting. */
274 config_set_d(CONFIG_CAMERA, camera);
279 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
284 /*---------------------------------------------------------------------------*/