diff options
author | Jun Zhang <jun@junz.org> | 2022-01-30 12:30:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-29 21:30:02 -0700 |
commit | cb7af3f4cac90f95926477b4001f9f80037568d5 (patch) | |
tree | 022f4700c796a9935acd3ee0d0fd80a812a78464 /src/train.cpp | |
parent | 99b4763f1028e72bb06d8db6c7e8ace469f8989c (diff) |
refactor: adjust the project infra. (#1)
* refactor: adjust the project infra.
This patch adds cmake build system to the project, and adjust infrastructure
stuff.
Signed-off-by: Jun Zhang <jun@junz.org>
* fix: remove compiler flags that only exist in GCC.
Signed-off-by: Jun Zhang <jun@junz.org>
Diffstat (limited to 'src/train.cpp')
-rw-r--r-- | src/train.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/train.cpp b/src/train.cpp new file mode 100644 index 0000000..e369887 --- /dev/null +++ b/src/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 |