the first source
This commit is contained in:
143
adpainter.cpp
Normal file
143
adpainter.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#include "adpainter.h"
|
||||
|
||||
|
||||
adpainter::adpainter(int width, int height, int adpcellsize)
|
||||
{
|
||||
QString str;
|
||||
QPixmap tmpAlPixmap;
|
||||
int i=1;
|
||||
cellsize = adpcellsize;
|
||||
buff = new QPixmap(width,height);
|
||||
background = new QPixmap(width,height);
|
||||
pen = new QPen();
|
||||
brush = new QBrush();
|
||||
str.setNum(i);
|
||||
while (i != 0) {
|
||||
str.setNum(i);
|
||||
tmpAlPixmap.load("./images/Aliens/Al_00_" + str + ".png");
|
||||
qDebug() << tmpAlPixmap.isNull();
|
||||
if (!tmpAlPixmap.isNull()) {
|
||||
AlienPix.push_back(tmpAlPixmap);
|
||||
tmpAlPixmap = 0;
|
||||
i++;
|
||||
}
|
||||
else i = 0;
|
||||
}
|
||||
qDebug() << "pictures:" << AlienPix.size();
|
||||
AnimAlien = 0;
|
||||
StepAlien = 0;
|
||||
}
|
||||
|
||||
|
||||
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(deque<QPointF> path, FPVector * position)
|
||||
{
|
||||
float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1;
|
||||
arctg = 0;
|
||||
QTransform rotated;
|
||||
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 (unsigned int i = 0; i < path.size(); i++){
|
||||
painter.drawEllipse(path[i].x() * cellsize +1, path[i].y() * cellsize +1, cellsize - 2, cellsize - 2);
|
||||
}
|
||||
tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize;
|
||||
tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize;
|
||||
tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize;
|
||||
tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize;
|
||||
/*if (qAbs(tmpdy1) > 0.01 && qAbs(tmpdx1) > 0.01)*/ arctg = atan(tmpdx1/tmpdy1);
|
||||
if (AlienPix.size() > 0) {
|
||||
//painter.rotate((arctg/3.1415)*180);
|
||||
rotated.rotateRadians(arctg/* + 3.1415/2*/);
|
||||
qDebug() << "angle:" << arctg;
|
||||
painter.save();
|
||||
painter.translate(position->pnt.x()+cellsize,position->pnt.y()+cellsize);
|
||||
//if (arctg == 0) painter.rotate(90);
|
||||
position->angle = 180*(-arctg)/3.1415;
|
||||
painter.rotate(position->angle);
|
||||
//position->pnt.setX(path.at(0).x());
|
||||
//position->pnt.setY(path.at(0).y());
|
||||
painter.drawPixmap(0, 0, cellsize*2, cellsize*2, AlienPix.at(AnimAlien));
|
||||
AnimAlien++;
|
||||
painter.restore();
|
||||
rotated.reset();
|
||||
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()--;
|
||||
}
|
||||
}
|
||||
if (AnimAlien >= AlienPix.size()) AnimAlien = 0;
|
||||
if (StepAlien >= path.size()) StepAlien = 0;
|
||||
//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;
|
||||
}
|
||||
Reference in New Issue
Block a user