bool MainGameLayer::init() { isLeftTouched = false; isSwipeStart = false; iSwipeStartY = 0; iSwipeEndY = 0; // Touch Director* director = Director::getInstance(); director->getTouchDispatcher()->addTargetedDelegate(this, 0, true); // box2d physics Box2dDirectorLayer* box2dDL = Box2dDirectorLayer::create(); addChild(box2dDL, 1, kTagLayerBox2dD); // background initBackground(); // HUD initHUD(); // Particles _bladeSparkle = ParticleSystemQuad::create("Particles/blade_sparkle.plist"); _bladeSparkle->stopSystem(); addChild(_bladeSparkle, 3); // Sounds SimpleAudioEngine::getInstance()->preloadEffect("Sounds/swoosh.caf"); SimpleAudioEngine::getInstance()->preloadEffect("Sounds/squash.caf"); SimpleAudioEngine::getInstance()->preloadEffect("Sounds/toss_consecutive.caf"); SimpleAudioEngine::getInstance()->preloadEffect("Sounds/toss_simultaneous.caf"); SimpleAudioEngine::getInstance()->preloadEffect("Sounds/toss_bomb.caf"); SimpleAudioEngine::getInstance()->preloadEffect("Sounds/lose_life.caf"); SimpleAudioEngine::getInstance()->playBackgroundMusic("Sounds/nature_bgm.aifc"); _timeCurrent = 0; //// TMX /*TileMapLayer* tilemapL = TileMapLayer::create(); addChild(tilemapL, 1, kTagTileMap); tilemapL->createWithTMX("grassMap.tmx"); */ //addMissionaries(); // polygon sprite /*PolygonSprite *sprite = (new Watermelon())->initWithWorld(box2dDL->world); addChild(sprite, 1); sprite->activateCollisions();*/ // Raycast //_raycastCallback = new RaycastCallback(); return true; }
HUDLayer::HUDLayer() { bool bRet = false; do { CC_BREAK_IF(! HUDLayer::init()); initHUD(); } while(0); //return bRet; }
//------------------------------------------------------------------------------ int main(int argc, char ** argv) { bool fullscreen = false; std::string str; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-d")) g_level = atoi(argv[++i]); else if (!strcmp(argv[i], "-c")) g_repeatCount = atoi(argv[++i]); else if (!strcmp(argv[i], "-f")) fullscreen = true; else { std::ifstream ifs(argv[1]); if (ifs) { std::stringstream ss; ss << ifs.rdbuf(); ifs.close(); str = ss.str(); g_defaultShapes.push_back(SimpleShape(str.c_str(), argv[1], kCatmark)); } } } initializeShapes(); OsdSetErrorCallback(callbackError); if (not glfwInit()) { printf("Failed to initialize GLFW\n"); return 1; } static const char windowTitle[] = "OpenSubdiv glBatchViewer"; #define CORE_PROFILE #ifdef CORE_PROFILE setGLCoreProfile(); #endif #if GLFW_VERSION_MAJOR>=3 if (fullscreen) { g_primary = glfwGetPrimaryMonitor(); // apparently glfwGetPrimaryMonitor fails under linux : if no primary, // settle for the first one in the list if (not g_primary) { int count=0; GLFWmonitor ** monitors = glfwGetMonitors(&count); if (count) g_primary = monitors[0]; } if (g_primary) { GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary); g_width = vidmode->width; g_height = vidmode->height; } } if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL))) { printf("Failed to open window.\n"); glfwTerminate(); return 1; } glfwMakeContextCurrent(g_window); glfwSetKeyCallback(g_window, keyboard); glfwSetCursorPosCallback(g_window, motion); glfwSetMouseButtonCallback(g_window, mouse); glfwSetWindowSizeCallback(g_window, reshape); #else if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { printf("Failed to open window.\n"); glfwTerminate(); return 1; } glfwSetWindowTitle(windowTitle); glfwSetKeyCallback(keyboard); glfwSetMousePosCallback(motion); glfwSetMouseButtonCallback(mouse); glfwSetWindowSizeCallback(reshape); #endif #if defined(OSD_USES_GLEW) #ifdef CORE_PROFILE // this is the only way to initialize glew correctly under core profile context. glewExperimental = true; #endif if (GLenum r = glewInit() != GLEW_OK) { printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r)); exit(1); } #ifdef CORE_PROFILE // clear GL errors which was generated during glewInit() glGetError(); #endif #endif // activate feature adaptive tessellation if OSD supports it g_adaptive = OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation(); initGL(); glfwSwapInterval(0); initHUD(); callbackModel(g_currentShape); g_fpsTimer.Start(); while (g_running) { idle(); display(); #if GLFW_VERSION_MAJOR>=3 glfwPollEvents(); glfwSwapBuffers(g_window); #else glfwSwapBuffers(); #endif } uninitGL(); glfwTerminate(); }
//------------------------------------------------------------------------------ int main(int argc, char ** argv) { bool fullscreen = false; std::string str; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-d")) g_level = atoi(argv[++i]); else if (!strcmp(argv[i], "-c")) g_repeatCount = atoi(argv[++i]); else if (!strcmp(argv[i], "-f")) fullscreen = true; else { std::ifstream ifs(argv[1]); if (ifs) { std::stringstream ss; ss << ifs.rdbuf(); ifs.close(); str = ss.str(); g_shapes.push_back(ShapeDesc(argv[1], str.c_str(), kCatmark)); } } } initShapes(); if (not glfwInit()) { printf("Failed to initialize GLFW\n"); return 1; } static const char windowTitle[] = "OpenSubdiv vtrViewer"; #define CORE_PROFILE #ifdef CORE_PROFILE setGLCoreProfile(); #endif if (fullscreen) { g_primary = glfwGetPrimaryMonitor(); // apparently glfwGetPrimaryMonitor fails under linux : if no primary, // settle for the first one in the list if (not g_primary) { int count=0; GLFWmonitor ** monitors = glfwGetMonitors(&count); if (count) g_primary = monitors[0]; } if (g_primary) { GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary); g_width = vidmode->width; g_height = vidmode->height; } } if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL))) { printf("Failed to open window.\n"); glfwTerminate(); return 1; } glfwMakeContextCurrent(g_window); // accommocate high DPI displays (e.g. mac retina displays) glfwGetFramebufferSize(g_window, &g_width, &g_height); glfwSetFramebufferSizeCallback(g_window, reshape); glfwSetKeyCallback(g_window, keyboard); glfwSetCursorPosCallback(g_window, motion); glfwSetMouseButtonCallback(g_window, mouse); glfwSetWindowCloseCallback(g_window, windowClose); #if defined(OSD_USES_GLEW) #ifdef CORE_PROFILE // this is the only way to initialize glew correctly under core profile context. glewExperimental = true; #endif if (GLenum r = glewInit() != GLEW_OK) { printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r)); exit(1); } #ifdef CORE_PROFILE // clear GL errors which was generated during glewInit() glGetError(); #endif #endif initGL(); glfwSwapInterval(0); initHUD(); rebuildOsdMeshes(); checkGLErrors("before loop"); while (g_running) { idle(); display(); glfwPollEvents(); glfwSwapBuffers(g_window); glFinish(); } uninitGL(); glfwTerminate(); }
bool gameLoop() { initLevelManager(); loadLevel(g_LevelManager, 0); initHUD(); bool done = false; int moveStartTime = SDL_GetTicks(); while(!done) { int startTime = SDL_GetTicks(); // handle game lose situation (timer has run out, eaten by monster) // now handled in cLevelManager::update() SDL_Event event; while(SDL_PollEvent(&event)) { //check for messages switch(event.type) { case SDL_QUIT: done = true; break; //check for keypresses case SDL_KEYDOWN: { //handle keypresses switch(event.key.keysym.sym) { case SDLK_ESCAPE: g_LevelManager.stop(); done = true; return true; break; case SDLK_m: g_LevelManager.stop(); done = true; return false; break; case SDLK_r: g_LevelManager.endLevel(); moveStartTime = SDL_GetTicks(); loadLevel(g_LevelManager, g_LevelManager.getCurrentLevel()); break; case SDLK_n: nextLevel(); moveStartTime = SDL_GetTicks(); break; case SDLK_p: prevLevel(); moveStartTime = SDL_GetTicks(); break; default: g_InputManager.updateKey(event.key.keysym.sym); break; } } } //end switch } //end of message processing //autoplay routine (if level autoplay enabled) if(g_LevelManager.activeLevel()->autoPlay()) { if(g_LevelManager.activePlayer()->moveNumber() < g_LevelManager.activePlayer()->movesSize()) { int moveCheckTime = SDL_GetTicks(); if(moveCheckTime - moveStartTime >= 300) { g_InputManager.update(); moveStartTime = moveCheckTime; } } } g_InputManager.autoUpdate(); //do game update /*****update graphics*****/ //clear screen SDL_FillRect(screen,0,SDL_MapRGB(screen->format,0,0,0)); //SDL_FillRect(display,0,SDL_MapRGB(display->format,0,0,0)); //draw image g_RenderManager.update(); int endTime = SDL_GetTicks(); if(endTime - startTime < 1000/fps) SDL_Delay(1000/fps - (endTime - startTime)); //end frame SDL_Flip(screen); //level win now handled in cLevelManager::update() if(g_LevelManager.checkWin()) { done = true; return false; } /* if(levelWon()) { nextLevel(); } */ } return done; //do exit }