126 lines
3.8 KiB
C++
126 lines
3.8 KiB
C++
#include "adpainter.h"
|
|
|
|
|
|
adpainter::adpainter(int width, int height, int adpcellsize)
|
|
{
|
|
cellsize = adpcellsize;
|
|
buff = new QPixmap(width,height);
|
|
background = new QPixmap(width,height);
|
|
pen = new QPen();
|
|
brush = new QBrush();
|
|
}
|
|
|
|
|
|
void adpainter::clear()
|
|
{
|
|
painter.begin(background);
|
|
pen->setColor(QColor::fromRgb(qRgb(150,150,150)));
|
|
painter.setPen(*pen);
|
|
painter.fillRect(buff->rect(),QColor::fromRgb(qRgb(150,150,150)));
|
|
painter.end();
|
|
}
|
|
|
|
|
|
void adpainter::drawgrid()
|
|
{
|
|
int i;
|
|
painter.begin(background);
|
|
pen->setColor(QColor::fromRgb(qRgb(100,100,100)));
|
|
painter.setPen(*pen);
|
|
for (i = 0;i<buff->width()/cellsize;i++)
|
|
{
|
|
painter.drawLine(i*cellsize,0,i*cellsize,background->height());
|
|
}
|
|
for (i = 0;i<buff->height()/cellsize;i++)
|
|
{
|
|
painter.drawLine(0,i*cellsize,background->width(),i*cellsize);
|
|
}
|
|
painter.end();
|
|
}
|
|
|
|
|
|
void adpainter::drawAliens(Alien * al,QVector<QPixmap> * pixmaps)
|
|
{
|
|
//float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1;
|
|
//arctg = 0;
|
|
QRectF rect;
|
|
painter.begin(buff);
|
|
pen->setColor(QColor::fromRgb(qRgb(80,200,100)));
|
|
brush->setColor(QColor::fromRgb(qRgb(230,10,10)));
|
|
brush->setStyle(Qt::SolidPattern);
|
|
painter.setPen(*pen);
|
|
painter.setBrush(*brush);
|
|
painter.drawPixmap(0,0,*background);
|
|
for (int i = 0; i < al->path.size(); i++){
|
|
rect.setRect(al->path[i].x() * cellsize +1, al->path[i].y() * cellsize +1, cellsize - 2, cellsize - 2);
|
|
painter.drawEllipse(rect);
|
|
}
|
|
//tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize;
|
|
//tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize;
|
|
//if (StepAlien + 1 < path.size()) {
|
|
// tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize;
|
|
// tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize;
|
|
//}
|
|
//arctg = atanf(tmpdx1/tmpdy1);
|
|
//position->angle = 180*(-arctg)/3.1415;
|
|
//if (tmpdy1 < 0) position->angle = 180 + position->angle;
|
|
//if (AlienPix.size() > 0) {
|
|
//qDebug() << "angle:" << position->angle;
|
|
/* if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++;
|
|
else {
|
|
if (qAbs(tmpdx) <= qAbs(tmpdy)) {
|
|
if (tmpdy < 0) position->pnt.ry()++;
|
|
else position->pnt.ry()--;
|
|
}
|
|
if (qAbs(tmpdx) >= qAbs(tmpdy)) {
|
|
if (tmpdx < 0) position->pnt.rx()++;
|
|
else position->pnt.rx()--;
|
|
}
|
|
}*/
|
|
painter.translate(al->Position.pnt.x()+cellsize/2, al->Position.pnt.y()+cellsize/2);
|
|
painter.rotate(al->Position.angle);
|
|
painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, pixmaps->at(al->PicIndex));
|
|
//AnimAlien++;
|
|
//if (AnimAlien >= AlienPix.size()) AnimAlien = 0;
|
|
/*if (StepAlien >= path.size()) {
|
|
StepAlien = 0;
|
|
position->pnt.setX(path.at(0).x()*cellsize);
|
|
position->pnt.setY(path.at(0).y()*cellsize);
|
|
}*/
|
|
//qDebug() << StepAlien;
|
|
//}
|
|
painter.end();
|
|
}
|
|
|
|
|
|
void adpainter::drawcell(QPoint pnt)
|
|
{
|
|
painter.begin(background);
|
|
pen->setColor(QColor::fromRgb(qRgb(0,0,0)));
|
|
brush->setColor(QColor::fromRgb(qRgb(0,0,0)));
|
|
brush->setStyle(Qt::SolidPattern);
|
|
painter.setPen(*pen);
|
|
painter.setBrush(*brush);
|
|
painter.drawRect(pnt.x()*cellsize+1,pnt.y()*cellsize+1,cellsize - 2, cellsize - 2);
|
|
painter.end();
|
|
}
|
|
|
|
|
|
void adpainter::clearcell(QPoint pnt)
|
|
{
|
|
painter.begin(background);
|
|
pen->setColor(QColor::fromRgb(qRgb(150,150,150)));
|
|
brush->setColor(QColor::fromRgb(qRgb(150,150,150)));
|
|
brush->setStyle(Qt::SolidPattern);
|
|
painter.setPen(*pen);
|
|
painter.setBrush(*brush);
|
|
painter.drawRect(pnt.x()*cellsize+1,pnt.y()*cellsize+1,cellsize - 2, cellsize - 2);
|
|
painter.end();
|
|
}
|
|
|
|
|
|
QPixmap * adpainter::getPixmap()
|
|
{
|
|
return buff;
|
|
}
|