Doc: Add FOV to rogue example.

Change-Id: Ib0f4caad9bc828a94616466f303d879fc967970d
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
bb10
Geir Vattekar 2012-08-15 15:33:13 +02:00 committed by Qt by Nokia
parent 6f09e100c9
commit a69425ff3f
1 changed files with 49 additions and 0 deletions

View File

@ -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('@'));
}