Load map data.
This commit is contained in:
parent
372f19df03
commit
118b570484
|
@ -34,6 +34,8 @@ void initAtlasTest(void)
|
|||
testImage = getImageFromAtlas("gfx/sprites/evilblobs/machineGunBlobRight1.png");
|
||||
|
||||
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||
|
||||
loadMapData("data/maps/raw/beachApproach.raw");
|
||||
}
|
||||
|
||||
static void logic(void)
|
||||
|
|
|
@ -23,5 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
extern Atlas *getImageFromAtlas(char *filename);
|
||||
extern Texture *getTexture(const char *filename);
|
||||
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||
extern void loadMapData(char *filename);
|
||||
|
||||
extern App app;
|
||||
|
|
|
@ -93,7 +93,7 @@ int isBreakable(int x, int y)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void calculateMapBounds(void)
|
||||
static void calculateMapBounds(void)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
|
@ -144,4 +144,54 @@ void calculateMapBounds(void)
|
|||
|
||||
world.map.bounds.w += MAP_TILE_SIZE;
|
||||
world.map.bounds.h += MAP_TILE_SIZE;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Map bounds [%d, %d, %d, %d]", world.map.bounds.x, world.map.bounds.y, world.map.bounds.w, world.map.bounds.h);
|
||||
}
|
||||
|
||||
void loadMapData(char *filename)
|
||||
{
|
||||
char *data, *p;
|
||||
int i, x, y;
|
||||
|
||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
||||
|
||||
data = readFile(filename);
|
||||
|
||||
p = data;
|
||||
|
||||
for (y = 0 ; y < MAP_HEIGHT ; y++)
|
||||
{
|
||||
for (x = 0 ; x < MAP_WIDTH ; x++)
|
||||
{
|
||||
sscanf(p, "%d", &i);
|
||||
|
||||
if (!world.isOutpostMission)
|
||||
{
|
||||
if (i >= 4 && i <= 7)
|
||||
{
|
||||
i = rrnd(4, 7);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i >= 4 && i <= 8)
|
||||
{
|
||||
i = rrnd(4, 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 200 && i <= 203)
|
||||
{
|
||||
i = rrnd(200, 203);
|
||||
}
|
||||
|
||||
world.map.data[x][y] = i;
|
||||
|
||||
do {p++;} while (*p != ' ');
|
||||
}
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
calculateMapBounds();
|
||||
}
|
||||
|
|
|
@ -25,5 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
extern float limit(float i, float a, float b);
|
||||
extern int rrnd(int low, int high);
|
||||
extern char *readFile(const char *filename);
|
||||
|
||||
extern World world;
|
||||
|
|
Loading…
Reference in New Issue