//------------------------------------------------------------------------- char runGame() { int offset; char i, willyCollideSprites = ColNoCol; BOOL willyCollideBackground = NO; if(m_keysFound == m_keysToFind) { ++m_keysFound; for(i = level2Sprite[m_level].index ;; ++i) { SpriteData *sprt = &spriteData[i]; if(sprt->spriteClass & SPClass_Door) { sprt->curEnabled = 1; m_doorToggle = 0; break; } else if(sprt->spriteClass & SPClass_Eugene) { sprt->curDirection = 1; sprt->curLocalStorage = 1; } } } else { for(i = 0; i < MaxKeysPerLevel; ++i) { offset = screenRowStart[keyPositions[m_level][i].y]+keyPositions[m_level][i].x ; if(WorldEmpty != SCREEN_RAM[offset]) incColourRamBy(offset, (i+1)); } } if(!--m_airAmount) return ColDie; moveSprites(); if(LEVEL_Solar_Power_Generator == m_level) buildPowerBeamPath(); if(GSTATE_Demo != m_gameState) willyCollideBackground = moveWilly(); renderFrame(); if(willyCollideBackground || (willyCollideSprites = checkSpriteCollisions())) { if(willyCollideSprites & ColDoor) return ColDoor; return ColDie; } return ColNoCol; }
int main(void) { int i; int memUsageTemp = 0xFFFFFFFF; videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); vramSetBankB(VRAM_B_MAIN_SPRITE); vramSetBankD(VRAM_D_SUB_SPRITE); consoleDemoInit(); // consoleDebugInit(DebugDevice_NOCASH); //send stderr to no$gba debug window //api: initialize OAM to 1D mapping with XX byte offsets and no external palette oamInit(oam, SpriteMapping_1D_128, false); //create some sprites for(i = 0; i < SPRITE_MAX; i++) randomSprite(&sprites[i]); //load a randomly colored palette for(i = 0; i < 256; i++) { SPRITE_PALETTE[i] = rand(); SPRITE_PALETTE_SUB[i] = rand(); } while(1) { moveSprites(); updateSprites(); swiWaitForVBlank(); //api: updates real oam memory oamUpdate(oam); if(oom) { memUsageTemp = memUsageTemp > spriteMemoryUsage ? spriteMemoryUsage : memUsageTemp; } consoleClear(); printf("Memory usage: %i %i%% \n", spriteMemoryUsage, 100 * spriteMemoryUsage / (spriteMemSize)); printf("Percentage fail: %i%% \n", oomCount * 100 / allocationCount); printf("Lowest Usage at fail %i %i%% \n", memUsageTemp, 100 * memUsageTemp / (spriteMemSize)); } return 0; }
//--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- // Initialize graphics gfxInitDefault(); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); // Initialize the render target C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); C3D_RenderTargetSetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); // Initialize the scene sceneInit(); // Main loop while (aptMainLoop()) { hidScanInput(); // Respond to user input u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu moveSprites(); // Render the scene C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameDrawOn(target); sceneRender(); C3D_FrameEnd(0); } // Deinitialize the scene sceneExit(); // Deinitialize graphics C3D_Fini(); gfxExit(); return 0; }
int main() { cv::namedWindow("render", cv::WINDOW_NORMAL); // cv::Mat map = cv::imread("test_map.bmp", cv::IMREAD_GRAYSCALE); EdgeMap map; /* map.push_back(Edge(-9.950000f, 8.350000f, -0.400000f, -8.300000f, 150)); map.push_back(Edge(-0.400000f, -8.300000f, 12.400000f, 4.100000f, 150)); map.push_back(Edge(12.400000f, 4.100000f, 1.000000f, 1.800000f, 150)); map.push_back(Edge(1.000000f, 1.800000f, -9.950000f, 8.350000f, 150)); */ map.push_back(Edge(10.0f, 10.0f, 10.0f, -10.0f, 100)); map.push_back(Edge(10.0f, -10.0f, 1.0f, -1.0f, 100)); map.push_back(Edge(1.0f, -1.0f, -10.0f, -10.0f, 100)); map.push_back(Edge(-10.0f, -10.0f, -10.0f, 10.0f, 100)); map.push_back(Edge(-10.0f, 10.0f, 10.0f, 10.0f, 100)); int wndWidth = 1440; int wndHeight = 900; cv::Mat render(wndHeight,wndWidth, CV_8UC3); float df = 0.0f; float ds = 0.0f; float x = 0.0f; float y = 0.0f; float angle = -M_PI/2.0f; float dangle = 0.3f; float fov = M_PI/3.0f; std::vector<Sprite> sprites; Sprite ballSprite; // ballSprite.states.push_back(cv::imread("svidetel.jpg")); // ballSprite.x = 32; // ballSprite.y = -32; // ballSprite.width = 2; sprites.push_back(ballSprite); Texpack texpack; texpack[50] = Texture(cv::imread("wall_window.bmp")); texpack[100] = Texture(cv::imread("wood_wall.jpeg")); texpack[150] = Texture(cv::imread("brick_wall.jpeg")); texpack[200] = Texture(cv::imread("doom_door.jpeg")); for(int i = 1; i<15; i++) { char buf[1000]; sprintf(buf,"doom_door_%d.jpg", i); texpack[200].addFrame(cv::imread(buf)); } for(int i = 14; i>0; i--) { char buf[1000]; sprintf(buf,"doom_door_%d.jpg", i); texpack[200].addFrame(cv::imread(buf)); } texpack[200].animationTime = 2; texpack[200].animationType = Texture::ANIMATION_FRAMES; cv::Mat bgImageRaw = cv::imread("bg.png"); cv::Mat bgImage; cv::resize(bgImageRaw, bgImage, cv::Size(2.0f*M_PI*(float)wndWidth/fov,wndHeight)); double prevTime = getTime(); while(1) { double cTime = getTime(); animateTextures(texpack, cTime); calcNewPosition(map, x, y, angle, df, ds, dangle, cTime - prevTime); moveSprites(sprites); prevTime = cTime; newRenderAt(render, map, bgImage, fov, wndWidth, texpack, sprites, x, y, angle); cv::imshow("render",render); /* cv::Mat mapD; cv::resize(map, mapD, cv::Size(640,640), 0, 0, cv::INTER_NEAREST); cv::line(mapD, cv::Point(x*10.0f,-y*10.0f), cv::Point(x + cos(-angle - fov/2.0f)*1000, y + sin(-angle - fov/2.0f)*1000)*10.0f, cv::Scalar(0,255,0,0),1); cv::line(mapD, cv::Point(x*10.0f,-y*10.0f), cv::Point(x + cos(-angle + fov/2.0f)*1000, y + sin(-angle + fov/2.0f)*1000)*10.0f, cv::Scalar(0,255,0,0),1); cv::imshow("map", mapD); */ int k = cv::waitKey(1); if((char)k == 'q') { break; } else if((char)k == ',') { ds = 5.0f; } else if((char)k == '.') { ds = -5.0f; } else if((char)k == 'a') { dangle = +1.0f; } else if((char)k == 'd') { dangle = -1.0f; } else if((char)k == 's') { df = -5.0f; } else if((char)k == 'w') { df = 5.0f; } else if((char)k == '[') { fov -= M_PI/180.0f; //myLidar = VirtualLidar(fov, render.cols, 0); } else if((char)k == ']') { fov += M_PI/180.0f; //myLidar = VirtualLidar(fov, render.cols, 0); } else if((char)k == 'e'){ ds = 0; df = 0; dangle = 0; } else { if(df > 1) df -= 5; else if(df < -1) df += 5; else df = 0; if(ds > 1) ds -= 5; else if(ds < -1) ds += 5; else ds = 0; if(dangle > 0.5f) { dangle -= 1.0f; } else if(dangle < -0.5f) { dangle += 1.0f; } else { dangle = 0; } } } return 0; }
/*********************************************************** synopsis: a big while loop that runs the full length of the game, checks the game events and responds accordingly event action ------------------------------------------------- winGame stop the clock and solve puzzle timeRemaining update the clock tick timeUp stop the clock and solve puzzle solvePuzzle trigger solve puzzle and stop clock updateAnswers trigger update answers startNew trigger start new updateScore trigger update score shuffle trigger shuffle clear trigger clear answer quit end loop poll events check for keyboard/mouse and quit finally, move the sprites -this is always called so the sprites are always considered to be moving no "move sprites" event exists - sprites x&y just needs to be updated and they will always be moved inputs: head - first node in the answers list (in/out) dblHead - first node in the dictionary list screen - the SDL_Surface to display the image letters - first node in the letter sprites (in/out) outputs: n/a ***********************************************************/ static void gameLoop(struct node **head, struct dlb_node *dlbHead, SDL_Surface *screen, struct sprite **letters) { int j,k; int done=0; int numofwords=1; SDL_Event event; time_t timeNow; SDL_TimerID timer; int timer_delay = 20; char buffer[512]; #ifdef demo if (conf.totalgames < 0){ conf.totalgames=8; } conf.totalgames +=1;//demo tags sprintf(buffer,"globaldata/agdemo.cfg"); saveCFG(buffer,&conf); #endif timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); /* main game loop */ while (!done) { if (winGame) { stopTheClock = 1; solvePuzzle = 1; } if ((gameTime < AVAILABLE_TIME) && !stopTheClock) { timeNow = time(0) - gameStart; if (timeNow != gameTime){ gameTime = timeNow; updateTime(screen); } } else { if (!stopTheClock){ stopTheClock = 1; solvePuzzle = 1; } } /* check messages */ if (solvePuzzle) { /* walk the list, setting everything to found */ solveIt(*head); clearWord(letters); strcpy(shuffle, SPACE_FILLED_STRING); strcpy(answer, rootWord); /*displayLetters(screen);*/ displayAnswerBoxes(*head, screen); gamePaused = 1; if (!stopTheClock){ stopTheClock = 1; } solvePuzzle = 0; } if (updateAnswers){ /* move letters back down again */ clearWord(letters); /* displayLetters(screen);*/ displayAnswerBoxes(*head, screen); updateAnswers = 0; } if ((stopTheClock && !gotBigWord && !checkScore)||(startNewGame&&!gotBigWord& !checkScore)){ //Error("inside highscore\n"); for(j=9;j>=0 && hiscore[j].score<totalScore;j--); //Error("score position: %i\n",j); /* the player will be in the hall of fame? */ if(j<9) { for(k=8;k>j;k--) hiscore[k+1]=hiscore[k]; /* put the new score */ hiscore[j+1].score=totalScore; hiscore[j+1].stage=numofwords; //hiscore[j+1].name[0]=0; //if(!getName(hiscore[j+1].name, j+2,i+1)) // break; /* probably a problem if the user closes the window */ /* show the hall of fame */ //hiscores(); /* save hi-scores */ #ifdef demo sprintf(buffer,"/media/internal/appdata/com.cribme.aghddemo/ag-hiscore"); #else sprintf(buffer,"/media/internal/appdata/com.cribme.aghd/ag-hiscore"); #endif //sprintf(buffer,"globaldata/ag-hiscore"); if(!saveScore(buffer,hiscore)) fprintf(stderr,"unable to save hi-scores\ndo you have permissions to write into %s?\n" ,buffer); } checkScore=1; } if (startNewGame) { /* move letters back down again */ if (!gotBigWord){ totalScore = 0; numofwords=0; } newGame(head, dlbHead, screen, letters); #ifdef demo conf.totalgames +=1;//demo tags char buffer[512]; sprintf(buffer,"globaldata/agdemo.cfg"); //Error("Buffer :%s\n",buffer); //Error("TotalGames Written to file :%i\n",conf.totalgames); saveCFG(buffer,&conf); #endif numofwords+=1; checkScore = 0; startNewGame = 0; } if (updateTheScore) { updateScore(screen); updateTheScore = 0; } if (shuffleRemaining) { /* shuffle up the shuffle box */ char shuffler[8]; strcpy(shuffler, shuffle); shuffleAvailableLetters(shuffler, letters); strcpy(shuffle, shuffler); shuffleRemaining = 0; } if (clearGuess) { /* clear the guess; */ if (clearWord(letters) > 0) { Mix_PlayChannel(-1, getSound("clear"),0); } clearGuess = 0; } #ifdef demo //Error("TotalGames:%i\n",conf.totalgames);//conf.totalgames if (conf.totalgames > 8){//conf.totalgames destroyLetters(letters); strcpy(txt, language); ShowBMP(strcat(txt,"images/demo.bmp"),screen, 100,75); done=1; } #endif if (quitGame) { done = 1; } if (inactive){ SDL_WaitEvent(&event); if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) { inactive = 0; timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); } } else { while (SDL_WaitEvent(&event)) { if (event.type == SDL_ACTIVEEVENT && event.active.gain == 0) { inactive = 1; break; } if (event.type == SDL_USEREVENT) { timer_delay = anySpritesMoving(letters) ? 10 : 100; moveSprites(&screen, letters, letterSpeed); timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); break; } else if (event.type == SDL_MOUSEBUTTONDOWN) { clickDetect(event.button.button, event.button.x, event.button.y, screen, *head, letters); moveSprites(&screen, letters, letterSpeed);//added by me } else if (event.type == SDL_KEYUP) { handleKeyboardEvent(&event, *head, letters); } else if (event.type == SDL_QUIT) { done = 1; break; } } } } #ifdef demo while(conf.totalgames > 8){//conf.totalgames while(SDL_WaitEvent(&event)){ if (event.type == SDL_MOUSEBUTTONDOWN) { PDL_ServiceCall("palm://com.palm.applicationManager/open", "{\"target\":\"http://developer.palm.com/appredirect/?packageid=com.cribme.aghd\"}"); //PDL_LaunchBrowser("http://developer.palm.com/appredirect/?packageid=com.cribme.aghd"); } } } #endif }