now this work stable
global restruct fuinish part 1 of 3
This commit is contained in:
@@ -80,7 +80,7 @@ void adpainter::drawAlien(Alien * al)
|
|||||||
painter.setBrush(*brush);
|
painter.setBrush(*brush);
|
||||||
painter.drawPixmap(0,0,*background);
|
painter.drawPixmap(0,0,*background);
|
||||||
for (int i = 0; i < al->path.size(); i++){
|
for (int i = 0; i < al->path.size(); i++){
|
||||||
painter.drawEllipse(al->path[i].x() * cellsize +4, al->path[i].y() * cellsize +4, cellsize - 8, cellsize - 8);
|
painter.drawEllipse(al->path.at(i).x() * cellsize +4, al->path.at(i).y() * cellsize +4, cellsize - 8, cellsize - 8);
|
||||||
}
|
}
|
||||||
/*tmpdx = position->pnt.x() - path[StepAlien].x()*cellsize;
|
/*tmpdx = position->pnt.x() - path[StepAlien].x()*cellsize;
|
||||||
tmpdy = position->pnt.y() - path[StepAlien].y()*cellsize;
|
tmpdy = position->pnt.y() - path[StepAlien].y()*cellsize;
|
||||||
@@ -117,13 +117,13 @@ void adpainter::drawAlien(Alien * al)
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
//painter.save();
|
//painter.save();
|
||||||
painter.translate(al->pos().pnt.x()+cellsize/2, al->pos().pnt.y()+cellsize/2);
|
painter.translate(al->Pos().x()+cellsize/2, al->Pos().y()+cellsize/2);
|
||||||
//if (arctg == 0) painter.rotate(90);
|
//if (arctg == 0) painter.rotate(90);
|
||||||
//memcpy(dd,&gg,4);
|
//memcpy(dd,&gg,4);
|
||||||
//dd[0]=0xFF;
|
//dd[0]=0xFF;
|
||||||
//qDebug() << "angle:" << position->angle;
|
//qDebug() << "angle:" << position->angle;
|
||||||
//qDebug() << dd[0] << dd[1] << dd[2] << dd[3];
|
//qDebug() << dd[0] << dd[1] << dd[2] << dd[3];
|
||||||
painter.rotate(al->pos().angle);
|
painter.rotate(al->Angl());
|
||||||
//position->pnt.setX(path.at(0).x());
|
//position->pnt.setX(path.at(0).x());
|
||||||
//position->pnt.setY(path.at(0).y());
|
//position->pnt.setY(path.at(0).y());
|
||||||
painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix[al->indexPix()]);
|
painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix[al->indexPix()]);
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
#ifndef ADPAINTER_H
|
#ifndef ADPAINTER_H
|
||||||
#define ADPAINTER_H
|
#define ADPAINTER_H
|
||||||
|
|
||||||
#include "basestruct.h"
|
|
||||||
#include "alien.h"
|
#include "alien.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPaintEvent>
|
|
||||||
#include <QPaintDevice>
|
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QPixmap>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
using std::atan;
|
using std::atan;
|
||||||
|
|
||||||
@@ -28,7 +23,7 @@ public:
|
|||||||
void drawAlien(Alien * al);
|
void drawAlien(Alien * al);
|
||||||
int AnimAlien, StepAlien;
|
int AnimAlien, StepAlien;
|
||||||
private:
|
private:
|
||||||
GameData * data;
|
//GameData * data;
|
||||||
QPixmap * buff;
|
QPixmap * buff;
|
||||||
QPixmap * background;
|
QPixmap * background;
|
||||||
QPen * pen;
|
QPen * pen;
|
||||||
|
|||||||
97
alien.cpp
97
alien.cpp
@@ -2,25 +2,27 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
Alien::Alien(GameData * AlienData, float alienspeed)
|
Alien::Alien(games *parent, float alienspeed)
|
||||||
{
|
{
|
||||||
data = AlienData;
|
game = parent;
|
||||||
Speed = alienspeed;
|
Speed = alienspeed;
|
||||||
TmpCells = new int*[data->size.width()];
|
TmpCells = new int*[game->size.width()];
|
||||||
for (int i = 0; i < data->size.width(); i++)
|
for (int i = 0; i < game->size.width(); i++)
|
||||||
TmpCells[i] = new int[data->size.height()];
|
TmpCells[i] = new int[game->size.height()];
|
||||||
Position.pnt = data->start*data->cellsize;
|
position = game->start*game->cellsize;
|
||||||
|
path.clear();
|
||||||
|
PicIndex = 0;
|
||||||
RecreatePath();
|
RecreatePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Alien::RecreatePath()
|
bool Alien::RecreatePath()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < data->size.width(); i++)
|
for (int i = 0; i < game->size.width(); i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < data->size.height(); j++)
|
for (int j = 0; j < game->size.height(); j++)
|
||||||
{
|
{
|
||||||
if (data->Cells[i][j] < 0 ) TmpCells[i][j] = -1;
|
if (game->Cells[i][j] < 0 ) TmpCells[i][j] = -1;
|
||||||
else TmpCells[i][j] = 0;
|
else TmpCells[i][j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,13 +31,13 @@ bool Alien::RecreatePath()
|
|||||||
QVector<QPoint> srcPath;
|
QVector<QPoint> srcPath;
|
||||||
QVector<QPointF> tmpPath;
|
QVector<QPointF> tmpPath;
|
||||||
PathIndex = 1;
|
PathIndex = 1;
|
||||||
start.setX(qRound(Position.pnt.x()/(float)data->cellsize));
|
start.setX(qRound(position.x()/(float)game->cellsize));
|
||||||
start.setY(qRound(Position.pnt.y()/(float)data->cellsize));
|
start.setY(qRound(position.y()/(float)game->cellsize));
|
||||||
srcPath = InvWaveTrace(data->finish,WaveTrace(start,data->finish));
|
srcPath = InvWaveTrace(game->finish,WaveTrace(start,game->finish));
|
||||||
for (int i=0; i<srcPath.size();i++)
|
for (int i=0; i<srcPath.size();i++)
|
||||||
{
|
{
|
||||||
data->Cells[srcPath[i].x()][srcPath[i].y()] = 1;
|
game->Cells[srcPath.at(i).x()][srcPath.at(i).y()] = 1;
|
||||||
tmpPath.push_back(QPointF(srcPath[i]));
|
tmpPath.push_back(QPointF(srcPath.at(i)));
|
||||||
}
|
}
|
||||||
srcPath.clear();
|
srcPath.clear();
|
||||||
//qDebug() << tmpPath.size();
|
//qDebug() << tmpPath.size();
|
||||||
@@ -44,15 +46,16 @@ bool Alien::RecreatePath()
|
|||||||
for (int j=0; j<4; j++)
|
for (int j=0; j<4; j++)
|
||||||
{
|
{
|
||||||
path.clear();
|
path.clear();
|
||||||
tp = tmpPath[0];
|
tp = tmpPath.at(0);
|
||||||
path.push_back(tp);
|
path.push_back(tp);
|
||||||
for (int i = 0; i < tmpPath.size() - 1; i++)
|
for (int i = 0; i < tmpPath.size() - 1; i++)
|
||||||
{
|
{
|
||||||
tp.setX((tmpPath[i].x() + tmpPath[i + 1].x()) / 2.0);
|
//if (j > 1) path.push_back(tmpPath[i]);
|
||||||
tp.setY((tmpPath[i].y() + tmpPath[i + 1].y()) / 2.0);
|
tp.setX((tmpPath.at(i).x() + tmpPath.at(i + 1).x()) / 2.0);
|
||||||
|
tp.setY((tmpPath.at(i).y() + tmpPath.at(i + 1).y()) / 2.0);
|
||||||
path.push_back(tp);
|
path.push_back(tp);
|
||||||
}
|
}
|
||||||
tp = tmpPath[tmpPath.size() - 1];
|
tp = tmpPath.at(tmpPath.size() - 1);
|
||||||
path.push_back(tp);
|
path.push_back(tp);
|
||||||
tmpPath = path;
|
tmpPath = path;
|
||||||
}
|
}
|
||||||
@@ -73,48 +76,48 @@ bool Alien::RecreatePath()
|
|||||||
void Alien::update()
|
void Alien::update()
|
||||||
{
|
{
|
||||||
float tmpdx,tmpdy,angl,arctg = 0;
|
float tmpdx,tmpdy,angl,arctg = 0;
|
||||||
tmpdx = Position.pnt.x() - path[PathIndex].x()*data->cellsize;
|
tmpdx = position.x() - path.at(PathIndex).x()*game->cellsize;
|
||||||
tmpdy = Position.pnt.y() - path[PathIndex].y()*data->cellsize;
|
tmpdy = position.y() - path.at(PathIndex).y()*game->cellsize;
|
||||||
while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*Speed*data->cellsize)
|
while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*Speed*game->cellsize)
|
||||||
{
|
{
|
||||||
PathIndex++;
|
PathIndex++;
|
||||||
if (PathIndex >= path.size()) PathIndex = 0;
|
if (PathIndex >= path.size())
|
||||||
tmpdx = Position.pnt.x() - path[PathIndex].x()*data->cellsize;
|
{
|
||||||
tmpdy = Position.pnt.y() - path[PathIndex].y()*data->cellsize;
|
PathIndex = 0;
|
||||||
|
position = game->start*game->cellsize;
|
||||||
|
}
|
||||||
|
tmpdx = position.x() - path.at(PathIndex).x()*game->cellsize;
|
||||||
|
tmpdy = position.y() - path.at(PathIndex).y()*game->cellsize;
|
||||||
//qDebug() << "next";
|
//qDebug() << "next";
|
||||||
}
|
}
|
||||||
arctg = std::atan(tmpdx/tmpdy);
|
arctg = std::atan(tmpdx/tmpdy);
|
||||||
if (tmpdy < 0) arctg=arctg+3.1416f;
|
if (tmpdy < 0) arctg=arctg+3.1416f;
|
||||||
angl = 180.0f*(-arctg)/3.1416f;
|
angl = 180.0f*(-arctg)/3.1416f;
|
||||||
//if (qAbs(Position.angle-angl) > 10) Position.angle = 5*angl/qAbs(angl);
|
/*if (PathIndex > 1)
|
||||||
//else
|
{
|
||||||
Position.angle = angl;
|
if ((Position.angle-angl < -5 || Position.angle-angl > 5) && angl < 175 && angl > -175)
|
||||||
|
{
|
||||||
|
if (angl > Position.angle) Position.angle += 5;
|
||||||
|
else Position.angle -= 5;
|
||||||
|
}
|
||||||
|
else Position.angle = angl;
|
||||||
|
}
|
||||||
|
else*/ angle = angl;
|
||||||
//qDebug() << "[" << PathIndex << ";" << PicIndex << "]" << "angle:" << Position.angle << "arctg:" << arctg << "Pos:" << Position.pnt;
|
//qDebug() << "[" << PathIndex << ";" << PicIndex << "]" << "angle:" << Position.angle << "arctg:" << arctg << "Pos:" << Position.pnt;
|
||||||
Position.pnt.setX(Position.pnt.x()
|
position.setX(position.x()
|
||||||
-Speed*(float)data->cellsize*std::sin(arctg));
|
-Speed*(float)game->cellsize*std::sin(arctg));
|
||||||
Position.pnt.setY(Position.pnt.y()
|
position.setY(position.y()
|
||||||
-Speed*(float)data->cellsize*std::cos(arctg));
|
-Speed*(float)game->cellsize*std::cos(arctg));
|
||||||
PicIndex++;
|
PicIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*bool Aliens::PathIntersect(Alien* Al, Rectangle rect)
|
|
||||||
{
|
|
||||||
//PathIntersect = False
|
|
||||||
for (int i = Al->PathIndex; i<=Al->path.size(); i++) // To UBound(Al.path(), 1)
|
|
||||||
if (Al->path[i].x + 0.5 >= rect.x0 - 1 && Al->path[i].x + 0.5 <= rect.x1 + 1)
|
|
||||||
if (Al->path[i].y + 0.5 >= rect.y0 - 1 && Al->path[i].y + 0.5 <= rect.y1 + 1)
|
|
||||||
return true; //PathIntersect = True //Exit Function
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
int Alien::WaveTrace(QPoint start, QPoint finish)
|
int Alien::WaveTrace(QPoint start, QPoint finish)
|
||||||
{
|
{
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
int step = 2;
|
int step = 2;
|
||||||
QPoint cp, tp;
|
QPoint cp, tp;
|
||||||
QRect fr(0, 0, data->size.width(), data->size.height());
|
QRect fr(0, 0, game->size.width(), game->size.height());
|
||||||
QVector<QPoint> tmpp, curp;
|
QVector<QPoint> tmpp, curp;
|
||||||
cp = start;
|
cp = start;
|
||||||
curp.push_back(cp);
|
curp.push_back(cp);
|
||||||
@@ -125,7 +128,7 @@ int Alien::WaveTrace(QPoint start, QPoint finish)
|
|||||||
curp.clear();
|
curp.clear();
|
||||||
stop = true;
|
stop = true;
|
||||||
for (int i = 0; i < tmpp.size(); i++) {
|
for (int i = 0; i < tmpp.size(); i++) {
|
||||||
cp = tmpp[i];
|
cp = tmpp.at(i);
|
||||||
if (cp == finish) {
|
if (cp == finish) {
|
||||||
TmpCells[cp.x()][cp.y()] = step;
|
TmpCells[cp.x()][cp.y()] = step;
|
||||||
//qDebug() << "trace done!";
|
//qDebug() << "trace done!";
|
||||||
@@ -160,7 +163,7 @@ int Alien::WaveTrace(QPoint start, QPoint finish)
|
|||||||
}
|
}
|
||||||
step++;
|
step++;
|
||||||
}
|
}
|
||||||
qDebug() << "trace false";
|
//qDebug() << "trace false";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +193,7 @@ QVector<QPoint> Alien::InvWaveTrace(QPoint finish, int cnt)
|
|||||||
chk = chk | 0x01;
|
chk = chk | 0x01;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
if (wp.x() + 1 < data->size.width() && TmpCells[wp.x()+1][wp.y()] == cnt)
|
if (wp.x() + 1 < game->size.width() && TmpCells[wp.x()+1][wp.y()] == cnt)
|
||||||
{
|
{
|
||||||
chk = chk | 0x02;
|
chk = chk | 0x02;
|
||||||
c++;
|
c++;
|
||||||
@@ -200,7 +203,7 @@ QVector<QPoint> Alien::InvWaveTrace(QPoint finish, int cnt)
|
|||||||
chk = chk | 0x04;
|
chk = chk | 0x04;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
if (wp.y() + 1 < data->size.height() && TmpCells[wp.x()][wp.y()+1] == cnt)
|
if (wp.y() + 1 < game->size.height() && TmpCells[wp.x()][wp.y()+1] == cnt)
|
||||||
{
|
{
|
||||||
chk = chk | 0x08;
|
chk = chk | 0x08;
|
||||||
c++;
|
c++;
|
||||||
|
|||||||
14
alien.h
14
alien.h
@@ -1,24 +1,26 @@
|
|||||||
#ifndef ALIEN_H
|
#ifndef ALIEN_H
|
||||||
#define ALIEN_H
|
#define ALIEN_H
|
||||||
|
|
||||||
#include "basestruct.h"
|
#include "games.h"
|
||||||
|
|
||||||
class Alien
|
class Alien
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Alien(GameData * AlienData, float alienspeed = 0.1);
|
Alien(games *parent, float alienspeed = 0.1);
|
||||||
bool RecreatePath();
|
bool RecreatePath();
|
||||||
//bool testTrace() {return (WaveTrace(data->start,data->finish) > 0);}
|
//bool testTrace() {return (WaveTrace(data->start,data->finish) > 0);}
|
||||||
void setPos(QPoint pos) {Position.pnt = pos;}
|
void setPos(QPointF pos) {position = pos;}
|
||||||
void update();
|
void update();
|
||||||
void resetIndexPic() {PicIndex = 0;}
|
void resetIndexPic() {PicIndex = 0;}
|
||||||
FPVector pos() const {return Position;}
|
QPointF Pos() const {return position;}
|
||||||
|
float Angl() const {return angle;}
|
||||||
int indexPix() const {return PicIndex;}
|
int indexPix() const {return PicIndex;}
|
||||||
QVector<QPointF> path;
|
QVector<QPointF> path;
|
||||||
private:
|
private:
|
||||||
int ** TmpCells;
|
int ** TmpCells;
|
||||||
GameData * data;
|
games *game;
|
||||||
FPVector Position;
|
QPointF position;
|
||||||
|
float angle;
|
||||||
//int PicType;
|
//int PicType;
|
||||||
//int FlX;
|
//int FlX;
|
||||||
//int FlY;
|
//int FlY;
|
||||||
|
|||||||
@@ -2,26 +2,26 @@
|
|||||||
# Project created by QtCreator 2009-08-17T19:38:55
|
# Project created by QtCreator 2009-08-17T19:38:55
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
QT += network \
|
QT += network \
|
||||||
opengl
|
opengl
|
||||||
TARGET = aliendefender
|
TARGET = aliendefender
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
adpainter.cpp \
|
adpainter.cpp \
|
||||||
aliens.cpp \
|
aliens.cpp \
|
||||||
udpsender.cpp \
|
udpsender.cpp \
|
||||||
towers.cpp \
|
towers.cpp \
|
||||||
map.cpp \
|
map.cpp \
|
||||||
game.cpp \
|
games.cpp \
|
||||||
alien.cpp
|
alien.cpp
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
adpainter.h \
|
adpainter.h \
|
||||||
aliens.h \
|
aliens.h \
|
||||||
basestruct.h \
|
basestruct.h \
|
||||||
udpsender.h \
|
udpsender.h \
|
||||||
towers.h \
|
towers.h \
|
||||||
map.h \
|
map.h \
|
||||||
game.h \
|
games.h \
|
||||||
alien.h
|
alien.h
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
RESOURCES += images.qrc
|
RESOURCES += images.qrc
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
#include "aliens.h"
|
#include "aliens.h"
|
||||||
|
|
||||||
//using std::vector;
|
Aliens::Aliens(games *parent)
|
||||||
|
|
||||||
Aliens::Aliens(GameData *dataAliens)
|
|
||||||
{
|
{
|
||||||
data = dataAliens;
|
game = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Aliens::AddAlien()
|
bool Aliens::AddAlien()
|
||||||
{
|
{
|
||||||
curAliens.push_back(new Alien(data,0.1));
|
curAliens.push_back(new Alien(game,0.1));
|
||||||
return !curAliens.isEmpty();
|
return !curAliens.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
aliens.h
5
aliens.h
@@ -1,18 +1,17 @@
|
|||||||
#ifndef ALIENS_H
|
#ifndef ALIENS_H
|
||||||
#define ALIENS_H
|
#define ALIENS_H
|
||||||
|
|
||||||
#include "basestruct.h"
|
|
||||||
#include "alien.h"
|
#include "alien.h"
|
||||||
|
|
||||||
class Aliens
|
class Aliens
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Aliens(GameData *dataAliens);
|
Aliens(games *parent);
|
||||||
bool AddAlien();
|
bool AddAlien();
|
||||||
void clearAliens();
|
void clearAliens();
|
||||||
Alien * alienAt(int index) const {return curAliens.at(index);}
|
Alien * alienAt(int index) const {return curAliens.at(index);}
|
||||||
private:
|
private:
|
||||||
GameData * data;
|
games * game;
|
||||||
QVector<Alien*> srcAliens;
|
QVector<Alien*> srcAliens;
|
||||||
QVector<Alien*> curAliens;
|
QVector<Alien*> curAliens;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,23 +10,25 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
struct FPVector
|
struct FPVector
|
||||||
{
|
{
|
||||||
QPointF pnt;
|
QPointF pnt;
|
||||||
float angle;
|
float angle;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
struct GameData
|
struct GameData
|
||||||
{
|
{
|
||||||
QSize size;
|
QSize size;
|
||||||
QPoint start;
|
QPoint start;
|
||||||
QPoint finish;
|
QPoint finish;
|
||||||
|
QPixmap * buff;
|
||||||
int cellsize;
|
int cellsize;
|
||||||
int ** Cells;
|
int ** Cells;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
/*struct Effect
|
/*struct Effect
|
||||||
{
|
{
|
||||||
|
|||||||
16
games.cpp
Normal file
16
games.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "games.h"
|
||||||
|
|
||||||
|
games::games(QSize formsize, QPoint startpnt, QPoint finishpnt, int sizeofcell)
|
||||||
|
{
|
||||||
|
buff = new QPixmap(formsize);
|
||||||
|
background = new QPixmap(formsize);
|
||||||
|
cellsize = sizeofcell;
|
||||||
|
size = formsize/cellsize;
|
||||||
|
start = startpnt/cellsize;
|
||||||
|
finish = finishpnt/cellsize;
|
||||||
|
Cells = new int*[size.width()];
|
||||||
|
for (int i = 0; i < size.width(); i++) {
|
||||||
|
Cells[i] = new int[size.height()];
|
||||||
|
for (int j = 0; j < size.height(); j++) Cells[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
games.h
Normal file
19
games.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef GAMES_H
|
||||||
|
#define GAMES_H
|
||||||
|
|
||||||
|
#include "basestruct.h"
|
||||||
|
|
||||||
|
class games
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
games(QSize formsize, QPoint startpnt, QPoint finishpnt, int sizeofcell = 16);
|
||||||
|
QSize size;
|
||||||
|
QPoint start;
|
||||||
|
QPoint finish;
|
||||||
|
QPixmap * buff;
|
||||||
|
QPixmap * background;
|
||||||
|
int cellsize;
|
||||||
|
int ** Cells;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GAMES_H
|
||||||
@@ -7,8 +7,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
{
|
{
|
||||||
qDebug() << "Load START!";
|
qDebug() << "Load START!";
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
sndr = new UdpSender("127.0.0.1",10101);
|
//sndr = new UdpSender("127.0.0.1",10101);
|
||||||
sndr->connectSend("hellow");
|
//sndr->connectSend("hellow");
|
||||||
cellsize = 16;
|
cellsize = 16;
|
||||||
destx = this->width() / cellsize;
|
destx = this->width() / cellsize;
|
||||||
desty = this->height() / cellsize / 2;
|
desty = this->height() / cellsize / 2;
|
||||||
@@ -17,8 +17,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
adp->clear();
|
adp->clear();
|
||||||
adp->drawgrid();
|
adp->drawgrid();
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(ADrender()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(ADrender()));
|
||||||
GameMain = new game(this->size(),QPoint(0,this->height()/2),QPoint(this->width()-cellsize,this->height()/2), cellsize);
|
GameMain = new games(this->size(),QPoint(0,this->height()/2),QPoint(this->width()-cellsize,this->height()/2), cellsize);
|
||||||
aliens = new Aliens(GameMain->data);
|
aliens = new Aliens(GameMain);
|
||||||
aliens->AddAlien();
|
aliens->AddAlien();
|
||||||
this->setGeometry(100,100,this->width(),this->height());
|
this->setGeometry(100,100,this->width(),this->height());
|
||||||
//qDebug() << "QT version" << qVersion();
|
//qDebug() << "QT version" << qVersion();
|
||||||
@@ -45,14 +45,14 @@ void MainWindow::paintEvent(QPaintEvent*)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::mouseMoveEvent ( QMouseEvent * event )
|
void MainWindow::mouseMoveEvent (QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (mousebt == 1) ClearCell(event->pos());
|
if (mousebt == 1) ClearCell(event->pos());
|
||||||
if (mousebt == 2) SetCell(event->pos());
|
if (mousebt == 2) SetCell(event->pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::mousePressEvent ( QMouseEvent * event )
|
void MainWindow::mousePressEvent (QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
ClearCell(event->pos());
|
ClearCell(event->pos());
|
||||||
@@ -76,7 +76,7 @@ void MainWindow::SetCell(QPoint pos)
|
|||||||
cp.setX(pos.x()/cellsize);
|
cp.setX(pos.x()/cellsize);
|
||||||
cp.setY(pos.y()/cellsize);
|
cp.setY(pos.y()/cellsize);
|
||||||
//qDebug() << "click: " << cp.x() << ";" << cp.y();
|
//qDebug() << "click: " << cp.x() << ";" << cp.y();
|
||||||
GameMain->data->Cells[cp.x()][cp.y()] = - 1;
|
GameMain->Cells[cp.x()][cp.y()] = - 1;
|
||||||
adp->drawcell(cp);
|
adp->drawcell(cp);
|
||||||
//aliens->clearAliens();
|
//aliens->clearAliens();
|
||||||
//adp->StepAlien=0;
|
//adp->StepAlien=0;
|
||||||
@@ -95,7 +95,7 @@ void MainWindow::ClearCell(QPoint pos)
|
|||||||
cp.setX(pos.x()/cellsize);
|
cp.setX(pos.x()/cellsize);
|
||||||
cp.setY(pos.y()/cellsize);
|
cp.setY(pos.y()/cellsize);
|
||||||
//qDebug() << "click: " << cp.x() << ";" << cp.y();
|
//qDebug() << "click: " << cp.x() << ";" << cp.y();
|
||||||
GameMain->data->Cells[cp.x()][cp.y()] = 0;
|
GameMain->Cells[cp.x()][cp.y()] = 0;
|
||||||
adp->clearcell(cp);
|
adp->clearcell(cp);
|
||||||
//aliens->clearAliens();
|
//aliens->clearAliens();
|
||||||
//aliens->AddAlien();
|
//aliens->AddAlien();
|
||||||
@@ -105,6 +105,17 @@ void MainWindow::ClearCell(QPoint pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::keyPressEvent(QKeyEvent * e)
|
||||||
|
{
|
||||||
|
qDebug() << e->key();
|
||||||
|
switch(e->key()) {
|
||||||
|
case 69:
|
||||||
|
aliens->AddAlien();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|||||||
12
mainwindow.h
12
mainwindow.h
@@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QKeyEvent>
|
||||||
#include "adpainter.h"
|
#include "adpainter.h"
|
||||||
#include "aliens.h"
|
#include "aliens.h"
|
||||||
#include "udpsender.h"
|
#include "udpsender.h"
|
||||||
#include "game.h"
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@@ -27,13 +28,14 @@ private:
|
|||||||
void paintEvent(QPaintEvent*);
|
void paintEvent(QPaintEvent*);
|
||||||
void SetCell(QPoint pos);
|
void SetCell(QPoint pos);
|
||||||
void ClearCell(QPoint pos);
|
void ClearCell(QPoint pos);
|
||||||
void mouseMoveEvent ( QMouseEvent * event );
|
void mouseMoveEvent(QMouseEvent *e);
|
||||||
void mousePressEvent ( QMouseEvent * event );
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
void keyPressEvent(QKeyEvent *e);
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Aliens * aliens;
|
Aliens * aliens;
|
||||||
UdpSender * sndr;
|
//UdpSender * sndr;
|
||||||
adpainter * adp;
|
adpainter * adp;
|
||||||
game * GameMain;
|
games * GameMain;
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
int mousebt;
|
int mousebt;
|
||||||
int cellsize, destx, desty;
|
int cellsize, destx, desty;
|
||||||
|
|||||||
2
map.cpp
2
map.cpp
@@ -1,6 +1,6 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
|
||||||
map::map(GameData *dataMap)
|
map::map(games *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
4
map.h
4
map.h
@@ -1,12 +1,12 @@
|
|||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|
||||||
#include "basestruct.h"
|
#include "games.h"
|
||||||
|
|
||||||
class map
|
class map
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
map(GameData *dataMap);
|
map(games *parent);
|
||||||
QPixmap * background;
|
QPixmap * background;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "towers.h"
|
#include "towers.h"
|
||||||
|
|
||||||
towers::towers(GameData *dataTowers)
|
towers::towers(games *parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
8
towers.h
8
towers.h
@@ -1,14 +1,14 @@
|
|||||||
#ifndef TOWERS_H
|
#ifndef TOWERS_H
|
||||||
#define TOWERS_H
|
#define TOWERS_H
|
||||||
|
|
||||||
#include "basestruct.h"
|
#include "games.h"
|
||||||
|
|
||||||
class towers
|
class towers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
towers(GameData *dataTowers);
|
towers(games *parent);
|
||||||
QVector<Tower> srcTowers;
|
//QVector<Tower> srcTowers;
|
||||||
QVector<Tower> curTowers;
|
//QVector<Tower> curTowers;
|
||||||
void AddTower(QPoint point, int type);
|
void AddTower(QPoint point, int type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user