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 /*---------------------------------------------------------------------------*/
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 /*---------------------------------------------------------------------------*/
30 #include <SDL_mixer.h>
43 #define TITLE "Neverputt"
45 /*---------------------------------------------------------------------------*/
49 static char filename
[MAXSTR
];
52 sprintf(filename
, "screen%02d.bmp", num
++);
59 /*---------------------------------------------------------------------------*/
66 while (d
&& SDL_PollEvent(&e
))
68 if (e
.type
== SDL_QUIT
)
71 if (e
.type
== SDL_KEYDOWN
&& e
.key
.keysym
.sym
== SDLK_SPACE
)
74 if (!config_get_pause())
78 d
= st_point(+e
.motion
.x
,
79 -e
.motion
.y
+ config_get_d(CONFIG_HEIGHT
),
84 case SDL_MOUSEBUTTONDOWN
:
85 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 1);
88 case SDL_MOUSEBUTTONUP
:
89 d
= st_click((e
.button
.button
== SDL_BUTTON_LEFT
) ? -1 : 1, 0);
93 switch (e
.key
.keysym
.sym
)
95 case SDLK_F10
: d
= shot(); break;
96 case SDLK_F9
: config_tgl_d(CONFIG_FPS
); break;
97 case SDLK_F8
: config_tgl_d(CONFIG_NICE
); break;
100 d
= st_keybd(e
.key
.keysym
.sym
);
104 case SDL_ACTIVEEVENT
:
105 if (e
.active
.state
== SDL_APPINPUTFOCUS
)
107 if (e
.active
.gain
== 0)
116 int main(int argc
, char *argv
[])
120 if (config_data_path((argc
> 1 ? argv
[1] : NULL
), HOLE_FILE
))
122 if (config_user_path(NULL
))
124 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_AUDIO
) == 0)
129 /* Cache Neverball's camera setting. */
131 camera
= config_get_d(CONFIG_CAMERA
);
133 /* Initialize the audio. */
137 /* Require 16-bit double buffer with 16-bit depth buffer. */
139 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 5);
140 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 5);
141 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 5);
142 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
143 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
145 /* Initialize the video. */
147 if (config_mode(config_get_d(CONFIG_FULLSCREEN
),
148 config_get_d(CONFIG_WIDTH
),
149 config_get_d(CONFIG_HEIGHT
)))
151 int t1
, t0
= SDL_GetTicks();
153 SDL_WM_SetCaption(TITLE
, TITLE
);
155 /* Run the main game loop. */
157 goto_state(&st_title
);
160 if ((t1
= SDL_GetTicks()) > t0
)
162 if (!config_get_pause())
163 st_timer((t1
- t0
) / 1000.f
);
166 SDL_GL_SwapBuffers();
170 if (config_get_d(CONFIG_NICE
))
174 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
176 /* Restore Neverball's camera setting. */
178 config_set_d(CONFIG_CAMERA
, camera
);
183 else fprintf(stderr
, "%s: %s\n", argv
[0], SDL_GetError());
185 else fprintf(stderr
, "Failure to establish config directory\n");
187 else fprintf(stderr
, "Failure to establish game data directory\n");
192 /*---------------------------------------------------------------------------*/