From d82cd8b91a8d155b2d0ed4328f12dc88667cc51c Mon Sep 17 00:00:00 2001 From: cflip Date: Mon, 24 Jan 2022 17:45:49 -0700 Subject: Automatically align adjacent tracks --- main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.cpp b/main.cpp index 8af8922..9e3b621 100644 --- a/main.cpp +++ b/main.cpp @@ -91,6 +91,11 @@ int main(int argc, char **argv) window.onMouseDown([&](int button, int x, int y) { if (button == 1) { + static const auto update_direction = [&](int xt, int yt) { + if (level.get(xt, yt) > 0) + level.set(xt, yt, ChooseDirection(level, xt, yt)); + }; + float mx = x / Scale + xOffs; float my = y / Scale + yOffs; Point2D tilePos = screenToTile({ mx, my }); @@ -102,6 +107,11 @@ int main(int argc, char **argv) else tile = ChooseDirection(level, tilePos.x, tilePos.y); level.set(tilePos.x, tilePos.y, tile); + + update_direction(tilePos.x - 1, tilePos.y); + update_direction(tilePos.x + 1, tilePos.y); + update_direction(tilePos.x, tilePos.y - 1); + update_direction(tilePos.x, tilePos.y + 1); } } else if (button == 2 && !isDragging) { xDrag = x; -- cgit v1.2.3