From 207ee62eaabac19e5a24e45adf773f81ca48f896 Mon Sep 17 00:00:00 2001 From: cflip Date: Tue, 25 Jan 2022 17:16:28 -0700 Subject: Implement simple train car For now, the car just exists at a certain tile and has a 'progress' timer until it moves to the next track tile. --- train.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 train.cpp (limited to 'train.cpp') diff --git a/train.cpp b/train.cpp new file mode 100644 index 0000000..e369887 --- /dev/null +++ b/train.cpp @@ -0,0 +1,52 @@ +#include "train.h" + +#include "level.h" +#include "bitmap.h" + +void TrainCar::update(Level& level) +{ + auto tile = level.get(x, y); + if (tile == 0) + return; + + if (m_progress < 12) { + m_progress++; + return; + } + else { + m_progress = 0; + } + + auto n = level.get(x, y - 1); + auto e = level.get(x + 1, y); + auto s = level.get(x, y + 1); + auto w = level.get(x - 1, y); + + if (m_dir == North) { + if (n == SouthEast) m_dir = East; + if (n == SouthWest) m_dir = West; + y--; + } + else if (m_dir == East) { + if (e == NorthWest) m_dir = North; + if (e == SouthWest) m_dir = South; + x++; + } + else if (m_dir == South) { + if (s == NorthEast) m_dir = East; + if (s == NorthWest) m_dir = West; + y++; + } + else if (m_dir == West) { + if (w == NorthEast) m_dir = North; + if (w == SouthEast) m_dir = South; + x--; + } +} + +void TrainCar::draw(Bitmap& bitmap, int xo, int yo) +{ + int xx = (x - y) * (24 / 2) - xo; + int yy = (x + y) * (24 / 4) - yo; + bitmap.blit(m_sprite, xx, yy, 0, 0, 24, 24); +} \ No newline at end of file -- cgit v1.2.3