summaryrefslogtreecommitdiff
path: root/src/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/src/map.c b/src/map.c
index 2b22888..29f9d55 100644
--- a/src/map.c
+++ b/src/map.c
@@ -3,19 +3,19 @@
static int get_height_of_tile_tl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map[y-1][x];
+ int tile_above = map_to_load.heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x > 0) {
- int tile_above = map[y-1][x-1];
+ int tile_above = map_to_load.heightmap[y-1][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (x > 0) {
- int tile_above = map[y][x-1];
+ int tile_above = map_to_load.heightmap[y][x-1];
if (tile_above > highest_point) {
highest_point = tile_above;
}
@@ -27,19 +27,19 @@ static int get_height_of_tile_tl(int current_height, int x, int y) {
static int get_height_of_tile_br(int current_height, int x, int y) {
int highest_point = current_height;
if (x < MAP_SIZE_X-1) {
- int tile_right = map[y][x+1];
+ int tile_right = map_to_load.heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
}
if (y < MAP_SIZE_Y-1 && x < MAP_SIZE_X-1) {
- int tile_bottom_right = map[y+1][x+1];
+ int tile_bottom_right = map_to_load.heightmap[y+1][x+1];
if (tile_bottom_right > highest_point) {
highest_point = tile_bottom_right;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map[y+1][x];
+ int tile_bottom = map_to_load.heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -50,19 +50,19 @@ static int get_height_of_tile_br(int current_height, int x, int y) {
static int get_height_of_tile_bl(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0 && x > 0) {
- int tile_left = map[y][x-1];
+ int tile_left = map_to_load.heightmap[y][x-1];
if (tile_left > highest_point) {
highest_point = tile_left;
}
}
if (y < MAP_SIZE_Y-1 && x > 0) {
- int tile_bottom_left = map[y+1][x-1];
+ int tile_bottom_left = map_to_load.heightmap[y+1][x-1];
if (tile_bottom_left > highest_point) {
highest_point = tile_bottom_left;
}
}
if (y < MAP_SIZE_Y-1) {
- int tile_bottom = map[y+1][x];
+ int tile_bottom = map_to_load.heightmap[y+1][x];
if (tile_bottom > highest_point) {
highest_point = tile_bottom;
}
@@ -73,19 +73,19 @@ static int get_height_of_tile_bl(int current_height, int x, int y) {
static int get_height_of_tile_tr(int current_height, int x, int y) {
int highest_point = current_height;
if (y > 0) {
- int tile_above = map[y-1][x];
+ int tile_above = map_to_load.heightmap[y-1][x];
if (tile_above > highest_point) {
highest_point = tile_above;
}
}
if (y > 0 && x < MAP_SIZE_X-1) {
- int tile_above_right = map[y-1][x+1];
+ int tile_above_right = map_to_load.heightmap[y-1][x+1];
if (tile_above_right > highest_point) {
highest_point = tile_above_right;
}
}
if (x < MAP_SIZE_X-1) {
- int tile_right = map[y][x+1];
+ int tile_right = map_to_load.heightmap[y][x+1];
if (tile_right > highest_point) {
highest_point = tile_right;
}
@@ -93,17 +93,7 @@ static int get_height_of_tile_tr(int current_height, int x, int y) {
return highest_point;
}
-// load hardcoded map.
-void load_map_from_data() {
-
- // load map from file..
- file_content content = platform_read_file_content("data/maps/map1.dat", "rb");
- memcpy(&map_to_load, content.content, content.content_length);
-
- //map_to_load.width = MAP_SIZE_X;
- //map_to_load.height = MAP_SIZE_Y;
- //memcpy(map_to_load.heightmap, map, sizeof(map));
-
+void export_map_from_map_data() {
for (int y = 0; y < MAP_SIZE_Y; y++) {
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
int h = map_to_load.heightmap[y][x];
@@ -111,13 +101,30 @@ void load_map_from_data() {
int highest_point_topright = get_height_of_tile_tr(h, x, y);
int highest_point_bottomright = get_height_of_tile_br(h, x, y);
int highest_point_bottomleft = get_height_of_tile_bl(h, x, y);
- map_loaded[y][x] = (tile){h, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
+ loaded_map.heightmap[y][x] = (tile){h, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
}
}
}
+
+void load_map_from_file() {
+
+ // load map from file..
+ file_content content = platform_read_file_content("data/maps/map1.dat", "rb");
+ memcpy(&map_to_load, content.content, content.content_length);
+
+ //map_to_load.width = MAP_SIZE_X;
+ //map_to_load.height = MAP_SIZE_Y;
+ //memcpy(map_to_load.heightmap, map, sizeof(map));
+
+ loaded_map.width = map_to_load.width;
+ loaded_map.height = map_to_load.height;
+
+ export_map_from_map_data();
+}
+
tile get_tile_under_coords(float x, float y) {
- return map_loaded[(int)(y)][(int)(x)];
+ return loaded_map.heightmap[(int)(y)][(int)(x)];
}
float get_height_of_tile_under_coords(float tocheckx, float tochecky) {
@@ -178,7 +185,7 @@ void draw_grid(platform_window* window) {
for (int y = 0; y < MAP_SIZE_Y; y++) {
MAP_RENDER_DEPTH;
for (int x = MAP_SIZE_X-1; x >= 0; x--) {
- tile tile = map_loaded[y][x];
+ tile tile = loaded_map.heightmap[y][x];
float xdiff_between_bottom_and_top = info.px_incline;
float render_x = (info.tile_width * x) + (xdiff_between_bottom_and_top * y);
@@ -241,10 +248,10 @@ void draw_grid(platform_window* window) {
renderer->render_line(topright.x, topright.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // right
renderer->render_line(bottomleft.x, bottomleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // bottom
*/
- map_loaded[y][x].tl = topleft;
- map_loaded[y][x].tr = topright;
- map_loaded[y][x].bl = bottomleft;
- map_loaded[y][x].br = bottomright;
+ loaded_map.heightmap[y][x].tl = topleft;
+ loaded_map.heightmap[y][x].tr = topright;
+ loaded_map.heightmap[y][x].bl = bottomleft;
+ loaded_map.heightmap[y][x].br = bottomright;
}
draw_objects_at_row(window, y);