diff options
author | cflip <cflip@cflip.net> | 2022-01-25 17:16:28 -0700 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-01-25 17:16:28 -0700 |
commit | 207ee62eaabac19e5a24e45adf773f81ca48f896 (patch) | |
tree | 90e71eacecd9a1294da21082a304483f27d35a18 /main.cpp | |
parent | e0f29aa0b03807ef3968edd5673d9dc5637f32af (diff) |
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.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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); } |