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 /*---------------------------------------------------------------------------*/
19 #include <SDL_mixer.h>
20 #include <SDL_image.h>
40 #define TITLE "Neverputt"
42 /*---------------------------------------------------------------------------*/
46 static char filename[MAXSTR];
49 sprintf(filename, "screen%02d.png", num++);
56 /*---------------------------------------------------------------------------*/
58 static void toggle_wire(void)
64 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
65 glEnable(GL_TEXTURE_2D);
66 glEnable(GL_LIGHTING);
71 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
72 glDisable(GL_TEXTURE_2D);
73 glDisable(GL_LIGHTING);
77 /*---------------------------------------------------------------------------*/
84 while (d && SDL_PollEvent(&e))
86 if (e.type == SDL_QUIT)
93 -e.motion.y + config_get_d(CONFIG_HEIGHT),
98 case SDL_MOUSEBUTTONDOWN:
99 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 1);
102 case SDL_MOUSEBUTTONUP:
103 d = st_click((e.button.button == SDL_BUTTON_LEFT) ? -1 : 1, 0);
107 switch (e.key.keysym.sym)
109 case SDLK_F10: d = shot(); break;
110 case SDLK_F9: config_tgl_d(CONFIG_FPS); break;
111 case SDLK_F8: config_tgl_d(CONFIG_NICE); break;
112 case SDLK_F7: toggle_wire(); break;
115 d = st_keybd(e.key.keysym.sym, 1);
119 case SDL_ACTIVEEVENT:
120 if (e.active.state == SDL_APPINPUTFOCUS)
122 if (e.active.gain == 0)
123 goto_pause(&st_over, 0);
131 int main(int argc, char *argv[])
136 srand((int) time(NULL));
138 lang_init("neverball", CONFIG_LOCALE);
140 if (config_data_path((argc > 1 ? argv[1] : NULL), COURSE_FILE))
142 if (config_user_path(NULL))
144 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == 0)
149 /* Cache Neverball's camera setting. */
151 camera = config_get_d(CONFIG_CAMERA);
153 /* Initialize the audio. */
155 audio_bind(AUD_BIRDIE, 1, "snd/birdie.ogg");
156 audio_bind(AUD_BOGEY, 1, "snd/bogey.ogg");
157 audio_bind(AUD_BUMP, 1, "snd/bink.wav");
158 audio_bind(AUD_DOUBLE, 1, "snd/double.ogg");
159 audio_bind(AUD_EAGLE, 1, "snd/eagle.ogg");
160 audio_bind(AUD_JUMP, 2, "snd/jump.ogg");
161 audio_bind(AUD_MENU, 2, "snd/menu.wav");
162 audio_bind(AUD_ONE, 1, "snd/one.ogg");
163 audio_bind(AUD_PAR, 1, "snd/par.ogg");
164 audio_bind(AUD_PENALTY, 1, "snd/penalty.ogg");
165 audio_bind(AUD_PLAYER1, 1, "snd/player1.ogg");
166 audio_bind(AUD_PLAYER2, 1, "snd/player2.ogg");
167 audio_bind(AUD_PLAYER3, 1, "snd/player3.ogg");
168 audio_bind(AUD_PLAYER4, 1, "snd/player4.ogg");
169 audio_bind(AUD_SWITCH, 2, "snd/switch.wav");
170 audio_bind(AUD_SUCCESS, 1, "snd/success.ogg");
174 /* Require 16-bit double buffer with 16-bit depth buffer. */
176 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
177 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
178 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
179 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
180 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
183 icon = IMG_Load(config_data("icon/neverputt.png"));
187 SDL_WM_SetIcon(icon, NULL);
188 SDL_FreeSurface(icon);
190 #endif /* __APPLE__ */
192 /* Initialize the video. */
194 if (config_mode(config_get_d(CONFIG_FULLSCREEN),
195 config_get_d(CONFIG_WIDTH),
196 config_get_d(CONFIG_HEIGHT)))
198 int t1, t0 = SDL_GetTicks();
200 SDL_WM_SetCaption(TITLE, TITLE);
202 /* Run the main game loop. */
204 init_state(&st_null);
205 goto_state(&st_title);
208 if ((t1 = SDL_GetTicks()) > t0)
210 st_timer((t1 - t0) / 1000.f);
212 SDL_GL_SwapBuffers();
216 if (config_get_d(CONFIG_NICE))
220 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
222 /* Restore Neverball's camera setting. */
224 config_set_d(CONFIG_CAMERA, camera);
229 else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
231 else fprintf(stderr, _("Failure to establish config directory\n"));
233 else fprintf(stderr, _("Failure to establish game data directory\n"));
238 /*---------------------------------------------------------------------------*/