PixelWars/generators/realWorld.cpp
2016-06-03 11:04:27 +02:00

37 lines
900 B
C++

#include <map.h>
#include <stdlib.h>
#include "image.h"
// windows MinGW
// g++ -shared realWorld.cpp -o realWorld.dll -I../src -funsigned-char -std=c++11
// linux gcc
// g++ -shared realWorld.cpp -o realWorld.so -I../src -fPIC -funsigned-char -std=c++11
extern "C" void generate(Map *mapPtr)
{
Map &map = *mapPtr;
int w = map.getWidth();
int h = map.getHeight();
int n = map.getNbTeams();
for(int i = 0 ; i < h ; i++){
for(int j = 0 ; j < w ; j++){
int ti = i*height/h;
int tj = j*width/w;
int to = ti*width+tj;
unsigned char * pix = (unsigned char*)header_data_cmap[(unsigned char)header_data[to]];
map[j][i].type = pix[0]?BERRIES:GRASS;
}
}
for(int i=0; i<n; i++){
Coord c = Coord((w/(n*2))*(1+i*2)+rand()%20-10, h/2+rand()%20-10);
map.team(i) = c;
map[c].type = SPAWN;
map[c.x+1][c.y].type = GRASS;
map[c].data.teamId = i;
}
}