//------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ int main(void) { // Initialization (Note windowTitle is unused on Android) //--------------------------------------------------------- InitWindow(screenWidth, screenHeight, "sample game: space invaders"); InitGame(); #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update and Draw //---------------------------------------------------------------------------------- UpdateDrawFrame(); //---------------------------------------------------------------------------------- } #endif // De-Initialization //-------------------------------------------------------------------------------------- UnloadGame(); // Unload loaded data (textures, sounds, models...) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
// -------------------------------------------------------------------- // メイン関数定義 // -------------------------------------------------------------------- int WINAPI WinMain( HINSTANCE hInstance, // 現在のインスタンスのハンドル HINSTANCE hPrevInstance, // 以前のインスタンスのハンドル LPSTR lpCmdLine, // コマンドライン int nCmdShow // 表示状態 ) { // DXLIBの初期化処理 DxLib_Init(); // ゲーム初期化 InitGame(); // ゲームループ // 以下の処理をエスケープキーが押されるまでかプレイヤーが生きている間繰り返す while( ProcessMessage() == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 && Player.state == STATE_LIVE) { GameMain(); } // DXLIBの終了処理 DxLib_End(); // アプリケーションの終了 return 0; }
// Handle the gameflow, start, restartm die...etc. void ShipRace::Update() { // Get the button to start the game if the game is not already started...Meh ! if (gDInput->keyPressed(DIK_SPACE) && !mGameStarted) { // Init the game InitGame(); } // If gameOver... if (!mGameOver) { // and the game is started... if (mGameStarted) { // and the ship is dead if (ship->GetIsDead()) { // Gameover ! GameOver(); } } } // Else if space is pressed and it is gameover else if (gDInput->keyPressed(DIK_SPACE) && mGameOver) { // Restart the game RestartGame(); } }
int PlayGame(int *Parameter){ Board gameBoard,nextBoard; int i; int maxLevel; InitGame(gameBoard); PrintBoard(gameBoard); while (1){ NextStep(nextBoard,gameBoard, Parameter, COUNT_STEP, MoveLeft, MoveRight, MoveUp, MoveDown); UpdateBoard(gameBoard,nextBoard); maxLevel = FinishGame(gameBoard); if ( maxLevel != 0){ break; } if (PLAY_MODE == 1) if ( TotalScore > 1000) Sleep(1000); else Sleep(100); } return maxLevel; }
// 主程序 int main(int argc, char *argv[]) { lua_State *pL_main; remove(DEBUG_FILE); freopen(ERROR_FILE,"wt",stderr); //设置stderr输出到文件 //初始化lua pL_main=luaL_newstate(); luaL_openlibs(pL_main); Lua_Config(pL_main,CONFIG_FILE); //读取lua配置文件,设置参数 InitSDL(); //初始化SDL InitGame(); //初始化游戏数据 Lua_Main(pL_main); //调用Lua主函数,开始游戏 //关闭lua lua_close(pL_main); ExitGame(); //释放游戏数据 ExitSDL(); //退出SDL return 0; }
int main(int argc, char **argv) { int i; for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "--nograb")) { mouseGrabEnabled = false; } } SDL_Init(SDL_INIT_EVERYTHING); SDL_EnableUNICODE(1); // needed to get complete input events SPG_Init(); SPA_Init(); SPD_SetupGameData(); SPI_ClearKeysDown(); US_Startup (); InitGame (); SDL_PauseAudio(0); DemoLoop(); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { if(!InitGame()) { printf("%s\n", SDL_GetError()); FreeGame(); //If InitGame failed, kill the program return 0; } while(ProgramIsRunning()) { long int oldTime = SDL_GetTicks(); //We will use this later to see how long it took to update the frame SDL_FillRect(Backbuffer, NULL, 0); //Clear the screen RunGame(); //Update the game DrawGame(); //Draw the screen int frameTime = SDL_GetTicks() - oldTime; if(frameTime < FRAME_DELAY) //Dont delay if we dont need to SDL_Delay(FRAME_DELAY - frameTime); //Delay //In SDL 2, SDL_UpdateWindowSurface replaces SDL_Flip SDL_UpdateWindowSurface(Window); //Flip the screen } FreeGame(); //Gracefully release SDL and its resources. return 0; }
void WorldInit() { TimeSeedGenerator(); DisplayInit(); InitGame(); LoadGame("Scenarios\\default.xml"); }
int main() { // Display a few instructions printf("Instructions:\nWhen ready, hit enter. You will have five seconds " "to place your mouse cursor in the upper left hand corner of the game board.\n" "\nTips: I would hit enter, then wait a few seconds and then click play. It might" " take a game or two to get your timing right.\n"); system("pause"); while (true) { CountDown(5); InitGame(); // Play game for specified time_limit for (time_t start_time = time(0); start_time + time_limit - time(0) >= 0;) { GetGems(); DisplayGrid(); MakeMove(); Sleep(throttle_time); } ClearGame(); printf("Game over. . . Play again?\n"); system("Pause"); } return 0; }
void nGame::RestartGame() { // Clean previous game objects CleanGame(); // Initialize new game objects InitGame(); }
static void retro_load_game(int argc, char *argv[]) { CheckParameters(argc, argv); CheckForEpisodes(); InitGame(); }
void startGame() { InitGame(); WaitLowButton(&gPushButton); WaitHighButton(&gPushButton); //Change the gameState of Game struct to DisplayPattern }
void Pi::Start() { Pi::intro = new Intro(Pi::renderer, Graphics::GetScreenWidth(), Graphics::GetScreenHeight()); ui->SetInnerWidget(ui->CallTemplate("MainMenu")); //XXX global ambient colour hack to make explicit the old default ambient colour dependency // for some models Pi::renderer->SetAmbientColor(Color(0.2f, 0.2f, 0.2f, 1.f)); ui->Layout(); Uint32 last_time = SDL_GetTicks(); float _time = 0; while (!Pi::game) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) Pi::Quit(); else ui->DispatchSDLEvent(event); // XXX hack // if we hit our exit conditions then ignore further queued events // protects against eg double-click during game generation if (Pi::game) while (SDL_PollEvent(&event)) {} } Pi::renderer->BeginFrame(); Pi::renderer->SetPerspectiveProjection(75, Pi::GetScrAspect(), 1.f, 10000.f); Pi::renderer->SetTransform(matrix4x4f::Identity()); intro->Draw(_time); Pi::renderer->EndFrame(); ui->Update(); ui->Draw(); Pi::renderer->SwapBuffers(); Pi::frameTime = 0.001f*(SDL_GetTicks() - last_time); _time += Pi::frameTime; last_time = SDL_GetTicks(); } ui->RemoveInnerWidget(); ui->Layout(); // UI does important things on layout, like updating keyboard shortcuts delete Pi::intro; Pi::intro = 0; InitGame(); StartGame(); MainLoop(); }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); //调整窗口尺寸布局 resize(AREA_COL*BLOCK_SIZE+MARGIN*4+4*BLOCK_SIZE,AREA_ROW*BLOCK_SIZE+MARGIN*2); //初始化游戏 InitGame(); }
// The original starting point of the game EXE void cat3d_exe_main (void) { //id0_short_t i; if (refkeen_current_gamever == BE_GAMEVER_CAT3D122) { if (BE_Cross_strcasecmp(id0_argv[1], "/VER") == 0) { BE_ST_printf("Catacomb 3-D version 1.22 (Rev 1)\n"); BE_ST_printf("Copyright 1991-93 Softdisk Publishing\n"); BE_ST_printf("Developed for use with 100%% IBM compatibles\n"); BE_ST_printf("that have 640K memory and DOS version 3.3 or later\n"); BE_ST_printf("and EGA graphics or better.\n"); BE_ST_HandleExit(0); } if (BE_Cross_strcasecmp(id0_argv[1], "/?") == 0) { BE_ST_printf("Catacomb 3-D version 1.22\n"); BE_ST_printf("Copyright 1991-93 Softdisk Publishing\n\n"); BE_ST_printf("Syntax:\n"); BE_ST_printf("CAT3D [/<switch>]\n\n"); BE_ST_printf("Switch What it does\n"); BE_ST_printf("/? This Information\n"); BE_ST_printf("/VER Display Program Version Information\n"); BE_ST_printf("/COMP Fix problems with SVGA screens\n"); BE_ST_printf("/NOAL No AdLib or SoundBlaster detection\n"); BE_ST_printf("/NOJOYS Tell program to ignore joystick\n"); BE_ST_printf("/NOMOUSE Tell program to ignore mouse\n"); BE_ST_printf("/HIDDENCARD Overrides video detection\n\n"); BE_ST_printf("Each switch must include a '/' and multiple switches\n"); BE_ST_printf("must be seperated by at least one space.\n\n"); BE_ST_HandleExit(0); } } // jabhack(); // REFKEEN - Commented out InitGame (); CheckMemory (); LoadLatchMem (); #ifdef PROFILE NewGame (); GameLoop (); #endif //NewGame (); //GameLoop (); DemoLoop(); Quit("Demo loop exited???"); }
void DXApp::Run() { MSG msg = { 0 }; BOOL bRet = 1; float dt = 0; PreInit(); InitGame(); LateInit(); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { m_gameTimer->Tick(); if (!m_appPaused) { CalculateFrameStats(); dt += m_gameTimer->DeltaTime(); if (dt >= 1.f / TICKS_PER_SECOND) { OnTickUpdate(m_gameTimer->DeltaTime()); LateTickUpdate(m_gameTimer->DeltaTime()); dt = 0; tick++; } if (tick == TICKS_PER_SECOND) { std::wstringstream ss; ss << "DirectX title - FPS: "; ss << fps; BOOL b = SetWindowText(m_mainHandle, LPCWSTR(ss.str().c_str())); DWORD d = GetLastError(); fps = 0; tick = 0; } PrepareWindow(); RenderUpdate(); RenderWindow(); fps++; } else { Sleep(100); } } } }
// Update game (one frame) void UpdateGame(void) { if (!gameOver) { if (IsKeyPressed('P')) pause = !pause; if (!pause) { // Player movement if (IsKeyDown(KEY_LEFT)) player.position.x -= 5; if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2; if (IsKeyDown(KEY_RIGHT)) player.position.x += 5; if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2; // Launch ball if (!ball.active) { if (IsKeyPressed(KEY_SPACE)) { ball.active = true; ball.speed = (Vector2){ 0, -5 }; } } UpdateBall(); // Game over logic if (player.life <= 0) gameOver = true; else { gameOver = true; for (int i = 0; i < LINES_OF_BRICKS; i++) { for (int j = 0; j < BRICKS_PER_LINE; j++) { if (brick[i][j].active) gameOver = false; } } } } } else { if (IsKeyPressed(KEY_ENTER)) { InitGame(); gameOver = false; } } }
Game::Game( Board *board, Figure *figures, Render *io, int screenHeight ) { m_screenHeight = screenHeight; // Get the pointer to the Board and Pieces classes m_board = board; m_figures = figures; m_io = io; // Game initialization InitGame(); }
/* ====================================== Init ====================================== */ Game::Game(Board *pBoard, Pieces *pPieces, IO *pIO, int pScreenHeight) { mScreenHeight = pScreenHeight; // Get the pointer to the Board and Pieces classes mBoard = pBoard; mPieces = pPieces; mIO = pIO; // Game initialization InitGame (); }
int main(int argc,char**argv){ ARParam cparam; ARParam wparam; int xsize,ysize; glutInit(&argc,argv); if(arVideoOpen(vconf_name)<0){ puts("ビデオデバイスエラー"); return -1; } if(arVideoInqSize(&xsize,&ysize) < 0)return -1; if(arParamLoad(cparam_name,1,&wparam)< 0){ puts("パラメータ読み込み失敗"); return -1; } arParamChangeSize(&wparam,xsize,ysize,&cparam); arInitCparam(&cparam); nyobj = nyar_NyARTransMat_O2_create(&cparam); if( (patt_id=arLoadPatt(pattern_name)) < 0){ puts("パターン読み込みエラー"); return -1; } argInit(&cparam, 1.0, 0, 0, 0, 0); mqoInit(); if(Data_Load()==-1) return -1; arVideoCapStart(); InitGame(); arUtilTimerReset(); #ifdef _WIN32 TIMECAPS Caps; timeGetDevCaps(&Caps, sizeof(TIMECAPS)); // 性能取得 timeBeginPeriod(Caps.wPeriodMin); #endif argMainLoop(MouseEvent,KeyEvent,MainLoop); #ifdef _WIN32 timeEndPeriod(Caps.wPeriodMin); #endif nyar_NyARTransMat_O2_free(nyobj); return 0; }
int handle() { gDreamsForceClose = 0; InitGame(); VW_SetScreenMode (GRMODE); VW_ClearVideo (BLACK); DemoLoop(); // If thread has finished, we can quit CG gEventManager.add( new GMQuit() ); return 0; }
tictactoe::tictactoe() { ui = new(Ui::tictactoe); ui->setupUi(this); GameSpaces[0] = ui->btnTL; GameSpaces[1] = ui->btnTC; GameSpaces[2] = ui->btnTR; GameSpaces[3] = ui->btnML; GameSpaces[4] = ui->btnMC; GameSpaces[5] = ui->btnMR; GameSpaces[6] = ui->btnBL; GameSpaces[7] = ui->btnBC; GameSpaces[8] = ui->btnBR; InitGame(); }
int main(int argc, char **argv) { srand(time(NULL)); if (!InitGame(argc, argv)) { fprintf(stderr, "\nInitialization failed.\n"); return -1; } DoTitleScreen(); DoMainMenu(); PlayGame(); ShutdownGame(); return 0; }
CNoGo::CNoGo(HINSTANCE hInst, HWND hWnd, char *LibPath) { this->hInst = hInst; this->hWnd = hWnd; strncpy(this->LibPath, LibPath, MAX_PATH - 1); hPen = NULL; hFont = NULL; //获取配置 GetConfig(); //创建兼容DC HDC hDC = GetDC(hWnd); hBlcDC = CreateCompatibleDC(hDC); hWhtDC = CreateCompatibleDC(hDC); hMarkDC = CreateCompatibleDC(hDC); InitGame(); }
int RunProgram(po::variables_map& options) { if(!InitProgram()) return 1; if(!InitDirectories()) return 1; // Zufallsgenerator initialisieren (Achtung: nur für Animations-Offsets interessant, für alles andere (spielentscheidende) wird unser Generator verwendet) srand(static_cast<unsigned int>(std::time(NULL))); // Exit-Handler initialisieren atexit(&ExitHandler); try{ if(!InitGame()) return 2; if(options.count("map")) QuickStartGame(options["map"].as<std::string>()); // Hauptschleife while(GAMEMANAGER.Run()) { #ifndef _WIN32 extern bool killme; killme = false; #endif // !_WIN32 } // Spiel beenden GAMEMANAGER.Stop(); libsiedler2::setAllocator(NULL); } catch(RTTR_AssertError& error) { // Write to log file, but don't throw any errors if this fails too try{ LOG.write(error.what()); } catch(...){} //-V565 return 42; } return 0; }
// 主程序 int SDL_main(int argc, char *argv[]) { remove_file(DEBUG_FILE); freopen_file(ERROR_FILE,"wt",stderr); //设置stderr输出到文件 //初始化lua g_pL_main=lua_open(); luaL_openlibs(g_pL_main); Lua_Config(g_pL_main,CONFIG_FILE); //读取lua配置文件,设置参数 InitSDL(); //初始化SDL InitGame(); //初始化游戏数据 #ifdef WIN32 SDL_mainLoop(); #endif return 0; }
void MoveSnake(int dx, int dy) { int x = px; int y = py; px += dx; Clamp(&px, 0, size-1); py += dy; Clamp(&py, 0, size-1); if (x != px || y != py) { int i = py * size + px; if (i == target) { maxLength = ResizeArray<int>(&segments, maxLength, maxLength + 1); MoveTarget(); } int old = segments[index]; if (map[i]) { map[old] = false; InitGame(); return; } map[i] = true; segments[index++] = i; ++length; if (index >= maxLength) index = 0; if (length > maxLength) length = maxLength; if (length == maxLength) map[old] = false; } }
int main(int argc, char* argv[]) { RenderContext rcx; rcx.nWindowWidth = 640; rcx.nWindowHeight = 480; rcx.nMousePosX = 0; rcx.nMousePosY = 0; CreateWindow(&rcx); InitGL(&rcx); InitGame(&rcx); Loop(&rcx, Draw); Cleanup(&rcx); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { Game game; InitGame(game); while (!IsGameFinished(game)) { // Get game time game.t = timeGetTime(); GetUserInput(game); PerformAI(game); DrawGame(game); } DisplayResults(game); TerminateGame(game); return 0; }
////////////////////////////////////////////////////////////////////////// // 游戏核心 void CGameCore::Gaming( DWORD inc ) { // 计时器 CountTimeFlash(inc); // 右上角计时器 glColor3f(0.0,1.0,0.0); g_myModel.DrawLetter(timeFlash, 9.5,7.5,0); // 左下角玩家一绝妙计数 g_myModel.DrawLetter(excellentNum,-10,-7.5,0); // 如果双人游戏的话 if (2 == g_MenuStateMain) { // 右下角玩家一绝妙计数 g_myModel.DrawLetter(excellentP2,10,-7.5,0); } glColor3f(1,1,1); if (initGame == false) { InitGame(); initGame = true; } // 单人游戏 if (1 == g_MenuStateMain) { GameSinglePlayer(inc); } // 双人游戏 if (2 == g_MenuStateMain) { GameDoublePlayer(inc); } if (3 == g_MenuStateMain) { GameEntertainment(inc); } }