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
| #include "map.h"
#include "constantes.h"
#include <string>
using namespace std;
Map::Map() :width(0),height(0),offsetX(0),offsetY(0),surf_chipset(NULL)
{
}
Map::~Map()
{
SDL_FreeSurface(surf_chipset);
free(data);
free(chipset);
}
void Map::aleatoire( int width, int height, char *chipset)
{
int i,x,y;
surf_chipset =SDL_LoadBMP(chipset);
/* Couleur transparente pour l'image */
SDL_SetColorKey(surf_chipset, SDL_SRCCOLORKEY, SDL_MapRGB(surf_chipset->format,8,33,82));
n_tile=(surf_chipset->w/TILE_WIDTH)*(surf_chipset->h/TILE_HEIGHT);
struct s_chipset tableau[i];
for (i=0;i<n_tile;i++)
{
tableau[i].x=x;
tableau[i].y=y;
tableau[i].collision=0;
tableau[i].nextTile=0;
x += TILE_WIDTH;
if (x>(surf_chipset->w-TILE_WIDTH))
{
x=0;
y+= TILE_HEIGHT;
}
}
width=width;
height=height;
data =(unsigned int*) malloc(width*height*sizeof(unsigned int));
for(x=0;x<width;x++)
for(y=0;y<height;y++)
data[x+y*width]=rand()%(n_tile);
} |
Partager