1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
//Render Map
SDL_Surface* render_map( SDL_Surface *chipset )
{
//Init of graph coordinats
int x;
int y;
//SDL_Surface
SDL_Surface *temp_map = NULL;
//Map array
int map_offset [15][6]=
{
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2},
{4,5,3,0,1,2},
{1,2,3,0,1,2},
{1,2,3,0,1,2}
};
//Rect
SDL_Rect set[6];
//Sprite map left corner top
set[0].x = 0;
set[0].y = 0;
set[0].w = 32;
set[0].h = 32;
//Sprite map left corner bottom
set[3].x = 0;
set[3].y = 32;
set[3].w = 32;
set[3].h = 32;
//Sprite map middle top
set[1].x = 32;
set[1].y = 0;
set[1].w = 32;
set[1].h = 32;
//Sprite map middle bottom
set[4].x = 32;
set[4].y = 32;
set[4].w = 32;
set[4].h = 32;
//Sprite map right corner top
set[2].x = 64;
set[2].y = 0;
set[2].w = 32;
set[2].h = 32;
//Sprite map right corner bottom
set[5].x = 64;
set[5].y = 64;
set[5].w = 32;
set[5].h = 32;
//Loop for map drawing
for(y=0; y<MAP_HEIGHT; y++)
{
for(x=0 ; x<MAP_WIDTH; x++)
{
switch(map_offset[y][x])
{
case 1 : apply_surface(x*32, y*32, chipset, temp_map, &set[0]); break;
case 2 : apply_surface(x*32, y*32, chipset, temp_map, &set[1]); break;
case 3 : apply_surface(x*32, y*32, chipset, temp_map, &set[2]); break;
case 4 : apply_surface(x*32, y*32, chipset, temp_map, &set[3]); break;
case 5 : apply_surface(x*32, y*32, chipset, temp_map, &set[4]); break;
case 6 : apply_surface(x*32, y*32, chipset, temp_map, &set[5]); break;
default : break;
}
}
}
//Return the rendered image
return temp_map;
}
|