diff options
author | Geir Vattekar <geir.vattekar@nokia.com> | 2012-08-15 15:33:13 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-18 21:08:33 +0200 |
commit | a69425ff3fc03e3baced93d3c5985abcc6fabbb4 (patch) | |
tree | 718bd02fdb2c2b4e46fc9636513307ba94d89ba2 | |
parent | 6f09e100c98e5636eff14c99a973817b5b17f492 (diff) |
Doc: Add FOV to rogue example.
Change-Id: Ib0f4caad9bc828a94616466f303d879fc967970d
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
-rw-r--r-- | examples/statemachine/rogue/window.cpp | 49 |
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('@')); } |