diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 5df292a..f2f97d0 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -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) diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index 3c0bc7f..94d6067 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -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; diff --git a/src/world/map.c b/src/world/map.c index 5e4ec53..7da29c5 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -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(); } diff --git a/src/world/map.h b/src/world/map.h index 2360875..c36a3b5 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -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;