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>
31 #include <SDL_image.h>
51 #define TITLE _("Neverputt")
53 /*---------------------------------------------------------------------------*/
57 static char filename[MAXSTR];
60 sprintf(filename, "screen%02d.bmp", num++);
67 /*---------------------------------------------------------------------------*/
69 static void toggle_wire(void)
75 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
76 glEnable(GL_TEXTURE_2D);
77 glEnable(GL_LIGHTING);
82 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
83 glDisable(GL_TEXTURE_2D);
84 glDisable(GL_LIGHTING);
88 /*---------------------------------------------------------------------------*/
95 while (d && SDL_PollEvent(&e))
97 if (e.type == SDL_QUIT)
100 if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_SPACE)
103 if (!config_get_pause())
106 case SDL_MOUSEMOTION:
107 st_point(+e.motion.x,
111 -e.motion.y + config_get_d(CONFIG_HEIGHT),
117 case SDL_MOUSEBUTTONDOWN:
118 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
121 case SDL_MOUSEBUTTONUP:
122 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
126 switch (e.key.keysym.sym)
128 case SDLK_F10: d = shot(); break;
129 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
130 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
131 case SDLK_F7: toggle_wire(); break;
134 d = st_keybd(e.key.keysym.sym, 1);
138 case SDL_ACTIVEEVENT:
139 if (e.active.state == SDL_APPINPUTFOCUS)
141 if (e.active.gain == 0)
150 int main(int argc, char *argv[])
154 srand((int) time(NULL));
156 language_init("neverball", CONFIG_LOCALE);
158 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
160 if (config_user_path(NULL))
162 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == 0)
167 /* Initialize the language. */
169 language_set(language_from_code(config_simple_get_s(CONFIG_LANG)));
171 /* Cache Neverball's camera setting. */
173 camera = config_get_d(CONFIG_CAMERA);
175 /* Initialize the audio. */
177 audio_bind(AUD_BIRDIE, 1, "snd/birdie.ogg");
178 audio_bind(AUD_BOGEY, 1, "snd/bogey.ogg");
179 audio_bind(AUD_BUMP, 1, "snd/bink.wav");
180 audio_bind(AUD_DOUBLE, 1, "snd/double.ogg");
181 audio_bind(AUD_EAGLE, 1, "snd/eagle.ogg");
182 audio_bind(AUD_JUMP, 2, "snd/jump.ogg");
183 audio_bind(AUD_MENU, 2, "snd/menu.wav");
184 audio_bind(AUD_ONE, 1, "snd/one.ogg");
185 audio_bind(AUD_PAR, 1, "snd/par.ogg");
186 audio_bind(AUD_PENALTY, 1, "snd/penalty.ogg");
187 audio_bind(AUD_PLAYER1, 1, "snd/player1.ogg");
188 audio_bind(AUD_PLAYER2, 1, "snd/player2.ogg");
189 audio_bind(AUD_PLAYER3, 1, "snd/player3.ogg");
190 audio_bind(AUD_PLAYER4, 1, "snd/player4.ogg");
191 audio_bind(AUD_SWITCH, 2, "snd/switch.wav");
192 audio_bind(AUD_SUCCESS, 1, "snd/success.ogg");
196 /* Require 16-bit double buffer with 16-bit depth buffer. */
198 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
199 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
200 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
201 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
202 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
204 /* Initialize the video. */
206 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
207 config_get_d(CONFIG_WIDTH),
208 config_get_d(CONFIG_HEIGHT)))
210 int t1, t0 = SDL_GetTicks();
212 SDL_Surface *icon = IMG_Load(config_data("icon/neverputt.png"));
213 SDL_WM_SetIcon(icon, NULL);
214 SDL_WM_SetCaption(TITLE, TITLE);
216 /* Run the main game loop. */
218 init_state(&st_null);
219 goto_state(&st_title);
222 if ((t1 = SDL_GetTicks()) > t0)
224 if (config_get_pause())
231 st_timer((t1 - t0) / 1000.f);
234 SDL_GL_SwapBuffers();
238 if (config_get_d(CONFIG_NICE))
242 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
244 /* Restore Neverball's camera setting. */
246 config_set_d(CONFIG_CAMERA, camera);
251 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
253 else fprintf(stderr, _("Failure to establish config directory\n"));
255 else fprintf(stderr, _("Failure to establish game data directory\n"));
260 /*---------------------------------------------------------------------------*/