added some graphics but only for debug

This commit is contained in:
peri4
2010-08-27 14:04:05 +04:00
parent b3854e867d
commit 95f3fb74fa
37 changed files with 876 additions and 707 deletions

106
ad_graphics.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include "ad_graphics.h"
AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent)
{
loadImages();
data = adcore->addata;
core = adcore;
//scale(cellSize, cellSize);
setAlignment(Qt::AlignLeft | Qt::AlignTop);
scene = new QGraphicsScene();
setScene(scene);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//gsw = new QGraphicsWidget();
//scene->addWidget(new QPushButton());
startTimer(25);
show();
}
AD_Graphics::~AD_Graphics()
{
//delete gsw;
delete scene;
}
void AD_Graphics::mouseDoubleClickEvent(QMouseEvent *)
{
core->nextWave();
}
void AD_Graphics::timerEvent(QTimerEvent * )
{
//qDebug() << data->curAliens.size();
draw();
}
void AD_Graphics::drawBackground(QPainter * p, const QRectF & )
{
for (int i=0; i<data->map->cells().size(); i++) {
for (int j=0; j<data->map->cells().at(i).size(); j++) {
QPen pen;
QBrush brush;
pen.setColor(Qt::white);
brush.setColor(Qt::white);
brush.setStyle(Qt::SolidPattern);
int cel = data->map->cells().at(i).at(j);
if (cel == Map::Wall) {
pen.setColor(Qt::black);
brush.setColor(Qt::black);
}
if (cel <= Map::PlayerTower && cel !=Map::Wall) {
pen.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255));
brush.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255));
}
// if (cel >= Map::PlayerAlien) {
// pen.setColor(Qt::yellow);
// brush.setColor(Qt::yellow);
// }
if (cel >= Map::Player) {
pen.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255,50));
brush.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255,50));
}
p->setPen(pen);
p->setBrush(brush);
p->drawRect(i*cellSize,j*cellSize,cellSize,cellSize);
}
}
for (QHash<int, AlienType>::iterator i = data->curAliens.begin(); i != data->curAliens.end(); ++i) {
//qDebug() << "draw alien";
//p->rotate(-90);
//p->scale(cellSize, cellSize);
//p->translate(rec.width()/2, rec.height()/2);
//p->rotate(-90);
//p->translate(-rec.height()/2, -rec.width()/2);
p->translate((*i).pos * cellSize+QPointF(10,10));
p->rotate((*i).angle);
p->drawImage(QRect(-20,-20,40,40), images[itAliens][0]->at(0));
p->resetTransform();
}
}
void AD_Graphics::draw()
{
scene->update();
//resetCachedContent();
//repaint();
}
void AD_Graphics::loadImages()
{
images.resize(3);
for (int i = 0; i < images.size(); i++) {
switch ((imagesType)i) {
case itAliens:
images[i].push_back(new Animation(":/images/images/Aliens/Al_00_"));
break;
default: break;
}
}
}