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 /*---------------------------------------------------------------------------*/
44 #define TITLE "Neverball"
46 /*---------------------------------------------------------------------------*/
48 static void shot(void)
50 static char filename
[MAXSTR
];
53 sprintf(filename
, "screen%02d.bmp", num
++);
58 /*---------------------------------------------------------------------------*/
60 static void toggle_wire(void)
66 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
67 glEnable(GL_TEXTURE_2D
);
68 glEnable(GL_LIGHTING
);
73 glPolygonMode(GL_FRONT_AND_BACK
, GL_LINE
);
74 glDisable(GL_TEXTURE_2D
);
75 glDisable(GL_LIGHTING
);
80 /*---------------------------------------------------------------------------*/
87 while (d
&& SDL_PollEvent(&e
))
89 if (e
.type
== SDL_QUIT
)
92 if (e
.type
== SDL_KEYDOWN
&& e
.key
.keysym
.sym
== SDLK_SPACE
)
95 if (!config_get_pause())
103 -e
.motion
.y
+ config_get_d(CONFIG_HEIGHT
),
106 config_get_d(CONFIG_MOUSE_INVERT
)
107 ? +e
.motion
.yrel
: -e
.motion
.yrel
);
110 case SDL_MOUSEBUTTONDOWN
:
111 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 1);
114 case SDL_MOUSEBUTTONUP
:
115 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 0);
120 switch (e
.key
.keysym
.sym
)
122 case SDLK_F10
: 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 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), -JOY_MAX
);
134 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), +JOY_MAX
);
137 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), -JOY_MAX
);
140 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), +JOY_MAX
);
144 d
= st_keybd(e
.key
.keysym
.sym
, 1);
150 switch (e
.key
.keysym
.sym
)
153 d
= st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A
), 0);
157 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), 1);
161 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), 1);
165 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 && config_get_grab())
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
[])
194 if (config_data_path((argc
> 1 ? argv
[1] : NULL
), SET_FILE
))
196 if (config_user_path(NULL
))
198 if (!SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_AUDIO
| SDL_INIT_JOYSTICK
))
200 SDL_Joystick
*joy
= NULL
;
205 /* Initialize the joystick. */
207 if (SDL_NumJoysticks() > 0)
209 joy
=SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE
));
211 SDL_JoystickEventState(SDL_ENABLE
);
214 /* Initialize the audio. */
216 audio_bind(AUD_MENU
, 3, "snd/menu.wav");
217 audio_bind(AUD_START
, 1, "snd/select.ogg");
218 audio_bind(AUD_READY
, 1, "snd/ready.ogg");
219 audio_bind(AUD_SET
, 1, "snd/set.ogg");
220 audio_bind(AUD_GO
, 1, "snd/go.ogg");
221 audio_bind(AUD_BALL
, 2, "snd/ball.ogg");
222 audio_bind(AUD_BUMP
, 3, "snd/bump.ogg");
223 audio_bind(AUD_COIN
, 2, "snd/coin.wav");
224 audio_bind(AUD_TICK
, 4, "snd/tick.ogg");
225 audio_bind(AUD_TOCK
, 4, "snd/tock.ogg");
226 audio_bind(AUD_SWITCH
, 5, "snd/switch.wav");
227 audio_bind(AUD_JUMP
, 5, "snd/jump.ogg");
228 audio_bind(AUD_GOAL
, 5, "snd/goal.wav");
229 audio_bind(AUD_SCORE
, 1, "snd/record.ogg");
230 audio_bind(AUD_FALL
, 1, "snd/fall.ogg");
231 audio_bind(AUD_TIME
, 1, "snd/time.ogg");
232 audio_bind(AUD_OVER
, 1, "snd/over.ogg");
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);
244 /* Initialize the video. */
246 if (config_mode(config_get_d(CONFIG_FULLSCREEN
),
247 config_get_d(CONFIG_WIDTH
),
248 config_get_d(CONFIG_HEIGHT
)))
250 int t1
, t0
= SDL_GetTicks();
252 SDL_WM_SetCaption(TITLE
, TITLE
);
254 /* Initialize the run state and the title display. */
256 init_state(&st_null
);
257 goto_state(&st_title
);
259 /* Run the main game loop. */
262 if ((t1
= SDL_GetTicks()) > t0
)
264 if (config_get_pause())
271 st_timer((t1
- t0
) / 1000.f
);
274 SDL_GL_SwapBuffers();
278 if (config_get_d(CONFIG_NICE
))
282 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
286 if (SDL_JoystickOpened(0))
287 SDL_JoystickClose(joy
);
291 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
293 else fprintf(stderr
, "Failure to establish config directory\n");
295 else fprintf(stderr
, "Failure to establish game data directory\n");
300 /*---------------------------------------------------------------------------*/