bool NumPlayersSelection( GameMode mode, GraphicsDevice *graphics, EventHandlers *handlers) { MenuSystem ms; MenuSystemInit( &ms, handlers, graphics, Vec2iZero(), graphics->cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { char buf[2]; if (IsMultiplayer(mode) && i == 0) { // At least two players for dogfights continue; } sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { const int numPlayers = ms.current->u.returnCode; for (int i = 0; i < (int)gPlayerDatas.size; i++) { const PlayerData *p = CArrayGet(&gPlayerDatas, i); CASSERT(!p->IsLocal, "unexpected local player"); } if (NetClientIsConnected(&gNetClient)) { // Tell the server that we want to add new players NetMsgNewPlayers np; np.ClientId = gNetClient.ClientId; np.NumPlayers = numPlayers; NetClientSendMsg(&gNetClient, MSG_NEW_PLAYERS, &np); } else { // We are the server, just add the players for (int i = 0; i < numPlayers; i++) { PlayerData *p = PlayerDataAdd(&gPlayerDatas); PlayerDataSetLocalDefaults(p, i); p->inputDevice = INPUT_DEVICE_UNSET; } } } MenuSystemTerminate(&ms); return ok; }
bool NumPlayersSelection(GraphicsDevice *graphics, EventHandlers *handlers) { MenuSystem ms; MenuSystemInit( &ms, handlers, graphics, Vec2iZero(), graphics->cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); MenuAddSubmenu(ms.current, MenuCreateReturn("(No local players)", 0)); for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { char buf[2]; sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); // Select 1 player default ms.current->u.normal.index = 1; MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { const int numPlayers = ms.current->u.returnCode; CA_FOREACH(const PlayerData, p, gPlayerDatas) CASSERT(!p->IsLocal, "unexpected local player"); CA_FOREACH_END() // Add the players for (int i = 0; i < numPlayers; i++) { GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA); e.u.PlayerData = PlayerDataDefault(i); e.u.PlayerData.UID = gNetClient.FirstPlayerUID + i; GameEventsEnqueue(&gGameEvents, e); } // Process the events to force add the players HandleGameEvents(&gGameEvents, NULL, NULL, NULL); // This also causes the client to send player data to the server } MenuSystemTerminate(&ms); return ok; }
bool ScreenWait(const char *message, void (*checkFunc)(menu_t *, void *)) { MenuSystem ms; MenuSystemInit( &ms, &gEventHandlers, &gGraphicsDevice, Vec2iZero(), gGraphicsDevice.cachedConfig.Res); ms.allowAborts = true; ms.root = ms.current = MenuCreateNormal("", message, MENU_TYPE_NORMAL, 0); MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuSetPostUpdateFunc(ms.root, checkFunc, &ms); MenuLoop(&ms); const bool ok = !ms.hasAbort; MenuSystemTerminate(&ms); return ok; }
int main() { state GameState; Game* MyGame; Menu* MyMenu; GameState = MENU; if(_InitAllegro()==0) // allegro init-je { while(STOP_GAME != 1) { switch(GameState) { case MENU: MyMenu = InitMenu(); MenuLoop(MyMenu); //amig a menuben vagyunk a menu loopon belul fut a program FreeMenu(MyMenu); GameState = GAME; break; case GAME: MyGame = _InitGame("resource.txt"); // a játék initje _GameLoop(MyGame); //amig a jatek fut, a Game loopon belul fog az futni // _FreeMyGame(MyGame); ez nem szuksegse, a game loop ugy lep ki, hogy felszabaditja GameState = MENU; break; } } } // játék loop return 0; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int main(int argc, char **argv) { #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.LocalPlayerName = GetLocalPlayerNameFromEnv(); if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players strucure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); return 0; }
bool ScreenMissionSummary( CampaignOptions *c, struct MissionOptions *m, const bool completed) { if (completed) { // Save password MissionSave ms; MissionSaveInit(&ms); ms.Campaign = c->Entry; // Don't make password for next level if there is none int passwordIndex = m->index + 1; if (passwordIndex == c->Entry.NumMissions) { passwordIndex--; } strcpy(ms.Password, MakePassword(passwordIndex, 0)); ms.MissionsCompleted = m->index + 1; AutosaveAddMission(&gAutosave, &ms); AutosaveSave(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE)); } // Calculate bonus scores // Bonuses only apply if at least one player has lived if (AreAnySurvived()) { int bonus = 0; // Objective bonuses CA_FOREACH(const Objective, o, m->missionData->Objectives) if (ObjectiveIsPerfect(o)) { bonus += PERFECT_BONUS; } CA_FOREACH_END() bonus += GetAccessBonus(m); bonus += GetTimeBonus(m, NULL); CA_FOREACH(PlayerData, p, gPlayerDatas) ApplyBonuses(p, bonus); CA_FOREACH_END() } MenuSystem ms; const int h = FontH() * 10; MenuSystemInit( &ms, &gEventHandlers, &gGraphicsDevice, Vec2iNew(0, gGraphicsDevice.cachedConfig.Res.y - h), Vec2iNew(gGraphicsDevice.cachedConfig.Res.x, h)); ms.current = ms.root = MenuCreateNormal("", "", MENU_TYPE_NORMAL, 0); // Use return code 0 for whether to continue the game if (completed) { MenuAddSubmenu(ms.root, MenuCreateReturn("Continue", 0)); } else { MenuAddSubmenu(ms.root, MenuCreateReturn("Replay mission", 0)); MenuAddSubmenu(ms.root, MenuCreateReturn("Back to menu", 1)); } ms.allowAborts = true; MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuSystemAddCustomDisplay(&ms, MissionSummaryDraw, m); MenuLoop(&ms); return ms.current->u.returnCode == 0; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int stratagusMain(int argc, char **argv) { #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif #ifdef USE_WIN32 SetUnhandledExceptionFilter(CreateDumpFile); #endif #if defined(USE_WIN32) && ! defined(REDIRECT_OUTPUT) SetupConsole(); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif #ifdef USE_PHYSFS if (PHYSFS_init(argv[0])) { PHYSFS_mount(PHYSFS_DATAFILE, "/", 0); } #endif #ifdef USE_STACKTRACE try { #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.SetLocalPlayerNameFromEnv(); #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename, parameters.luaScriptArguments); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players structure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); #ifdef USE_STACKTRACE } catch (const std::exception &e) { fprintf(stderr, "Stratagus crashed!\n"); //Wyrmgus start // fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Wargus/stratagus/issues\n"); fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Andrettin/Wyrmgus/issues\n"); //Wyrmgus end fprintf(stderr, "and tell us what caused this bug to occur.\n"); fprintf(stderr, " === exception state traceback === \n"); fprintf(stderr, "%s", e.what()); exit(1); } #endif return 0; }
bool GameOptions(const GameMode gm) { // Create selection menus const int w = gGraphicsDevice.cachedConfig.Res.x; const int h = gGraphicsDevice.cachedConfig.Res.y; MenuSystem ms; MenuSystemInit( &ms, &gEventHandlers, &gGraphicsDevice, Vec2iZero(), Vec2iNew(w, h)); ms.align = MENU_ALIGN_CENTER; ms.allowAborts = true; AllowedWeaponsData awData; AllowedWeaponsDataInit(&awData, &gMission.Weapons); switch (gm) { case GAME_MODE_DEATHMATCH: ms.root = ms.current = MenuCreateNormal( "", "", MENU_TYPE_OPTIONS, 0); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.PlayerHP")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Deathmatch.Lives")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.HealthPickups")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Game.Ammo")); MenuAddSubmenu(ms.current, MenuCreateAllowedWeapons("Weapons...", &awData)); MenuAddSubmenu(ms.current, MenuCreateSeparator("")); MenuAddSubmenu(ms.current, MenuCreateReturn("Done", 0)); break; case GAME_MODE_DOGFIGHT: ms.root = ms.current = MenuCreateNormal( "", "", MENU_TYPE_OPTIONS, 0); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Dogfight.PlayerHP")); MenuAddConfigOptionsItem( ms.current, ConfigGet(&gConfig, "Dogfight.FirstTo")); MenuAddSubmenu(ms.current, MenuCreateAllowedWeapons("Weapons...", &awData)); MenuAddSubmenu(ms.current, MenuCreateSeparator("")); MenuAddSubmenu(ms.current, MenuCreateReturn("Done", 0)); break; default: CASSERT(false, "unknown game mode"); break; } MenuAddExitType(&ms, MENU_TYPE_RETURN); MenuLoop(&ms); const bool ok = !ms.hasAbort; if (ok) { ConfigApply(&gConfig); // Save options for later ConfigSave(&gConfig, GetConfigFilePath(CONFIG_FILE)); // Set allowed weapons // First check if the player has unwittingly disabled all weapons // if so, enable all weapons bool allDisabled = true; for (int i = 0, j = 0; i < (int)awData.allowed.size; i++, j++) { const bool *allowed = CArrayGet(&awData.allowed, i); if (*allowed) { allDisabled = false; break; } } if (!allDisabled) { for (int i = 0, j = 0; i < (int)awData.allowed.size; i++, j++) { const bool *allowed = CArrayGet(&awData.allowed, i); if (!*allowed) { CArrayDelete(&gMission.Weapons, j); j--; } } } } AllowedWeaponsDataTerminate(&awData); MenuSystemTerminate(&ms); return ok; }
void GameControl::GameKeyHandle(int key, int action) { //if they no longer want the piece to drop faster... stop it if (action == GLFW_RELEASE && key == GLFW_KEY_DOWN) { //set the accel to 0 and make the interval drop //right for the current level. game->SetDropAccel(0.0f); game->SetDropInterval(DROP_INTERVAL_DEFAULT - (game->GetLevel() * DROP_INTERVAL_INCREMENT)); } if (action == GLFW_PRESS) { switch(key) { case GLFW_KEY_ESC: menu = new MenuControl(); menu->EscDown = true; MenuLoop(); delete menu; break; case GLFW_KEY_UP: { Tetromino *temp = new Tetromino(); memcpy(temp, game->GetTetromino(), sizeof(Tetromino)); int pos = temp->GetPosition(); pos++; if (pos > temp->GetMaxPositions()) { pos = 1; } temp->SetShape(temp->GetType(), pos); if (!game->GetGrid()->CheckCollision(temp)) { game->GetTetromino()->SetShape(game->GetTetromino()->GetType(), pos); sound->Play(SOUND_ROTATE); } } break; case GLFW_KEY_LEFT: { LOCATION_T location = game->GetTetromino()->GetLocation(); Tetromino *temp = new Tetromino(); memcpy(temp, game->GetTetromino(), sizeof(Tetromino)); temp->SetGridLocation(location.GridX - 1, location.GridY); if (!game->GetGrid()->CheckCollision(temp)) { game->GetTetromino()->SetGridLocation(location.GridX - 1, location.GridY); sound->Play(SOUND_MOVE); } delete temp; } break; case GLFW_KEY_RIGHT: { LOCATION_T location = game->GetTetromino()->GetLocation(); Tetromino *temp = new Tetromino(); memcpy(temp, game->GetTetromino(), sizeof(Tetromino)); temp->SetGridLocation(location.GridX + 1, location.GridY); if (!game->GetGrid()->CheckCollision(temp)) { game->GetTetromino()->SetGridLocation(location.GridX + 1, location.GridY); sound->Play(SOUND_MOVE); } delete temp; } break; case GLFW_KEY_DOWN: //have to set the drop interval to the default //otherwise drop calculation in main loop is too fast game->SetDropInterval(1.0f); game->SetDropAccel(0.02f); sound->Play(SOUND_ACCEL); break; case GLFW_KEY_F2: game->StartNewGame(); /* game->GetTetromino()->Reset(); game->GetTetromino()->Create(); game->CaptureKeys(true); game->GetGrid()->Reset(); game->SetLevel(0); game->SetDropInterval(DROP_INTERVAL_DEFAULT - (game->GetLevel() * DROP_INTERVAL_INCREMENT));*/ break; default: break; } } fflush(stdout); }
void GameOver() { //stop all movement game->SetDropAccel(0.0f); game->SetDropInterval(0.0f); float startx = game->GetGrid()->GetGridXStart(); startx -= 50; float starty = game->GetGrid()->GetGridYStart(); starty += game->GetGrid()->GetGridBlockSize() * (GRID_HEIGHT / 2) - (100/2); glBindTexture(GL_TEXTURE_2D, game->GetTextures()[FONT_TEXTURE]); glListBase(game->GetTextureBase()-32); game->CaptureKeys(false); bool loop = true; do { glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); UpdateDisplay(); glEnable(GL_BLEND); glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); glColor4f(0.3f, 0.3f, 0.3f, 0.3f); glBegin(GL_QUADS); glVertex2f(startx, starty); glVertex2f(startx + 250, starty); glVertex2f(startx + 250, starty + 100); glVertex2f(startx, starty + 100); glEnd(); //save where we are glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBlendFunc(GL_ONE, GL_DST_ALPHA); glTranslated(startx + ((250.0f / 2.0f) - float((9.0f * 16.0f) / 2)), starty + ((100.0f / 2.0f) - (16.0f / 2.0f)), 0); glColor4f(1.0f, 1.0f, 1.0f, 0.0f); glCallLists(9, GL_UNSIGNED_BYTE, "GAME OVER"); glPopMatrix(); glDisable(GL_BLEND); glfwSwapBuffers(); glfwSleep(0.003); loop = !glfwGetKey(GLFW_KEY_F2); if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS) { //show the menu menu = new MenuControl(); menu->EscDown = true; MenuLoop(); loop = false; delete menu; menu = NULL; } } while(loop); game->StartNewGame(); }
void update(double dt) { // get the delta time elapsedTime += dt; deltaTime = dt; if ( menu == 1 )//Main Menu { if (keyPressed[K_UP] && ArrowLocate.Y > 11) { //Beep(1440, 30); ArrowLocate.Y -= 3; ArrowLocate2.Y -=3; } if (keyPressed[K_DOWN] && ArrowLocate.Y <18) { //Beep(1440, 30); ArrowLocate.Y += 3; ArrowLocate2.Y += 3; } if (keyPressed[K_ENTER] && ArrowLocate.Y == 11) //Start { menu = 0 ; game = 1; init(); gameLoop(); } if (keyPressed[K_ENTER] && ArrowLocate.Y == 14) //Options { option = 1 ; menu = 0 ; //ArrowLocate.Y = 14; //ArrowLocate2.Y = 14; init(); MenuLoop(); } if (keyPressed[K_ENTER] && ArrowLocate.Y == 17) //Choose Ship { menu=0; option=0; game=0; Ship=1; init(); MenuLoop(); } if (keyPressed[K_ENTER] && ArrowLocate.Y == 20) //Exit Game { exit(1); } if (keyPressed[K_ESCAPE]) { g_quitGame = true; } } if ( option == 1 )//Options { if (keyPressed[K_UP] && ArrowLocate.Y > 0) { //Beep(1440, 30); ArrowLocate.Y -=3; ArrowLocate2.Y -=3; } if (keyPressed[K_DOWN] && ArrowLocate.Y < 17) { //Beep(1440, 30); ArrowLocate.Y += 3; ArrowLocate2.Y += 3; } if (keyPressed[K_ENTER] && ArrowLocate.Y == 14) //Back { option = 0 ; menu = 1; game = 0; } if (keyPressed[K_ESCAPE]) { g_quitGame = true; } } if ( Ship == 1 ) { if (keyPressed[K_ESCAPE]) { g_quitGame = true; } } // quits the game if player hits the escape key if (keyPressed[K_ESCAPE]) { g_quitGame = true; } }