diff options
author | cflip <cflip@cflip.net> | 2022-03-21 20:59:13 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-03-21 22:13:14 -0600 |
commit | e13dd6b4625f4b56941ae38f9278b175b4c15c05 (patch) | |
tree | ae8c9418e5fc3668750d15d7c617582250416a02 | |
parent | c48dbb7a7cbff7dc6d413edc42a011c261047297 (diff) |
Add a basic wall tile
-rw-r--r-- | src/level.cpp | 25 | ||||
-rw-r--r-- | src/level.h | 3 |
2 files changed, 21 insertions, 7 deletions
diff --git a/src/level.cpp b/src/level.cpp index bdff5fb..e197d8e 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -7,6 +7,9 @@ Level::Level(int width, int height, Bitmap& tileSprites) { m_tiles = new uint8_t[width * height]; memset(m_tiles, TileGround, width * height); + + for (int i = 4; i < 14; i++) + m_tiles[i + 6 * m_width] = TileWall; } uint8_t Level::get(int x, int y) @@ -32,17 +35,26 @@ void Level::update() void Level::draw(Bitmap& bitmap, int xo, int yo) { - for (int y = 0; y < 32; ++y) { - for (int x = 0; x < 32; ++x) { + for (int y = 0; y < m_height; ++y) { + for (int x = 0; x < m_width; ++x) { auto tile = get(x, y); int xx = (x - y) * (TileSize / 2) - xo; int yy = (x + y) * (TileSize / 4) - yo; - int tx = (x + y) % 2; - int ty = 0; - - if (TILE_TYPE(tile) == TileTrack) { + int tx = 0; + int ty = 1; + + switch (TILE_TYPE(tile)) { + case TileGround: + tx = (x + y) % 2; + ty = 0; + break; + case TileWall: + tx = 2; + ty = 0; + break; + case TileTrack: { uint8_t dir = TILE_DATA(tile); if (dir == NorthSouth) { tx = 0; @@ -63,6 +75,7 @@ void Level::draw(Bitmap& bitmap, int xo, int yo) tx = 2; ty = 3; } + } break; } bitmap.blit(m_tileSprites, xx, yy, tx * TileSize, ty * TileSize, TileSize, TileSize); diff --git a/src/level.h b/src/level.h index d24ccb4..8c95f2f 100644 --- a/src/level.h +++ b/src/level.h @@ -7,12 +7,13 @@ #define TILE_TYPE(x) ((x)&0xf) #define TILE_DATA(x) (x >> 4 & 0xf) -#define MAKE_TILE(t, d) ((((d) & 0xf) << 4) + ((t)&0xf)) +#define MAKE_TILE(t, d) ((((d)&0xf) << 4) + ((t)&0xf)) class Train; enum TileType : uint8_t { TileGround, + TileWall, TileTrack }; |