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/train.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/train.cpp') diff --git a/src/train.cpp b/src/train.cpp index 2db57ef..7ce1c2d 100644 --- a/src/train.cpp +++ b/src/train.cpp @@ -10,7 +10,7 @@ void Train::update() m_progress = m_next->m_progress; } else { auto tile = m_level.get(x, y); - if (tile == 0) + if (TILE_TYPE(tile) != TileTrack) return; } @@ -66,24 +66,24 @@ void Train::addVehicle(Train* newTrain) void Train::findDirection() { - auto tile = m_level.get(x, y); + auto dir = TILE_DATA(m_level.get(x, y)); if (m_dir == North) { - if (tile == SouthEast) m_dir = East; - if (tile == SouthWest) m_dir = West; - if (tile == EastWest) m_dir = East; + if (dir == SouthEast) m_dir = East; + if (dir == SouthWest) m_dir = West; + if (dir == EastWest) m_dir = East; } else if (m_dir == East) { - if (tile == NorthWest) m_dir = North; - if (tile == SouthWest) m_dir = South; - if (tile == NorthSouth) m_dir = South; + if (dir == NorthWest) m_dir = North; + if (dir == SouthWest) m_dir = South; + if (dir == NorthSouth) m_dir = South; } else if (m_dir == South) { - if (tile == NorthEast) m_dir = East; - if (tile == NorthWest) m_dir = West; - if (tile == EastWest) m_dir = West; + if (dir == NorthEast) m_dir = East; + if (dir == NorthWest) m_dir = West; + if (dir == EastWest) m_dir = West; } else if (m_dir == West) { - if (tile == NorthEast) m_dir = North; - if (tile == SouthEast) m_dir = South; - if (tile == NorthSouth) m_dir = North; + if (dir == NorthEast) m_dir = North; + if (dir == SouthEast) m_dir = South; + if (dir == NorthSouth) m_dir = North; } } -- cgit v1.2.3