diff options
Diffstat (limited to 'src/terrain')
| -rw-r--r-- | src/terrain/inc/terrain.h | 3 | ||||
| -rw-r--r-- | src/terrain/src/terrain.c | 23 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/terrain/inc/terrain.h b/src/terrain/inc/terrain.h index 9552555..d5f4e12 100644 --- a/src/terrain/inc/terrain.h +++ b/src/terrain/inc/terrain.h @@ -26,10 +26,11 @@ enum terrain_type struct terrain_map { enum terrain_type m[MAP_TILES][MAP_TILES]; - int nx, ny; + int nx, ny, last_w, last_h; }; void terrain_init(struct terrain_map *map); +void terrain_update(struct terrain_map *map); int terrain_render(const struct terrain_map *map, const struct camera *cam); extern struct sprite grass_sprite; diff --git a/src/terrain/src/terrain.c b/src/terrain/src/terrain.c index 04df6e6..a528c10 100644 --- a/src/terrain/src/terrain.c +++ b/src/terrain/src/terrain.c @@ -7,6 +7,25 @@ struct sprite grass_sprite; +void terrain_update(struct terrain_map *const map) +{ + if (map->last_w != screen_w) + { + const int extra = !!(screen_w % TERRAIN_SZ); + + map->nx = screen_w / TERRAIN_SZ + extra; + map->last_w = screen_w; + } + + if (map->last_h != screen_h) + { + const int extra = !!(screen_h % TERRAIN_SZ); + + map->ny = screen_h / TERRAIN_SZ + extra; + map->last_h = screen_h; + } +} + int terrain_render(const struct terrain_map *const map, const struct camera *const cam) { @@ -59,9 +78,5 @@ int terrain_render(const struct terrain_map *const map, void terrain_init(struct terrain_map *const map) { - const int extra = !!(screen_w % TERRAIN_SZ); - memset(map, 0, sizeof *map); - map->nx = screen_w / TERRAIN_SZ + extra; - map->ny = screen_h / TERRAIN_SZ + extra; } |
