From a69425ff3fc03e3baced93d3c5985abcc6fabbb4 Mon Sep 17 00:00:00 2001 From: Geir Vattekar Date: Wed, 15 Aug 2012 15:33:13 +0200 Subject: Doc: Add FOV to rogue example. Change-Id: Ib0f4caad9bc828a94616466f303d879fc967970d Reviewed-by: Casper van Donderen --- examples/statemachine/rogue/window.cpp | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'examples') 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(pX); + double y1 = static_cast(pY); + double x2 = static_cast(x); + double y2 = static_cast(y); + + if (x2x1) { + x2-=0.5; + } + + if (y2y1) { + 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(xi+0.5); + int cy = static_cast(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('@')); } -- cgit v1.2.3