From c48dbb7a7cbff7dc6d413edc42a011c261047297 Mon Sep 17 00:00:00 2001 From: cflip Date: Sun, 6 Mar 2022 10:59:56 -0700 Subject: Create new tile byte format Track tiles now have their direction information stored in the high 4 bits of the tile byte, creating a clearer separation between the type of tile and other persistent data. This will make the code more managable for adding new tile types and with the new macros and enums the code is much easier to read and understand. --- src/level.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/level.h') diff --git a/src/level.h b/src/level.h index e915da3..d24ccb4 100644 --- a/src/level.h +++ b/src/level.h @@ -5,8 +5,26 @@ #include #include +#define TILE_TYPE(x) ((x)&0xf) +#define TILE_DATA(x) (x >> 4 & 0xf) +#define MAKE_TILE(t, d) ((((d) & 0xf) << 4) + ((t)&0xf)) + class Train; +enum TileType : uint8_t { + TileGround, + TileTrack +}; + +enum TrackDirection : uint8_t { + NorthSouth, + EastWest, + SouthEast, + SouthWest, + NorthWest, + NorthEast, +}; + class Level { public: Level(int width, int height, Bitmap& tileSprites); @@ -30,13 +48,4 @@ private: std::vector m_vehicles; }; -enum RailDirection { - NorthSouth = 1, - EastWest, - SouthEast, - SouthWest, - NorthWest, - NorthEast, -}; - -RailDirection ChooseDirection(Level& level, int x, int y); \ No newline at end of file +TrackDirection ChooseDirection(Level& level, int x, int y); \ No newline at end of file -- cgit v1.2.3