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. --- main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 9e3b621..610dbb1 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include "window.h" #include "bitmap.h" #include "level.h" +#include "train.h" struct Point2D { float x, y; @@ -89,6 +90,8 @@ int main(int argc, char **argv) int xDrag, yDrag; bool isDragging = false; + TrainCar car(0, 0); + window.onMouseDown([&](int button, int x, int y) { if (button == 1) { static const auto update_direction = [&](int xt, int yt) { @@ -117,6 +120,12 @@ int main(int argc, char **argv) xDrag = x; yDrag = y; isDragging = true; + } else { + float mx = x / Scale + xOffs; + float my = y / Scale + yOffs; + auto pos = screenToTile({ mx, my }); + car.x = pos.x; + car.y = pos.y; } }); @@ -137,6 +146,8 @@ int main(int argc, char **argv) while (!window.shouldClose()) { window.update(); DrawLevel(bitmap, tiles, level, xOffs, yOffs); + car.update(level); + car.draw(bitmap, xOffs, yOffs); window.draw(bitmap); } -- cgit v1.2.3