GL-117 一款飞行模拟游戏,环境上和效果上都是以真实的场景作参考!可以选择战斗机和武器。常见的任务地形是山谷和沙漠。
目标是破坏敌军设施如油库,基地,飞机等等。任务中会受到反飞机武器如对空导弹,对空战车的攻击,也少不了空战。
项目需要3D库:SDL.dll、SDL_mixer.dll,效果如图:
入口源码:
/****************************************************************************
GL-117 ENTRY POINT
****************************************************************************/
int main (int argc, char **argv)
{
char buf [STDSIZE]; // temp buffer
checkargs (argc, argv); // process command line parameters
dirs = new Dirs (argv [0]); // get data directory (DATADIR, defined via autoconf)
sprintf (buf, "Startup %s, %s ... ", argv [0], VERSIONSTRING);
display (buf, LOG_MOST);
#ifdef _MSC_VER
display ("Windows detected ", LOG_MOST);
#endif
display ("Getting directory locations", LOG_ALL);
if (!load_config ()) // try to load conf file (conf.cpp) and validate settings
{
// no conf file found => create new one
display ("Creating new configuration", LOG_ALL);
config_test (argc, argv); // do screen test
firststart = true; // enable adjusting quality/view/graphics automatically by the game
}
save_config (); // save conf file (validated)
load_configInterface (); // load interface settings from conf.interface and validate
save_configInterface (); // save interface settings
maploader = new MapLoader ();
// here srand should be called to initialize the random number generator
// this is currently done by grabbing random numbers via the init methods (not very elegant)
server = NULL;
client = NULL;
display ("Creating/Loading pilots list", LOG_ALL);
pilots = new PilotList (dirs->getSaves ("pilots")); // look at pilots.h
// NO SDL FOUND => USE GLUT ONLY
#ifdef USE_GLUT
display ("Using GLUT only", LOG_MOST);
if (!configinit)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
if (!setScreen (width, height, bpp, fullscreen))
{
load_saveconfig ();
if (!setScreen (width, height, bpp, fullscreen))
{
sprintf (buf, "No working display mode %dx%d found", width, height);
display (buf, LOG_FATAL);
exit (EXIT_INIT);
}
}
}
display ("Calling main initialization method", LOG_ALL);
myFirstInit ();
display ("Creating dummy sound system, install SDL to enable sound", LOG_ALL);
sound = new SoundSystem ();
createMenu ();
display ("Registering GLUT callbacks", LOG_ALL);
glutReshapeFunc (myReshapeFunc);
glutDisplayFunc (myDisplayFunc);
glutKeyboardFunc (myKeyboardFunc);
glutSpecialFunc (mySpecialFunc);
glutPassiveMotionFunc (myPassiveMotionFunc);
glutMouseFunc (myMouseFunc);
glutIdleFunc (myIdleFunc);
glutTimerFunc (20, myTimerFunc, 0);
// parameters: visible angle, aspectracio, z-nearclip, z-farclip
gluPerspective (visibleangle, (float) width / height, nearclippingplane * GLOBALSCALE, 50.0 * GLOBALSCALE);
// no keyboard available with GLUT, as there are no KEY_DOWN/UP events
if (controls <= 0)
controls = CONTROLS_MOUSE;
display ("Entering GLUT main loop", LOG_ALL);
glutMainLoop(); // give controls to GLUT
// SDL FOUND
#else
display ("Using SDL and GLUT", LOG_MOST);
if (!configinit)
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
{
sprintf (buf, "Couldn't initialize SDL: %s", SDL_GetError ());
display (buf, LOG_FATAL);
exit (EXIT_INIT);
}
atexit (SDL_Quit);
// SDL_NET INSTALLED?
#ifdef HAVE_SDL_NET
if (SDLNet_Init () == -1) // initialize SDL_net
{
sprintf (buf, "SDLNet_Init: %s", SDLNet_GetError ());
display (buf, LOG_FATAL);
exit (EXIT_INIT);
}
display ("Using SDL_net", LOG_MOST);
#endif
if (!configinit)
{
if (!setScreen (width, height, bpp, fullscreen))
{
load_saveconfig ();
if (!setScreen (width, height, bpp, fullscreen))
{
sprintf (buf, "No working display mode %dx%d found.", width, height);
display (buf, LOG_FATAL);
exit (EXIT_INIT);
}
}
}
display ("Setting SDL caption", LOG_ALL);
SDL_WM_SetCaption ("GL-117", "GL-117"); // window name
SDL_ShowCursor (0);
display ("Creating sound system", LOG_ALL);
sound = new SoundSystem (); // look at audio.cpp
sound->volumesound = volumesound;
sound->volumemusic = volumemusic;
sound->setVolume (); // set all sound volumes
sound->setVolumeMusic (); // set all music volumes
display ("Playing startup music", LOG_ALL);
sound->playMusic (1);
#ifdef HAVE_SDL_MIXER
Mix_HookMusicFinished (playRandomMusic);
#endif
display ("Calling main initialization method", LOG_ALL);
myFirstInit ();
myReshapeFunc (width, height);
display ("Querying joystick", LOG_ALL);
joysticks = SDL_NumJoysticks ();
memset (jaxis, 0, maxjaxis * maxjoysticks * sizeof (int));
if (joysticks > 0)
{
for (i = 0; i < joysticks; i ++)
{
SDL_JoystickEventState (SDL_ENABLE);
sdljoystick [i] = SDL_JoystickOpen (i);
sdljoystickaxes [i] = SDL_JoystickNumAxes (sdljoystick [i]);
sprintf (buf, "Joystick \"%s\" detected", SDL_JoystickName (i));
display (buf, LOG_MOST);
}
}
else
{
display ("No joystick found", LOG_MOST);
// sdljoystick [0] = NULL;
if (controls == CONTROLS_JOYSTICK) // no joystick available, so switch to mouse controls
controls = CONTROLS_MOUSE;
}
// disable joystick manually
// joysticks = 0;
/* joysticks = 2;
sdljoystickaxes [0] = 4;
sdljoystickaxes [1] = 2;*/
SDL_EnableUNICODE (1);
SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
// Restrict mouse to SDL window
// SDL_WM_GrabInput (SDL_GRAB_ON);
createMenu ();
display ("Entering SDL main loop (GLUT emulation)", LOG_ALL);
sdlMainLoop (); // simulate GLUT's main loop (above)
#endif
return 0; // exit without signaling errors
}
学习的目标是成熟!~~~~~