Sign in to follow this  
peb

Problems with scrolling maps and SDL

Recommended Posts

Hello... im trying to make a scrolling map with SDL... i get no errors the problem is that the pictures just dosnt show... heres the code: SDL_Surface *screen; int game_state; int i; int x; int y; int bytecount; SDL_Surface *tiles[3]; int world[100*100];//map is 100x100 void load() { tiles[0] = SDL_LoadBMP("gfx/water.bmp"); tiles[1] = SDL_LoadBMP("gfx/desert.bmp"); tiles[2] = SDL_LoadBMP("gfx/grass.bmp"); long size; int bytecount; int count; FILE *f; f=fopen("maps/desert.map","r"); if (f==NULL) perror ("Error opening file desert.map"); else { fseek (f, 0, SEEK_END); size=ftell (f); fclose (f); bytecount = size; } int world_index = 0;//stores our position in the world array while(i<bytecount) { int temp = fgetc(f);//read a tile index from the file world[world_index] = temp;//store value from file in our world map array ++world_index;//move to next position in array i=i+1; } } //this is to be called from your game loop //this is the same code from the earlier example int world_x;//player's x position in the world int world_y;//player's y position in the wolrd //...insert code that get player input and updates world_x and world_y based on player input. void draw() { int x, y; //assume player character is at center of screen //find start position to draw from in tile array int start_x = world_x-10;//assume tiles are 32x32 and screen width is 640. int start_y = world_y-7;//assume tiles are 32x32 and screen height is 480. for(y = start_y; y < start_y+15; ++y)//again, assumes 15 rows { for(x = start_x; x < start_x+20; ++x)//assumes 20 columns { //find out which tile we are currently looking for int tile_index = world[y*20+x]; //use that value to get the tile from the tile set array SDL_Surface *curr_tile = tiles[tile_index]; //draw the current tile. sorry, dont know real funtion name ShowBMP(curr_tile, screen, 0, 0); } } SDL_Delay(1000); }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this