diff options
author | cflip <cflip@cflip.net> | 2022-03-06 10:59:56 -0700 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-03-06 11:05:05 -0700 |
commit | c48dbb7a7cbff7dc6d413edc42a011c261047297 (patch) | |
tree | 55d69061e55aabe73698539cb2f5602e465ae8c9 /src/train.cpp | |
parent | d198dd25af201aaacc7782f4bd36d2cfa5f0c05b (diff) |
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.
Diffstat (limited to 'src/train.cpp')
-rw-r--r-- | src/train.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
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; } } |