diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-28 03:01:13 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-28 15:17:49 +0100 |
| commit | fd53c7da8c5f2b79b87f624e313ff508072361ad (patch) | |
| tree | db569413cd3d42034a22368a7980aa99d7d55235 /src/terrain | |
| parent | e49e3073c67af785447ddb0ecbdc521b68cf3ea9 (diff) | |
| download | jancity-fd53c7da8c5f2b79b87f624e313ff508072361ad.tar.gz | |
Big rushed update
Diffstat (limited to 'src/terrain')
| -rw-r--r-- | src/terrain/inc/terrain.h | 4 | ||||
| -rw-r--r-- | src/terrain/privinc/terrain_tiles.h | 114 | ||||
| -rw-r--r-- | src/terrain/src/init.c | 2 | ||||
| -rw-r--r-- | src/terrain/src/render.c | 10 |
4 files changed, 117 insertions, 13 deletions
diff --git a/src/terrain/inc/terrain.h b/src/terrain/inc/terrain.h index 7997025..dc29883 100644 --- a/src/terrain/inc/terrain.h +++ b/src/terrain/inc/terrain.h @@ -13,7 +13,7 @@ extern "C" enum { - MAP_TILES = 120, + MAP_TILES = 24, TERRAIN_SZ = 16, MAP_W = MAP_TILES * TERRAIN_SZ, MAP_H = MAP_TILES * TERRAIN_SZ @@ -39,7 +39,9 @@ enum GRASS, ROOF1, ROOF2, + PAVEMENT, BUILDING1, + BUILDING2, MAX_TERRAIN_SPRITES }; diff --git a/src/terrain/privinc/terrain_tiles.h b/src/terrain/privinc/terrain_tiles.h index 962bafe..89b8457 100644 --- a/src/terrain/privinc/terrain_tiles.h +++ b/src/terrain/privinc/terrain_tiles.h @@ -15,7 +15,6 @@ enum SIDEWALK_2_NW, SIDEWALK_2_NE, SIDEWALK_3_NW, - SIDEWALK_3_N, SIDEWALK_3_NE, SIDEWALK_4_N, @@ -25,7 +24,6 @@ enum SIDEWALK_2_SW, SIDEWALK_2_SE, SIDEWALK_3_SW, - SIDEWALK_3_S, SIDEWALK_3_SE, SIDEWALK_4_C, @@ -49,7 +47,6 @@ enum ROOF1_2_NE, ROOF1_3_NW, ROOF1_3_N, - ROOF1_3_NE, ROOF1_4_N, ROOF1_1_W, @@ -58,7 +55,6 @@ enum ROOF1_2_SW, ROOF1_2_SE, ROOF1_3_SW, - ROOF1_3_S, ROOF1_3_SE, ROOF1_4_C, @@ -82,7 +78,6 @@ enum ROOF2_2_NE, ROOF2_3_NW, ROOF2_3_N, - ROOF2_3_NE, ROOF2_4_N, ROOF2_1_W, @@ -91,7 +86,6 @@ enum ROOF2_2_SW, ROOF2_2_SE, ROOF2_3_SW, - ROOF2_3_S, ROOF2_3_SE, ROOF2_4_C, @@ -105,7 +99,111 @@ enum ROOF2_4_S, ROOF2_START = ROOF2_1_NW, - ROOF2_END = ROOF2_4_S + ROOF2_END = ROOF2_4_S, + + /* PAVEMENT */ + PAVEMENT_CW_H_MID, + PAVEMENT_STR_MID_H_1, + PAVEMENT_CW_V_LEFT, + PAVEMENT_CW_V_MID, + PAVEMENT_CW_V_RIGHT, + PAVEMENT_RND_NW, + PAVEMENT_RND_NE, + PAVEMENT_SP_NW, + PAVEMENT_SP_NE, + PAVEMENT_1, + PAVEMENT_P, + PAVEMENT_CW_H_TOP, + PAVEMENT_STR_H_TOP, + + PAVEMENT_CW_H_DOWN, + PAVEMENT_STR_H_DOWN, + PAVEMENT_STR_V_LEFT, + PAVEMENT_STR_V_MID, + PAVEMENT_STR_V_RIGHT, + PAVEMENT_RND_SW, + PAVEMENT_RND_SE, + PAVEMENT_SP_SW, + PAVEMENT_SP_SE, + PAVEMENT_2, + PAVEMENT_BIKE, + PAVEMENT_PLUS, + PAVEMENT_EMPTY, + + PAVEMENT_START = PAVEMENT_CW_H_MID, + PAVEMENT_END = PAVEMENT_EMPTY, + + /* BUILDING1 */ + BUILDING1_1_N, + BUILDING1_2_NW, + BUILDING1_2_N, + BUILDING1_2_NE, + BUILDING1_3_NW, + BUILDING1_3_N, + BUILDING1_3_NE, + + BUILDING1_1_C_1, + BUILDING1_2_W_1, + BUILDING1_2_C_1, + BUILDING1_2_E_1, + BUILDING1_3_W_1, + BUILDING1_3_C_1, + BUILDING1_3_E_1, + + BUILDING1_1_C_2, + BUILDING1_2_W_2, + BUILDING1_2_C_2, + BUILDING1_2_E_2, + BUILDING1_3_W_2, + BUILDING1_3_C_2, + BUILDING1_3_E_2, + + BUILDING1_1_S, + BUILDING1_2_SW, + BUILDING1_2_S, + BUILDING1_2_SE, + BUILDING1_3_SW, + BUILDING1_3_S, + BUILDING1_3_SE, + + BUILDING1_START = BUILDING1_1_N, + BUILDING1_END = BUILDING1_2_SE, + + /* BUILDING2 */ + BUILDING2_1_N, + BUILDING2_2_NW, + BUILDING2_2_N, + BUILDING2_2_NE, + BUILDING2_3_NW, + BUILDING2_3_N, + BUILDING2_3_NE, + + BUILDING2_1_C_1, + BUILDING2_2_W_1, + BUILDING2_2_C_1, + BUILDING2_2_E_1, + BUILDING2_3_W_1, + BUILDING2_3_C_1, + BUILDING2_3_E_1, + + BUILDING2_1_C_2, + BUILDING2_2_W_2, + BUILDING2_2_C_2, + BUILDING2_2_E_2, + BUILDING2_3_W_2, + BUILDING2_3_C_2, + BUILDING2_3_E_2, + + BUILDING2_1_S, + BUILDING2_2_SW, + BUILDING2_2_S, + BUILDING2_2_SE, + BUILDING2_3_SW, + BUILDING2_3_S, + BUILDING2_3_SE, + + BUILDING2_START = BUILDING2_1_N, + BUILDING2_END = BUILDING2_3_SE }; enum @@ -119,7 +217,6 @@ enum GRASS_2_NW, GRASS_2_NE, GRASS_3_NW, - GRASS_3_N, GRASS_3_NE, GRASS_4_N, @@ -129,7 +226,6 @@ enum GRASS_2_SW, GRASS_2_SE, GRASS_3_SW, - GRASS_3_S, GRASS_3_SE, GRASS_4_C, diff --git a/src/terrain/src/init.c b/src/terrain/src/init.c index 88140d8..c16859c 100644 --- a/src/terrain/src/init.c +++ b/src/terrain/src/init.c @@ -133,6 +133,8 @@ int terrain_init(const char *const path, struct terrain_map *const map) FILE *const f = fopen(path, "rb"); unsigned w, h; + *map = (const struct terrain_map){0}; + if (!f) { fprintf(stderr, "%s: fopen(3): %s\n", __func__, strerror(errno)); diff --git a/src/terrain/src/render.c b/src/terrain/src/render.c index 8b35d95..bfa1e74 100644 --- a/src/terrain/src/render.c +++ b/src/terrain/src/render.c @@ -22,7 +22,7 @@ struct tile static int render_tile(const unsigned char id, const short x, const short y, const struct tile *const tiles, const size_t n) { - for (size_t i = 0; i < n / n; i++) + for (size_t i = 0; i < n; i++) { const struct tile *const rt = &tiles[i]; @@ -37,7 +37,8 @@ static int render_tile(const unsigned char id, const short x, } const unsigned char pos = id - rt->start; - const short tx = pos % TERRAIN_SZ, ty = pos / TERRAIN_SZ; + const short tx = pos % (s->w / TERRAIN_SZ), + ty = (pos * TERRAIN_SZ) / s->w; s->x = x; s->y = y; @@ -67,7 +68,10 @@ static int render_ground(const struct terrain_tile *const t, const short x, #define TILE(t) {.s = &terrain_sprites[t], .start = t##_START, .end = t##_END} TILE(SIDEWALK), TILE(ROOF1), - TILE(ROOF2) + TILE(ROOF2), + TILE(PAVEMENT), + TILE(BUILDING1), + TILE(BUILDING2) #undef TILE }; |
