int main( int argc, char** argv ) { // Create Game Game game; // Initialise Game; Return Failure if we unsuccessful if ( !GameInit(&game) ) return -1; // Load Game Assets; Return Failure if we unsuccessful if ( !GameLoadAssets(&game) ) { // Quit and Return Failure GameQuit(&game); return -2; } // Do Initial Setup of game, after resources are loaded GameSetup(&game); // Enter Main Game Loop GameLoop(&game); // Unload Game Assets GameFreeAssets(&game); // Unload Game Data when Exiting GameQuit(&game); // Return Success return 0; }
/* ======================= StartNetGame Begins a game based on the contents of setupPacket ======================= */ boolean StartNetGame() { // make sure we are supposed to be in this game int slot = -1; for ( int i = 0 ; i < MAXPLAYERS ; i++ ) { if ( setupPacket.playerID[i] == playerID ) { slot = i; } } if ( slot == -1 ) { return false; } GameSetup(); consoleplayer = displayplayer = slot; netgame = true; // respawn without restarting levels if ( setupPacket.deathmatch ) { // deathmatch game deathmatch = setupPacket.deathmatch; // could be either 1 or 2 for altdeath nomonsters = true; if ( setupPacket.timelimit > 0 ) { levelTimer = true; // 30 hz, minutes levelTimeCount = setupPacket.timelimit * 30 * 60; } if ( setupPacket.fraglimit > 0 ) { levelFragLimit = true; levelFragLimitCount = setupPacket.fraglimit; } } else { // coop game deathmatch = false; nomonsters = false; } for ( int i = 0 ; i < MAXPLAYERS ; i++ ) { if ( setupPacket.playerID[i] != 0 ) { playeringame[i] = 1; } else { playeringame[i] = 0; } } gametic = 0; maketic = 1; // allow everyone to run the first frame without waiting for a packet memset( netcmds, 0, sizeof( netcmds ) ); memset( consistancy, 0, sizeof( consistancy ) ); gameID = setupPacket.gameID; // start the map G_InitNew( setupPacket.map.skill, setupPacket.map.episode, setupPacket.map.map ); return true; }
/* ======================= StartDemoGame The demo button has been hit on the main menu ======================= */ void StartDemoGame( boolean timeDemoMode ) { if ( levelHasBeenLoaded && !netgame && !demoplayback && usergame && gamestate == GS_LEVEL ) { // save the current game before starting the demos levelHasBeenLoaded = false; G_SaveGame( 0, "quicksave" ); G_DoSaveGame(true); } lastState = IPM_GAME; GameSetup(); if ( timeDemoMode ) { iphoneTimeDemo = true; } // always skip to the next one on each exit from the menu advancedemo = true; }
/* ======================= StartSinglePlayerGame ======================= */ void StartSinglePlayerGame( mapStart_t map ) { playState.map = map; playState.saveGameIsValid = true; // assume we will save the game on exit lastState = IPM_GAME; // mark this level / skill combination as tried // mapStats_t *cms = FindMapStats( playState.map.dataset, playState.map.episode, playState.map.map, true ); if ( cms ) { // if we are at MAX_MAPS, no stat tracking... cms->completionFlags[playState.map.skill] |= MF_TRIED; } GameSetup(); // start the map G_InitNew( playState.map.skill, playState.map.episode, playState.map.map ); }
bool CGameManager::FrontEndUpdate( CD3DManager* d3dManager, float updateTime ) { bool mouse = KeyHit( Mouse_LButton ); int result = m_GUI->Update( updateTime, mouse ); if( result == 1 ) { m_GUI->SetState( GUILoading ); Render( d3dManager, updateTime ); ShowCursor( false ); m_GameState = Game; GameSetup( d3dManager ); } else if( result == 2 ) return false; return true; }
/* ======================= StartSaveGame Can be called by both the resume game button after launch, or the load game button after a player death ======================= */ void StartSaveGame() { GameSetup(); G_LoadGame( 0, true ); G_DoLoadGame(); }
KDbool Level1Scene::init ( KDvoid ) { m_nScoreCount = 0; m_bTargetThrough = KD_FALSE; m_bSecondTab = KD_FALSE; m_bHit = KD_FALSE; m_pMouseJoint = KD_NULL; m_nTargetIndex = 0; m_pTargetBody = KD_NULL; m_pTargetJoint = KD_NULL; if ( !CCLayer::init ( ) ) { return KD_FALSE; } // ��ġ Ȱ��ȭ this->setTouchEnabled ( KD_TRUE ); const CCSize& tLyrSize = this->getContentSize ( ); this->initPhysics ( ); // ����̹����� �ѷ��ش�. CCSprite* pSprite = CCSprite::create ( "BackGround/bgempty.png" ); pSprite->setAnchorPoint ( ccpz ); pSprite->setPosition ( ccp ( 0, 0 ) ); this->addChild ( pSprite, 0, 0 ); CCSprite* spLevel = CCSprite::create ( "SpriteImage/level1.png" ); spLevel->setAnchorPoint ( ccpz ); spLevel->setPosition ( ccp ( 440, 290 ) ); this->addChild ( spLevel, 10 ); m_pBackgroundNode = CCParallaxNode::create ( ); this->addChild ( m_pBackgroundNode, 3 ); m_pCloud1 = CCSprite::create ( "SpriteImage/clowdsmall.png" ); m_pCloud2 = CCSprite::create ( "SpriteImage/clowdlarge.png" ); m_pCloud3 = CCSprite::create ( "SpriteImage/clowdlarge.png" ); m_pCloud4 = CCSprite::create ( "SpriteImage/clowdsmall.png" ); m_pBird1 = CCSprite::create ( "SpriteImage/bird1.png" ); m_pBird2 = CCSprite::create ( "SpriteImage/bird1.png" ); m_pBird3 = CCSprite::create ( "SpriteImage/bird1.png" ); m_pBird4 = CCSprite::create ( "SpriteImage/bird1.png" ); m_nBirdindex = 1; CCPoint dustSpeed = ccp ( 0.1f, 0.1f ); CCPoint bgSpeed = ccp ( 0.05f, 0.05f); m_pBackgroundNode->addChild ( m_pCloud1, 6, dustSpeed , ccp ( 300,250 ) ); m_pBackgroundNode->addChild ( m_pCloud3, 6 , dustSpeed , ccp ( 700,280 ) ); m_pBackgroundNode->addChild ( m_pCloud2, 6, dustSpeed , ccp ( 100,220 ) ); m_pBackgroundNode->addChild ( m_pCloud4, 6 , dustSpeed , ccp ( 400,200 ) ); m_pBackgroundNode->addChild ( m_pBird1, 6 , dustSpeed , ccp ( 200,160 ) ); m_pBackgroundNode->addChild ( m_pBird2, 6 , dustSpeed , ccp ( 700,180 ) ); m_pBackgroundNode->addChild ( m_pBird3, 6 , dustSpeed , ccp ( 500,260 ) ); m_pBackgroundNode->addChild ( m_pBird4, 6 , dustSpeed , ccp ( 800,200 ) ); // ���ھ� ǥ�� this->m_pScoreLabel = CCLabelTTF::create ( "Score:0", "Marker Felt.ttf", 20 ); m_pScoreLabel ->retain ( ); m_pScoreLabel ->setColor ( ccc3 ( 128, 128, 250 ) ); m_pScoreLabel ->setPosition ( ccp ( 70, 300 ) ); this->addChild ( m_pScoreLabel ,0 ); CCMenuItemImage* pCloseItem = CCMenuItemImage::create ( "SpriteImage/backbutton.png", "SpriteImage/backbutton.png", this, menu_selector ( Level1Scene::onMenu ) ); pCloseItem->setPosition ( ccp ( tLyrSize.cx - 30, tLyrSize.cy - 30 ) ); this->addChild ( CCMenu::createWithItem ( pCloseItem ), 20, 1 ); // ���� �̹���. CCSprite* pSlingshot = CCSprite::create ( "SpriteImage/shooter.png" ); this->addChild ( pSlingshot, 1 ); // b2BodyDef tSlingshotBodyDef; tSlingshotBodyDef.type = b2_dynamicBody; tSlingshotBodyDef.position.Set ( 130.0f / PTM_RATIO, 38.0f / PTM_RATIO ); tSlingshotBodyDef.userData = pSlingshot; m_pSlingBody = m_pWorld->CreateBody ( &tSlingshotBodyDef ); b2PolygonShape tBox; b2FixtureDef tSlingshotBoxDef; tSlingshotBoxDef.shape = &tBox; tSlingshotBoxDef.density = 0.3f; tBox.SetAsBox ( 11.0/PTM_RATIO, 31.0f/PTM_RATIO ); m_pSlingBody->CreateFixture ( &tSlingshotBoxDef ); b2RevoluteJointDef tSlingshotJointDef; tSlingshotJointDef.Initialize ( m_pBody, m_pSlingBody, b2Vec2 ( 140.0f / PTM_RATIO, 0.0f/ PTM_RATIO ) ); tSlingshotJointDef.maxMotorTorque = 800.0f; // ������ġ, 0�̸� �������. tSlingshotJointDef.motorSpeed = -10.0f; tSlingshotJointDef.lowerAngle = CC_DEGREES_TO_RADIANS ( 5 ); tSlingshotJointDef.upperAngle = CC_DEGREES_TO_RADIANS ( 175 ); tSlingshotJointDef.enableLimit = KD_TRUE; tSlingshotJointDef.enableMotor = KD_TRUE; m_pSlingJoint = ( b2RevoluteJoint* ) m_pWorld->CreateJoint ( &tSlingshotJointDef ); m_pTargets = new std::vector<b2Body*>; m_pStructures = new std::vector<b2Body*>; m_pClowns = new std::vector<b2Body*>; m_pClownheads = new std::vector<b2Body*>; m_pRocks = new std::vector<b2Body*>; m_pWoods = new std::vector<b2Body*>; m_pAngle = new std::vector <CCSprite*>; GameSetup ( ); m_pContact = new Level1ContactListener ( ); m_pWorld->SetContactListener ( m_pContact ); schedule ( schedule_selector ( Level1Scene::tick ) ); schedule ( schedule_selector ( Level1Scene::update ) ); return KD_TRUE; }
int GameEngineMain(int argc, _TCHAR* argv[]) // int _main (int argc, const char * const* argv) #endif { bool bStdModuleExist = EngineStdReference(); klb_assert(bStdModuleExist, "The links of a system are insufficient."); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH); glutCreateWindow("GLEW Test"); GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); #define HEIGHT (768) #define WIDTH (1024) #define POS_X (10) #define POS_Y (10) //#define HEIGHT (800) //#define WIDTH (400) int scrW = WIDTH; int scrH = HEIGHT; int fixedDelta = 0; *g_basePath = 0; *g_fileName = 0; g_pathExtern = PATH_EXTERN; g_pathInstall = PATH_INSTALL; g_fileName[0] = 0; bool hasDefaultFont = true; bool hasDefaultDB = false; if (argc > 1) { int parse = 1; int max = argc; while (parse < max) { if(*argv[parse] == '-') { if (strcmp("-w",argv[parse]) == 0) { sscanf_s(argv[parse+1],"%i",&scrW); } if (strcmp("-h",argv[parse]) == 0) { sscanf_s(argv[parse+1],"%i",&scrH); } if (strcmp("-i",argv[parse]) == 0) { g_pathInstall = convertPath(argv[parse+1]); } if (strcmp("-e",argv[parse]) == 0) { g_pathExtern = convertPath(argv[parse+1]); } if (strcmp("-t",argv[parse]) == 0) { fixedDelta = atoi(argv[parse+1]); } if (strcmp("-enc", argv[parse]) == 0) { bool encrypt = false; if (stricmp(argv[parse+1],"true") == 0) { encrypt = true; } if (stricmp(argv[parse+1],"1") == 0) { encrypt = true; } CWin32Platform::setEncrypt(encrypt); } if (strcmp("-no", argv[parse]) == 0) { if (strcmp("defaultfont", argv[parse+1]) == 0) { hasDefaultFont = false; } } parse += 2; } else { // Specify the boot file const char* file = argv[parse]; int lenf = strlen(file); memcpy(g_fileName, file, lenf); g_fileName[lenf] = 0; // ファイル名そのものは start.lua に相当する起動ファイルとする。 // File name of the file used as a start.lua parse++; } } } CWin32PathConv& pathconv = CWin32PathConv::getInstance(); pathconv.setPath(g_pathInstall, g_pathExtern); WNDCLASS wc; HWND hwnd; HDC hDC; HGLRC hRC; HINSTANCE hInstance = GetModuleHandle(NULL); // register window class wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = "GameEngineGL"; RegisterClass( &wc ); // create main window hwnd = CreateWindow( "GameEngineGL", "Playground", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, 256, 256, NULL, NULL, hInstance, NULL ); /* "EngineGL", NULL, WS_THICKFRAME|WS_DISABLED, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL );*/ if (!hwnd) return -1; // enable OpenGL for the window EnableOpenGL( hwnd, &hDC, &hRC ); // COM Initialization CoInitialize(NULL); EnableWindow(hwnd, TRUE); DragAcceptFiles(hwnd, true); RECT area; area.left = 0; area.top = 0; #ifdef _WIN32_WCE area.right = GetSystemMetrics(SM_CXSCREEN); area.bottom = GetSystemMetrics(SM_CYSCREEN); SetWindowLong(hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(hwnd, HWND_TOPMOST, area.left, area.top, area.right, area.bottom, SWP_FRAMECHANGED); #else // Window border hard coded //area.right = scrW + 8; //area.bottom = scrH + 27; ////area.right = GetSystemMetrics(SM_CXSCREEN); ////area.bottom = GetSystemMetrics(SM_CYSCREEN); int addW = GetSystemMetrics(SM_CXSIZEFRAME) * 2; int addH = GetSystemMetrics(SM_CYSIZEFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION); area.right = scrW + addW; area.bottom = scrH + addH; /* AdjustWindowRect( &area, WS_SYSMENU|WS_THICKFRAME|WS_DISABLED, false );*/ SetWindowPos(hwnd, HWND_TOP, area.left, area.top, area.right, area.bottom, SWP_NOMOVE); #endif /* set as foreground window to give this app focus in case it doesn't have it */ SetForegroundWindow(hwnd); ShowWindow(hwnd, SW_SHOWNORMAL); glClearColor(1.0f, 0.7f, 0.2039f, 0.0f); glDisable( GL_CULL_FACE ); // // testCodeInit(); CPFInterface& pfif = CPFInterface::getInstance(); CWin32Platform * pPlatform = new CWin32Platform(hwnd); if (!hasDefaultFont) { pPlatform->setNoDefaultFont(); } pfif.setPlatformRequest(pPlatform); GameSetup(); // client side setup // Can only access client AFTER GameSetup. pfif.client().setInitParam((hasDefaultDB ? IClientRequest::ENGINE_USE_DEFAULTDB : 0) | (hasDefaultFont ? IClientRequest::ENGINE_USE_DEFAULTFONT : 0), NULL); // sound initialize SoundSystemInitFor_Win32(); CWin32AudioMgr::getInstance().init(hwnd); // set screen size pfif.client().setScreenInfo(false, scrW, scrH); // boot path if (strlen(g_fileName)) { pfif.client().setFilePath(g_fileName); } else { pfif.client().setFilePath(NULL); } if (!pfif.client().initGame()) { klb_assertAlways("Could not initialize game, most likely memory error"); } else { static DWORD lastTime = GetTickCount(); // Main message loop: bool quit = false; s32 frameTime = pfif.client().getFrameTime(); IClientRequest& pClient = pfif.client(); while (!quit) { /* relay message queue messages to windowproc's */ MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); if (msg.message == WM_QUIT) { quit = true; break; } DispatchMessage(&msg); } if (!quit) { // This is not the safest or best way to handle timing, but this code // is only added to make the triangle rotate at a basically constant // rate, independent of the target (Win32) platform DWORD newTime = GetTickCount(); DWORD delta = newTime - lastTime; // Handle rollover if (newTime < lastTime) { delta = 0; } else { if (delta > (DWORD)frameTime) { sendEvents(); lastTime = newTime; //dglClear(GL_COLOR_BUFFER_BIT); // // Rendering complete. // //testCodeLoop(delta); pClient.frameFlip(fixedDelta ? fixedDelta : delta); // pfIF.platform().flipFrame(); SwapBuffers( hDC ); } // コントロール(ex. TextBox)が作られている場合、その再描画を行う // If a Control (ex TextBox) is done, redraw them. CWin32Widget::ReDrawControls(); } } Sleep(1); } } pfif.client().finishGame(); SoundSystemExitFor_Win32(); delete pPlatform; // shutdown OpenGL DisableOpenGL( hwnd, hDC, hRC ); CWin32AudioMgr::getInstance().release(); // End of COM CoUninitialize(); if(DestroyWindow (hwnd)) { printf("DestroyWindow SUCCESS\n"); } return 0; }