bool TileManager::next() { if(done()) return false; if(progressive && state.resolution_divider > 1) { state.sample = 0; state.resolution_divider /= 2; state.num_samples = 1; set_tiles(); } else { state.sample++; if(progressive) state.num_samples = 1; else if(range_num_samples == -1) state.num_samples = num_samples; else state.num_samples = range_num_samples; state.resolution_divider = 1; set_tiles(); } return true; }
bool TileManager::next() { if(done()) return false; if(progressive && state.resolution > 1) { state.sample = 0; state.resolution /= 2; set_tiles(); } else { state.sample++; state.resolution = 1; set_tiles(); } return true; }
static void load_tiles (void) { char * path; path = malloc(strlen(OMEGALIB) + strlen(TILEFILE) + 1); if (0 == path) return; strcpy(path, OMEGALIB); strcat(path, TILEFILE); set_tiles(path); free(path); }
// main image handler: probe for best zoom level, then get and draw tiles void manage_imagery() { // return if we don't know what imagery to get if (got_lla_origin == 0) return; // if zoom level unknown, keep probing if (zoom_level_known() == 0){ int ret = run_probe(lat0, lon0); // return if zoom level still unknown if (ret == -1) return; // if zoom level figured out, set zoom level and init tiles zoom_level = ret; ix_iy_from_lat_lon_zoom( &ix0, &iy0, lat0, lon0, zoom_level ); printf("Imagery available at zoom level: %d\n", zoom_level); set_tiles(); } // if zoom level is know, get/load tiles if they're not already gotten for ( int k=0; k < NUM_IMAGE_TILES; k++){ get_imagery( &(image_tiles[k])); draw_tile( &(image_tiles[k]) ); } // finally, display a message when all tiles are fetched/loaded for ( int k=0; k < NUM_IMAGE_TILES; k++) if (image_tiles[k].status != TILE_READY) return; static int last_tile_loaded = 0; if ( last_tile_loaded == 0 ){ last_tile_loaded = 1; printf("Imagery finished downloading and/or loading from cache.\n" "%d image tiles loaded at zoom level %d\n", NUM_IMAGE_TILES, zoom_level); } }
int main( int argc, char* args[] ) { bool quit = false; bool debug = false; int level = 1; Player control(200,700); Ball bullet(200 + PADDLE_WIDTH/2, 500); int tilesDestroyed = 0; float startTicks = 0; float deltaTicks = 0; char ballVelX[5]; char ballVelY[5]; char playerLife[5]; Tile *tiles[TOTAL_TILES]; int destroyedTile[TOTAL_TILES]; for( int t = 0; t < TOTAL_TILES; t++ ) { destroyedTile[t] = false; } if(init() == false) { return 5; } if(load_files() == false) { return 6; } clip_tiles(); if( set_tiles( tiles , level ) == false ) { return 1; } startTicks = SDL_GetTicks(); while(quit == false) { tilesDestroyed = 0; while(SDL_PollEvent(&event)) { if((event.type == SDL_KEYDOWN)) { if(event.key.keysym.sym == SDLK_1 && debug == true)//Adjusting velocity via the 1 number key in debuging mode { bullet.xVelocity += 100; bullet.yVelocity += 100; } else if(event.key.keysym.sym == SDLK_2 && debug == true)//Adjusting velocity via the 2 number key in debuging mode { bullet.xVelocity -= 100; bullet.yVelocity -= 100; } else if(event.key.keysym.sym == SDLK_F1)//Enabling or disabling debuging mode ( information of velocities) { if(debug == false) { debug = true; } else { debug = false; } } } control.handle_input();//Handle the paddle's movement if(event.type == SDL_QUIT) { quit = true; } } deltaTicks = SDL_GetTicks() - startTicks;//Frame rate control.move(deltaTicks); bullet.move(control.player,tiles,deltaTicks,destroyedTile);//Moving the ball SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) );//Black color every frame for( int t = 0; t < TOTAL_TILES; t++ ) { if(destroyedTile[t] == 0) { tiles[ t ]->show(); } } control.show(); bullet.show(); sprintf(ballVelX,"xVel %d",bullet.xVelocity);//Formating text to be displayed for the HUD sprintf(ballVelY,"yVel %d",bullet.yVelocity); sprintf(playerLife,"Life : %d",bullet.life); showBallvelocityX = TTF_RenderText_Solid(font,ballVelX,textColor); showBallvelocityY = TTF_RenderText_Solid(font,ballVelY,textColor); life = TTF_RenderText_Solid(font,playerLife,textColor); apply_surface(20, 10, life, screen ); if(debug == true) { apply_surface(20, 50, showBallvelocityX, screen ); apply_surface(20, 70, showBallvelocityY, screen ); SDL_FreeSurface(showBallvelocityY); SDL_FreeSurface(showBallvelocityX); } startTicks = SDL_GetTicks(); deltaTicks = 0; for( int t = 0; t < TOTAL_TILES; t++ )//Checking how many tiles are destroyed in the game { if(destroyedTile[t] == 1) { tilesDestroyed++; } } if(bullet.life == 0 || tilesDestroyed == TOTAL_TILES)//Close the game if life drops to zero or all the tiles are destroyed in the game { quit = true; } if( SDL_Flip( screen ) == -1 ) { return 1; } } clean_up(); return 0; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //The dot Dot myDot; //The tiles that will be used Tile *tiles[ TOTAL_TILES ]; //The frame rate regulator Timer fps; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Clip the tile sheet clip_tiles(); //Set the tiles if( set_tiles( tiles ) == false ) { return 1; } //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the dot myDot.handle_input(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the dot myDot.move( tiles ); //Set the camera myDot.set_camera(); //Show the tiles for( int t = 0; t < TOTAL_TILES; t++ ) { tiles[ t ]->show(); } //Show the dot on the screen myDot.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up( tiles ); return 0; }
int main( int argc, char* args[] ) { quit = 0; Tile *tiles[ TOTAL_TILES ]; Timer fps; levelwon = 0; //Initialize if( init() == false ) { return 1; } if( TTF_Init() == -1 ) { return false; } //Initialize SDL_mixer if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } //Load the files if( load_files() == false ) { return 1; } //Clip the tile sheeti if( Mix_PlayMusic( music, -1 ) == -1 ) { return 1; } clip_tiles(); if(!welcome)return 1; SDL_BlitSurface(welcome, NULL, screen, NULL ); SDL_Flip( screen ); SDL_Delay(6000); robin robinp; while(quit ==false) { if(level!= 1) { SDL_BlitSurface( prepare, NULL, screen, NULL ); SDL_Flip(screen); SDL_Delay(3000); } robinp.reset(); //Set the tiles if( set_tiles( tiles ) == false ) { return 1; } // SDL_Delay(3000); first=1; ///////////////////////////////////////////////////////////////////////////////////// while( quit == false && levelwon == 0)/////////////////////////////////// { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { robinp.handle_events(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } SDL_BlitSurface( background, NULL, screen, NULL ); robinp.move(tiles); robinp.set_camera(); for( int t = 0; t < TOTAL_TILES; t++ ) { tiles[ t ]->show(); } for(int i=0;i< en_num;i++) { enemys[en_num]->show(); //robinp.reset(); } robinp.show(); showscore(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } clean_up(tiles); level++; levelwon = 0; ///////////////////////////////////////////////////////////////////////////////////// //cout<<"out of level"; } SDL_FreeSurface( background ); SDL_FreeSurface( gameover ); SDL_FreeSurface( tileSheet ); //Free the music Mix_FreeMusic( music ); Mix_FreeChunk( jumpsou ); Mix_FreeChunk( coinsou ); Mix_FreeChunk( hitsou ); Mix_FreeChunk( diamoundsou ); //Close the font TTF_CloseFont( font ); //Quit SDL_mixer Mix_CloseAudio(); SDL_Quit(); //Quit SDL_ttf TTF_Quit(); return 0; }