2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL 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 /*---------------------------------------------------------------------------*/
18 #pragma comment(lib, "SDL_ttf.lib")
19 #pragma comment(lib, "SDL_mixer.lib")
20 #pragma comment(lib, "SDL_image.lib")
21 #pragma comment(lib, "SDL.lib")
22 #pragma comment(lib, "SDLmain.lib")
23 #pragma comment(lib, "opengl32.lib")
26 /*---------------------------------------------------------------------------*/
29 #include <SDL_image.h>
45 #define TITLE _("Neverball")
47 /*---------------------------------------------------------------------------*/
49 static void shot(void)
51 static char filename[MAXSTR];
54 sprintf(filename, "screen%02d.bmp", num++);
59 /*---------------------------------------------------------------------------*/
61 static void toggle_wire(void)
67 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
68 glEnable(GL_TEXTURE_2D);
69 glEnable(GL_LIGHTING);
74 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
75 glDisable(GL_TEXTURE_2D);
76 glDisable(GL_LIGHTING);
81 /*---------------------------------------------------------------------------*/
88 while (d && SDL_PollEvent(&e))
90 if (e.type == SDL_QUIT)
93 if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_SPACE)
96 if (!config_get_pause())
100 st_point(+e.motion.x,
104 -e.motion.y + config_get_d(CONFIG_HEIGHT),
107 config_get_d(CONFIG_MOUSE_INVERT)
108 ? +e.motion.yrel : -e.motion.yrel);
111 case SDL_MOUSEBUTTONDOWN:
112 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
115 case SDL_MOUSEBUTTONUP:
116 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
121 switch (e.key.keysym.sym)
123 case SDLK_F10: 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 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX);
135 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX);
138 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX);
141 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX);
145 d = st_keybd(e.key.keysym.sym, 1);
151 switch (e.key.keysym.sym)
154 d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0);
158 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1);
162 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
166 d = st_keybd(e.key.keysym.sym, 0);
171 case SDL_ACTIVEEVENT:
172 if (e.active.state == SDL_APPINPUTFOCUS)
173 if (e.active.gain == 0 && config_get_grab())
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[])
195 language_init("neverball", CONFIG_LOCALE);
197 if (config_data_path((argc > 1 ? argv[1] : NULL), SET_FILE))
199 if (config_user_path(NULL))
201 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK))
203 SDL_Joystick *joy = NULL;
208 /* Initialize the language. */
209 language_set(language_from_code(config_simple_get_s(CONFIG_LANG)));
211 /* Initialize the joystick. */
213 if (SDL_NumJoysticks() > 0)
215 joy=SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
217 SDL_JoystickEventState(SDL_ENABLE);
220 /* Initialize the audio. */
222 audio_bind(AUD_MENU, 3, "snd/menu.wav");
223 audio_bind(AUD_START, 1, "snd/select.ogg");
224 audio_bind(AUD_READY, 1, "snd/ready.ogg");
225 audio_bind(AUD_SET, 1, "snd/set.ogg");
226 audio_bind(AUD_GO, 1, "snd/go.ogg");
227 audio_bind(AUD_BALL, 2, "snd/ball.ogg");
228 audio_bind(AUD_BUMP, 3, "snd/bump.ogg");
229 audio_bind(AUD_COIN, 2, "snd/coin.wav");
230 audio_bind(AUD_TICK, 4, "snd/tick.ogg");
231 audio_bind(AUD_TOCK, 4, "snd/tock.ogg");
232 audio_bind(AUD_SWITCH, 5, "snd/switch.wav");
233 audio_bind(AUD_JUMP, 5, "snd/jump.ogg");
234 audio_bind(AUD_GOAL, 5, "snd/goal.wav");
235 audio_bind(AUD_SCORE, 1, "snd/record.ogg");
236 audio_bind(AUD_FALL, 1, "snd/fall.ogg");
237 audio_bind(AUD_TIME, 1, "snd/time.ogg");
238 audio_bind(AUD_OVER, 1, "snd/over.ogg");
242 /* Require 16-bit double buffer with 16-bit depth buffer. */
244 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
245 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
246 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
247 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
248 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
250 /* Initialize the video. */
252 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
253 config_get_d(CONFIG_WIDTH),
254 config_get_d(CONFIG_HEIGHT)))
256 int t1, t0 = SDL_GetTicks();
258 SDL_Surface *icon = IMG_Load(config_data("icon/neverball.png"));
259 SDL_WM_SetIcon(icon, NULL);
260 SDL_WM_SetCaption(TITLE, TITLE);
262 /* Initialize the run state and the title display. */
264 init_state(&st_null);
265 goto_state(&st_title);
267 /* Run the main game loop. */
270 if ((t1 = SDL_GetTicks()) > t0)
272 if (config_get_pause())
279 st_timer((t1 - t0) / 1000.f);
282 SDL_GL_SwapBuffers();
286 if (config_get_d(CONFIG_NICE))
290 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
294 if (SDL_JoystickOpened(0))
295 SDL_JoystickClose(joy);
299 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
301 else fprintf(stderr, "Failure to establish config directory\n");
303 else fprintf(stderr, "Failure to establish game data directory\n");
308 /*---------------------------------------------------------------------------*/