summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/rogue/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/statemachine/rogue/window.cpp')
-rw-r--r--examples/statemachine/rogue/window.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/statemachine/rogue/window.cpp b/examples/statemachine/rogue/window.cpp
index 5fcd259c91..0c57b2c2d7 100644
--- a/examples/statemachine/rogue/window.cpp
+++ b/examples/statemachine/rogue/window.cpp
@@ -107,10 +107,59 @@ void Window::paintEvent(QPaintEvent * /* event */)
continue;
}
+ painter.setPen(Qt::white);
+
+ double x1 = static_cast<double>(pX);
+ double y1 = static_cast<double>(pY);
+ double x2 = static_cast<double>(x);
+ double y2 = static_cast<double>(y);
+
+ if (x2<x1) {
+ x2+=0.5;
+ } else if (x2>x1) {
+ x2-=0.5;
+ }
+
+ if (y2<y1) {
+ y2+=0.5;
+ } else if (y2>y1) {
+ y2-=0.5;
+ }
+
+ double dx = x2 - x1;
+ double dy = y2 - y1;
+
+ double length = qSqrt(dx*dx+dy*dy);
+
+ dx /= length;
+ dy /= length;
+
+ double xi = x1;
+ double yi = y1;
+
+ while (length > 0) {
+ int cx = static_cast<int>(xi+0.5);
+ int cy = static_cast<int>(yi+0.5);
+
+ if (x2 == cx && y2 == cy)
+ break;
+
+ if (!(x1==cx && y1==cy)
+ && (map[cx][cy] == '#' || (length-10) > 0)) {
+ painter.setPen(QColor(60,60,60));
+ break;
+ }
+
+ xi += dx;
+ yi += dy;
+ --length;
+ }
+
painter.drawText(QPoint(xPos, yPos), map[x][y]);
xPos += fontWidth;
}
}
+ painter.setPen(Qt::white);
painter.drawText(QPoint(pX * fontWidth, (pY + 2) * fontHeight), QChar('@'));
}