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, "glu32.lib")
24 #pragma comment(lib, "opengl32.lib")
27 /*---------------------------------------------------------------------------*/
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())
100 -e
.motion
.y
+ config_get_d(CONFIG_HEIGHT
),
102 config_get_d(CONFIG_MOUSE_INVERT
)
103 ? +e
.motion
.yrel
: -e
.motion
.yrel
);
106 case SDL_MOUSEBUTTONDOWN
:
107 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 1);
110 case SDL_MOUSEBUTTONUP
:
111 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 0);
116 switch (e
.key
.keysym
.sym
)
118 case SDLK_F10
: shot(); break;
119 case SDLK_F9
: config_tgl_d(CONFIG_FPS
); break;
120 case SDLK_F8
: config_tgl_d(CONFIG_NICE
); break;
121 case SDLK_F7
: toggle_wire(); break;
124 d
= st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A
), 1);
127 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), -JOY_MAX
);
130 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), +JOY_MAX
);
133 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), -JOY_MAX
);
136 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), +JOY_MAX
);
140 d
= st_keybd(e
.key
.keysym
.sym
, 1);
146 switch (e
.key
.keysym
.sym
)
149 d
= st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A
), 0);
153 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X
), 0);
157 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y
), 0);
161 d
= st_keybd(e
.key
.keysym
.sym
, 0);
166 case SDL_ACTIVEEVENT
:
167 if (e
.active
.state
== SDL_APPINPUTFOCUS
)
168 if (e
.active
.gain
== 0)
172 case SDL_JOYAXISMOTION
:
173 st_stick(e
.jaxis
.axis
, e
.jaxis
.value
);
176 case SDL_JOYBUTTONDOWN
:
177 d
= st_buttn(e
.jbutton
.button
, 1);
180 case SDL_JOYBUTTONUP
:
181 d
= st_buttn(e
.jbutton
.button
, 0);
188 int main(int argc
, char *argv
[])
190 if (config_data_path((argc
> 1 ? argv
[1] : NULL
), SET_FILE
))
192 if (config_user_path(NULL
))
194 if (!SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_AUDIO
| SDL_INIT_JOYSTICK
))
196 SDL_Joystick
*joy
= NULL
;
201 /* Initialize the joystick. */
203 if (SDL_NumJoysticks() > 0)
205 joy
=SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE
));
207 SDL_JoystickEventState(SDL_ENABLE
);
210 /* Initialize the audio. */
214 /* Require 16-bit double buffer with 16-bit depth buffer. */
216 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 5);
217 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 5);
218 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 5);
219 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
220 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
222 /* Initialize the video. */
224 if (config_mode(config_get_d(CONFIG_FULLSCREEN
),
225 config_get_d(CONFIG_WIDTH
),
226 config_get_d(CONFIG_HEIGHT
)))
228 int t1
, t0
= SDL_GetTicks();
230 SDL_WM_SetCaption(TITLE
, TITLE
);
232 /* Initialize the run state and the title display. */
234 init_state(&st_null
);
235 goto_state(&st_title
);
237 /* Run the main game loop. */
240 if ((t1
= SDL_GetTicks()) > t0
)
242 if (config_get_pause())
249 st_timer((t1
- t0
) / 1000.f
);
252 SDL_GL_SwapBuffers();
256 if (config_get_d(CONFIG_NICE
))
260 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
264 if (SDL_JoystickOpened(0))
265 SDL_JoystickClose(joy
);
269 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
271 else fprintf(stderr
, "Failure to establish config directory\n");
273 else fprintf(stderr
, "Failure to establish game data directory\n");
278 /*---------------------------------------------------------------------------*/