/* * main.c * * Where it all begins * * (c) 2008 Thomas White * * thrust3d - a silly game * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "types.h" #include "model.h" #include "game.h" #include "render.h" #include "physics.h" int main(int argc, char *argv[]) { SDL_Event event; int finished; SDL_Surface *screen; /* SDL initial setup */ if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ) { fprintf(stderr, "Couldn't initialise SDL: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); screen = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL); if (screen == NULL) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("Thrust3D", "Thrust3D"); /* World setup */ Game *game; game = game_new(); /* Main loop */ finished = 0; while ( !finished ) { SDL_PollEvent(&event); switch ( event.type ) { case SDL_KEYDOWN : if ( !game->paused ) { if ( event.key.keysym.sym == SDLK_SPACE ) game->thrusting = 1; if ( event.key.keysym.sym == SDLK_LEFT ) game->turn_left = 1; if ( event.key.keysym.sym == SDLK_RIGHT ) game->turn_right = 1; if ( event.key.keysym.sym == SDLK_UP ) game->forward = 1; if ( event.key.keysym.sym == SDLK_DOWN ) game->reverse = 1; } if ( event.key.keysym.sym == SDLK_p ) game_pause(game); break; case SDL_KEYUP : if ( !game->paused ) { if ( event.key.keysym.sym == SDLK_SPACE ) game->thrusting = 0; if ( event.key.keysym.sym == SDLK_LEFT ) game->turn_left = 0; if ( event.key.keysym.sym == SDLK_RIGHT ) game->turn_right = 0; if ( event.key.keysym.sym == SDLK_UP ) game->forward = 0; if ( event.key.keysym.sym == SDLK_DOWN ) game->reverse = 0; } if ( event.key.keysym.sym == SDLK_p ) game->pause_rel = 1; break; case SDL_VIDEOEXPOSE : /* Don't bother redrawing if not paused - not long to wait! */ if ( game->paused ) render_draw(game); break; case SDL_QUIT : finished = 1; break; } if ( !game->paused ) { physics_step(game); render_draw(game); } } render_shutdown(game->render); SDL_Quit(); printf("\n"); return 0; }