picture loading and rotate alien and retrace

This commit is contained in:
2009-09-05 00:09:46 +04:00
parent 5ec3aa2be9
commit 77da6cad14
41 changed files with 172 additions and 89 deletions

View File

@@ -2,7 +2,9 @@ hello
this is the source code of wavetrace(base part of game) this is the source code of wavetrace(base part of game)
to compilling this code you must have QT4 library and gcc compiller to compilling this code you must have QT4 library and gcc compiller
to make this project you cad do: to make this project you cad do:
$ qmake -project $ qmake
$ make clean
$ make distclean
$ qmake $ qmake
$ make $ make
or open the .pro file in Qt-Creator and run aplication. or open the aliendefender.pro file in Qt-Creator and run aplication.

View File

@@ -1,21 +1,21 @@
############################################################################# #############################################################################
# Makefile for building: aliendefender # Makefile for building: aliendefender
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 3 22:49:40 2009 # Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 3 23:47:46 2009
# Project: aliendefender.pro # Project: aliendefender.pro
# Template: app # Template: app
# Command: /usr/bin/qmake -unix -o Makefile aliendefender.pro # Command: /usr/bin/qmake -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
############################################################################# #############################################################################
####### Compiler, tools and options ####### Compiler, tools and options
CC = gcc CC = gcc
CXX = g++ CXX = g++
DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED DEFINES = -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -march=native -O2 -pipe -fomit-frame-pointer -Wall -W -D_REENTRANT $(DEFINES) CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -march=native -O2 -pipe -fomit-frame-pointer -Wall -W -D_REENTRANT $(DEFINES) CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I../../share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/include -I. -I. INCPATH = -I../../share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/include -I. -I.
LINK = g++ LINK = g++
LFLAGS = -Wl,-O1 LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib/qt4 -L/usr/X11R6/lib -lQtOpenGL -L/usr/lib/qt4 -L/usr/X11R6/lib -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -lQtGui -pthread -lpng -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lXrandr -lXinerama -lfontconfig -lXext -lX11 -lQtNetwork -pthread -pthread -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lGLU -lGL -lpthread LIBS = $(SUBLIBS) -L/usr/lib/qt4 -L/usr/X11R6/lib -lQtOpenGL -L/usr/lib/qt4 -L/usr/X11R6/lib -pthread -pthread -pthread -pthread -pthread -pthread -pthread -pthread -lQtGui -pthread -lpng -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lXrandr -lXinerama -lfontconfig -lXext -lX11 -lQtNetwork -pthread -pthread -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lGLU -lGL -lpthread
AR = ar cqs AR = ar cqs
RANLIB = RANLIB =
@@ -65,7 +65,7 @@ DIST = ../../share/qt4/mkspecs/common/g++.conf \
../../share/qt4/mkspecs/features/qt_config.prf \ ../../share/qt4/mkspecs/features/qt_config.prf \
../../share/qt4/mkspecs/features/exclusive_builds.prf \ ../../share/qt4/mkspecs/features/exclusive_builds.prf \
../../share/qt4/mkspecs/features/default_pre.prf \ ../../share/qt4/mkspecs/features/default_pre.prf \
../../share/qt4/mkspecs/features/release.prf \ ../../share/qt4/mkspecs/features/debug.prf \
../../share/qt4/mkspecs/features/default_post.prf \ ../../share/qt4/mkspecs/features/default_post.prf \
../../share/qt4/mkspecs/features/warn_on.prf \ ../../share/qt4/mkspecs/features/warn_on.prf \
../../share/qt4/mkspecs/features/qt.prf \ ../../share/qt4/mkspecs/features/qt.prf \
@@ -117,7 +117,7 @@ Makefile: aliendefender.pro ../../share/qt4/mkspecs/linux-g++/qmake.conf ../../
../../share/qt4/mkspecs/features/qt_config.prf \ ../../share/qt4/mkspecs/features/qt_config.prf \
../../share/qt4/mkspecs/features/exclusive_builds.prf \ ../../share/qt4/mkspecs/features/exclusive_builds.prf \
../../share/qt4/mkspecs/features/default_pre.prf \ ../../share/qt4/mkspecs/features/default_pre.prf \
../../share/qt4/mkspecs/features/release.prf \ ../../share/qt4/mkspecs/features/debug.prf \
../../share/qt4/mkspecs/features/default_post.prf \ ../../share/qt4/mkspecs/features/default_post.prf \
../../share/qt4/mkspecs/features/warn_on.prf \ ../../share/qt4/mkspecs/features/warn_on.prf \
../../share/qt4/mkspecs/features/qt.prf \ ../../share/qt4/mkspecs/features/qt.prf \
@@ -133,7 +133,7 @@ Makefile: aliendefender.pro ../../share/qt4/mkspecs/linux-g++/qmake.conf ../../
/usr/lib/qt4/libQtGui.prl \ /usr/lib/qt4/libQtGui.prl \
/usr/lib/qt4/libQtCore.prl \ /usr/lib/qt4/libQtCore.prl \
/usr/lib/qt4/libQtNetwork.prl /usr/lib/qt4/libQtNetwork.prl
$(QMAKE) -unix -o Makefile aliendefender.pro $(QMAKE) -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
../../share/qt4/mkspecs/common/g++.conf: ../../share/qt4/mkspecs/common/g++.conf:
../../share/qt4/mkspecs/common/unix.conf: ../../share/qt4/mkspecs/common/unix.conf:
../../share/qt4/mkspecs/common/linux.conf: ../../share/qt4/mkspecs/common/linux.conf:
@@ -142,7 +142,7 @@ Makefile: aliendefender.pro ../../share/qt4/mkspecs/linux-g++/qmake.conf ../../
../../share/qt4/mkspecs/features/qt_config.prf: ../../share/qt4/mkspecs/features/qt_config.prf:
../../share/qt4/mkspecs/features/exclusive_builds.prf: ../../share/qt4/mkspecs/features/exclusive_builds.prf:
../../share/qt4/mkspecs/features/default_pre.prf: ../../share/qt4/mkspecs/features/default_pre.prf:
../../share/qt4/mkspecs/features/release.prf: ../../share/qt4/mkspecs/features/debug.prf:
../../share/qt4/mkspecs/features/default_post.prf: ../../share/qt4/mkspecs/features/default_post.prf:
../../share/qt4/mkspecs/features/warn_on.prf: ../../share/qt4/mkspecs/features/warn_on.prf:
../../share/qt4/mkspecs/features/qt.prf: ../../share/qt4/mkspecs/features/qt.prf:
@@ -159,7 +159,7 @@ Makefile: aliendefender.pro ../../share/qt4/mkspecs/linux-g++/qmake.conf ../../
/usr/lib/qt4/libQtCore.prl: /usr/lib/qt4/libQtCore.prl:
/usr/lib/qt4/libQtNetwork.prl: /usr/lib/qt4/libQtNetwork.prl:
qmake: FORCE qmake: FORCE
@$(QMAKE) -unix -o Makefile aliendefender.pro @$(QMAKE) -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0 @$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0

View File

@@ -14,8 +14,7 @@ adpainter::adpainter(int width, int height, int adpcellsize)
str.setNum(i); str.setNum(i);
while (i != 0) { while (i != 0) {
str.setNum(i); str.setNum(i);
tmpAlPixmap.load("./images/Aliens/Al_00_" + str + ".png"); tmpAlPixmap.load("./images/Aliens/Al_0_" + str + ".png");
qDebug() << tmpAlPixmap.isNull();
if (!tmpAlPixmap.isNull()) { if (!tmpAlPixmap.isNull()) {
AlienPix.push_back(tmpAlPixmap); AlienPix.push_back(tmpAlPixmap);
tmpAlPixmap = 0; tmpAlPixmap = 0;
@@ -60,11 +59,7 @@ void adpainter::drawgrid()
void adpainter::drawAliens(QVector<QPointF> path, FPVector * position) void adpainter::drawAliens(QVector<QPointF> path, FPVector * position)
{ {
float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1; float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1;
//unsigned char dd[4];
//int gg;
arctg = 0; arctg = 0;
//qDebug() << path.size();
//QTransform rotated;
painter.begin(buff); painter.begin(buff);
pen->setColor(QColor::fromRgb(qRgb(80,200,100))); pen->setColor(QColor::fromRgb(qRgb(80,200,100)));
brush->setColor(QColor::fromRgb(qRgb(230,10,10))); brush->setColor(QColor::fromRgb(qRgb(230,10,10)));
@@ -82,48 +77,30 @@ void adpainter::drawAliens(QVector<QPointF> path, FPVector * position)
tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize; tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize;
} }
arctg = atanf(tmpdx1/tmpdy1); arctg = atanf(tmpdx1/tmpdy1);
//memcpy(&gg,&arctg,4);
position->angle = 180*(-arctg)/3.1415; position->angle = 180*(-arctg)/3.1415;
if (tmpdy1 < 0) position->angle = 180 + position->angle; if (tmpdy1 < 0) position->angle = 180 + position->angle;
if (AlienPix.size() > 0) { if (AlienPix.size() > 0) {
//painter.rotate((arctg/3.1415)*180); //qDebug() << "angle:" << position->angle;
//rotated.rotateRadians(arctg/* + 3.1415/2*/);
qDebug() << "angle:" << position->angle;
//rotated.reset();
if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++; if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++;
else { else {
if (qAbs(tmpdx) <= qAbs(tmpdy)) { if (qAbs(tmpdx) <= qAbs(tmpdy)) {
if (tmpdy < 0) { if (tmpdy < 0) position->pnt.ry()++;
position->pnt.ry()++; else position->pnt.ry()--;
//position->angle = - position->angle;
}
else {
position->pnt.ry()--;
}
} }
if (qAbs(tmpdx) >= qAbs(tmpdy)) { if (qAbs(tmpdx) >= qAbs(tmpdy)) {
if (tmpdx < 0) { if (tmpdx < 0) position->pnt.rx()++;
position->pnt.rx()++;
//position->angle = - position->angle;
}
else position->pnt.rx()--; else position->pnt.rx()--;
} }
} }
//painter.save();
painter.translate(position->pnt.x()+cellsize/2, position->pnt.y()+cellsize/2); painter.translate(position->pnt.x()+cellsize/2, position->pnt.y()+cellsize/2);
//if (arctg == 0) painter.rotate(90);
//memcpy(dd,&gg,4);
//dd[0]=0xFF;
//qDebug() << "angle:" << position->angle;
//qDebug() << dd[0] << dd[1] << dd[2] << dd[3];
painter.rotate(position->angle); painter.rotate(position->angle);
//position->pnt.setX(path.at(0).x());
//position->pnt.setY(path.at(0).y());
painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix.at(AnimAlien)); painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix.at(AnimAlien));
AnimAlien++; AnimAlien++;
//painter.restore();
if (AnimAlien >= AlienPix.size()) AnimAlien = 0; if (AnimAlien >= AlienPix.size()) AnimAlien = 0;
if (StepAlien >= path.size()) StepAlien = 0; if (StepAlien >= path.size()) {
StepAlien = 0;
position->pnt = path.at(0);
}
//qDebug() << StepAlien; //qDebug() << StepAlien;
} }
painter.end(); painter.end();

Binary file not shown.

Binary file not shown.

View File

@@ -10,7 +10,7 @@
</data> </data>
<data> <data>
<variable>RunConfiguration0-RunConfiguration.name</variable> <variable>RunConfiguration0-RunConfiguration.name</variable>
<value type="QString" >wavetrace</value> <value type="QString" >aliendefender</value>
</data> </data>
<data> <data>
<variable>RunConfiguration0-UseDyldImageSuffix</variable> <variable>RunConfiguration0-UseDyldImageSuffix</variable>
@@ -26,15 +26,47 @@
</data> </data>
<data> <data>
<variable>RunConfiguration0-UserSetName</variable> <variable>RunConfiguration0-UserSetName</variable>
<value type="bool" >false</value> <value type="bool" >true</value>
</data> </data>
<data> <data>
<variable>RunConfiguration0-type</variable> <variable>RunConfiguration0-type</variable>
<value type="QString" >Qt4ProjectManager.Qt4RunConfiguration</value> <value type="QString" >Qt4ProjectManager.Qt4RunConfiguration</value>
</data> </data>
<data>
<variable>RunConfiguration1-CommandLineArguments</variable>
<valuelist type="QVariantList" />
</data>
<data>
<variable>RunConfiguration1-ProFile</variable>
<value type="QString" >aliendefender.pro</value>
</data>
<data>
<variable>RunConfiguration1-RunConfiguration.name</variable>
<value type="QString" >aliendefender</value>
</data>
<data>
<variable>RunConfiguration1-UseDyldImageSuffix</variable>
<value type="bool" >false</value>
</data>
<data>
<variable>RunConfiguration1-UseTerminal</variable>
<value type="bool" >false</value>
</data>
<data>
<variable>RunConfiguration1-UserEnvironmentChanges</variable>
<valuelist type="QVariantList" />
</data>
<data>
<variable>RunConfiguration1-UserSetName</variable>
<value type="bool" >false</value>
</data>
<data>
<variable>RunConfiguration1-type</variable>
<value type="QString" >Qt4ProjectManager.Qt4RunConfiguration</value>
</data>
<data> <data>
<variable>activeRunConfiguration</variable> <variable>activeRunConfiguration</variable>
<value type="int" >0</value> <value type="int" >1</value>
</data> </data>
<data> <data>
<variable>activebuildconfiguration</variable> <variable>activebuildconfiguration</variable>
@@ -46,7 +78,7 @@
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString" >Debug</value> <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString" >Debug</value>
<value key="QtVersionId" type="int" >0</value> <value key="QtVersionId" type="int" >0</value>
<value key="addQDumper" type="" ></value> <value key="addQDumper" type="" ></value>
<value key="buildDirectory" type="QString" >/home/andrey/sm11/Alien Defender/wavetrace</value> <value key="buildDirectory" type="QString" >/home/andrey/aliendefender</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>
@@ -110,7 +142,7 @@
<value type="QString" >XSESSION=icewm</value> <value type="QString" >XSESSION=icewm</value>
</valuelist> </valuelist>
<valuelist key="abstractProcess.arguments" type="QVariantList" > <valuelist key="abstractProcess.arguments" type="QVariantList" >
<value type="QString" >/home/andrey/sm11/Alien Defender/wavetrace/wavetrace.pro</value> <value type="QString" >/home/andrey/aliendefender/aliendefender.pro</value>
<value type="QString" >-spec</value> <value type="QString" >-spec</value>
<value type="QString" >/usr/share/qt4/mkspecs/linux-g++</value> <value type="QString" >/usr/share/qt4/mkspecs/linux-g++</value>
<value type="QString" >-r</value> <value type="QString" >-r</value>
@@ -119,7 +151,7 @@
</valuelist> </valuelist>
<value key="abstractProcess.command" type="QString" >/usr/bin/qmake</value> <value key="abstractProcess.command" type="QString" >/usr/bin/qmake</value>
<value key="abstractProcess.enabled" type="bool" >false</value> <value key="abstractProcess.enabled" type="bool" >false</value>
<value key="abstractProcess.workingDirectory" type="QString" >/home/andrey/sm11/Alien Defender/wavetrace</value> <value key="abstractProcess.workingDirectory" type="QString" >/home/andrey/aliendefender</value>
<value key="buildConfiguration" type="int" >2</value> <value key="buildConfiguration" type="int" >2</value>
<valuelist key="qmakeArgs" type="QVariantList" > <valuelist key="qmakeArgs" type="QVariantList" >
<value type="QString" >-Wall</value> <value type="QString" >-Wall</value>
@@ -184,7 +216,7 @@
</valuelist> </valuelist>
<value key="abstractProcess.command" type="QString" >/usr/bin/make</value> <value key="abstractProcess.command" type="QString" >/usr/bin/make</value>
<value key="abstractProcess.enabled" type="bool" >true</value> <value key="abstractProcess.enabled" type="bool" >true</value>
<value key="abstractProcess.workingDirectory" type="QString" >/home/andrey/sm11/Alien Defender/wavetrace</value> <value key="abstractProcess.workingDirectory" type="QString" >/home/andrey/aliendefender</value>
<valuelist key="makeargs" type="QVariantList" > <valuelist key="makeargs" type="QVariantList" >
<value type="QString" >-j3</value> <value type="QString" >-j3</value>
</valuelist> </valuelist>

View File

@@ -10,7 +10,7 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
fw = afw; fw = afw;
fh = afh; fh = afh;
//AliensCnt = -1; //AliensCnt = -1;
//CurWave = 0; CurWave = -1;
Cells = new int*[fw]; Cells = new int*[fw];
TmpCells = new int*[fw]; TmpCells = new int*[fw];
for (int i = 0; i < fw; i++) { for (int i = 0; i < fw; i++) {
@@ -18,29 +18,58 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
TmpCells[i] = new int[fh]; TmpCells[i] = new int[fh];
} }
clearCells(); clearCells();
Alien al;
al.PicType = 0;
al.PathIndex = 0;
al.PicFrame = 0;
al.Speed = 1;
srcAliens.push_back(al);
CurWave = 0;
} }
int Aliens::loadAlienImages(int PicType) bool Aliens::loadPixmaps(Alien * al)
{
if (AliensPixmaps.size() != 0) {
for (int i = 0; i < AliensPixmaps.size(); i++) {
if (AliensPixmaps[i].type == al->PicType) {
qDebug() << "Pictures exist!";
return true;
}
}
}
AlienImages * pixmaps;
pixmaps = new AlienImages;
if (loadPixmap(al->PicType,pixmaps) > 0) AliensPixmaps.push_back(* pixmaps);
else return false;
qDebug() << "Pictures loaded!";
return true;
}
int Aliens::loadPixmap(int PicType, AlienImages * pixmaps)
{ {
int i = 1; int i = 1;
QString str1,str2; QString str1,str2;
QPixmap tmpAlPixmap; QPixmap tmpAlPixmap;
str1.setNum(i); str1.setNum(i);
str2.setNum(PicType); str2.setNum(PicType);
qDebug() << PicType;
while (i != 0) { while (i != 0) {
str1.setNum(i); str1.setNum(i);
tmpAlPixmap.load("./images/Aliens/Al_" + str2 + "_" + str1 + ".png"); tmpAlPixmap.load("./images/Aliens/Al_" + str2 + "_" + str1 + ".png");
qDebug() << tmpAlPixmap.isNull(); //qDebug() << tmpAlPixmap.isNull();
if (!tmpAlPixmap.isNull()) { if (!tmpAlPixmap.isNull()) {
//AlienPix.push_back(tmpAlPixmap); //AlienPix.push_back(tmpAlPixmap);
pixmaps->pix.push_back(tmpAlPixmap);
pixmaps->type = PicType;
tmpAlPixmap = 0; tmpAlPixmap = 0;
i++; i++;
} }
else i = 0; else i = 0;
} }
//qDebug() << "pictures:" << AlienPix.size(); qDebug() << "pictures:" << pixmaps->pix.size();
return i; return pixmaps->pix.size();
} }
@@ -53,24 +82,24 @@ void Aliens::clearCells()
bool Aliens::AddAlien() bool Aliens::AddAlien()
{ {
//bool ok; //bool ok;
Alien al; //Alien al;
//AliensCnt++; //AliensCnt++;
//if (CurWave < 0) CurWave = 0; //if (CurWave < 0) CurWave = 0;
//if (AliensCnt > curAliens.size()) ReDim Preserve Aliens(AliensCnt) As Alien //if (AliensCnt > curAliens.size()) ReDim Preserve Aliens(AliensCnt) As Alien
//Aliens(AliensCnt) = SrcAliens(CurWave) //Aliens(AliensCnt) = SrcAliens(CurWave)
curAliens.push_back(al); //srcAliens[CurWave]); curAliens.push_back(srcAliens.at(CurWave));
//curAliens[AliensCnt].Level = CurWave + 1; //curAliens[AliensCnt].Level = CurWave + 1;
curAliens[0].Position.pnt.setX(0); curAliens[curAliens.size()-1].Position.pnt.setX(0);
curAliens[0].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6); curAliens[curAliens.size()-1].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6);
//DestPoint.setX(fw - 1); //DestPoint.setX(fw - 1);
//DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y(); //DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y();
curAliens[0].DestPnt = DestPoint; curAliens[curAliens.size()-1].DestPnt = DestPoint;
// curAliens[AliensCnt].MaxFrame = 0; //srcAliens[CurWave].MaxFrame; // curAliens[AliensCnt].MaxFrame = 0; //srcAliens[CurWave].MaxFrame;
// curAliens[AliensCnt].PicFrame = 0; // curAliens[AliensCnt].PicFrame = 0;
for (int i = 0; i < fw; i++) { for (int i = 0; i < fw; i++) {
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j]; for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
} }
return CreatePath(&curAliens[0]); return (CreatePath(&curAliens[curAliens.size()-1]) && loadPixmaps(&curAliens[curAliens.size()-1]));
} }
@@ -89,6 +118,7 @@ bool Aliens::CreatePath(Alien * al)
{ {
tmpPnt.clear(); tmpPnt.clear();
tp = al->path[0]; tp = al->path[0];
//qDebug() << al->path.at(0);
tmpPnt.push_back(tp); tmpPnt.push_back(tp);
for (int i = 0; i < al->path.size() - 1; i++) for (int i = 0; i < al->path.size() - 1; i++)
{ {
@@ -98,7 +128,7 @@ bool Aliens::CreatePath(Alien * al)
} }
tp = al->path[al->path.size() - 1]; tp = al->path[al->path.size() - 1];
tmpPnt.push_back(tp); tmpPnt.push_back(tp);
qDebug() << tmpPnt.size(); //qDebug() << tmpPnt.size();
al->path = tmpPnt; al->path = tmpPnt;
al->Position.pnt.setX(al->path.at(0).x()*cellsize); al->Position.pnt.setX(al->path.at(0).x()*cellsize);
al->Position.pnt.setY(al->path.at(0).y()*cellsize); al->Position.pnt.setY(al->path.at(0).y()*cellsize);
@@ -128,17 +158,38 @@ void Aliens::updateAlienPos(Alien * al)
}*/ }*/
bool Aliens::recreatePath()
{
QPointF ap;
bool trace;
for (int i = 0; i < fw; i++) {
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
}
for (int i = 0; i < curAliens.size(); i++) {
ap = curAliens[i].Position.pnt;
curAliens[i].Position.pnt.setX(0);
curAliens[i].Position.pnt.setY(fh/2);
curAliens[i].path.clear();
trace = CreatePath(&curAliens[i]);
if (!trace) return false;
curAliens[i].Position.pnt = ap;
}
return true;
}
bool Aliens::WaveTrace(Alien * al) { bool Aliens::WaveTrace(Alien * al) {
bool stop = false; bool stop = false;
int step = 2; int step = 2;
QPoint cp, tp; QPoint cp, tp;
QRect fr(0, 0, fw, fh); QRect fr(0, 0, fw, fh);
QVector<QPoint> tmpp, curp; QVector<QPoint> tmpp, curp;
cp = al->Position.pnt; cp.setX(al->Position.pnt.x());
curp.push_back(cp); cp.setY(al->Position.pnt.y());
curp.push_back(cp);
TmpCells[cp.x()][cp.y()] = 1; TmpCells[cp.x()][cp.y()] = 1;
while (!stop) { while (!stop) {
qDebug() << "trace"; //qDebug() << "trace";
tmpp = curp; tmpp = curp;
curp.clear(); curp.clear();
qDebug() << tmpp.size(); qDebug() << tmpp.size();
@@ -317,6 +368,5 @@ void Aliens::InvWaveTrace(QPoint cp, int cnt, Alien * al)
void Aliens::clearAliens() void Aliens::clearAliens()
{ {
//AliensCnt = - 1;
curAliens.clear(); curAliens.clear();
} }

View File

@@ -13,23 +13,26 @@ class Aliens
QVector<Alien> curAliens; QVector<Alien> curAliens;
//vector< vector<int> > TmpCells; //vector< vector<int> > TmpCells;
int ** Cells; int ** Cells;
int CurWave;
//bool PathIntersect(Alien* Al, Rectangle rect); //bool PathIntersect(Alien* Al, Rectangle rect);
bool AddAlien(); bool AddAlien();
void clearAliens(); void clearAliens();
void clearCells(); void clearCells();
bool recreatePath();
private: private:
int cellsize; int cellsize;
int ** TmpCells; int ** TmpCells;
int fw, fh; int fw, fh;
QPoint DestPoint; QPoint DestPoint;
QVector< QVector<QPixmap> > AliensPixmaps; QVector<AlienImages> AliensPixmaps;
//AlienImages AliensPixmaps[1]; //AlienImages AliensPixmaps[1];
bool CreatePath(Alien* al);
bool WaveTrace(Alien* al); bool WaveTrace(Alien* al);
void InvWaveTrace(QPoint cp, int cnt, Alien* al); bool CreatePath(Alien* al);
void InvWaveTrace(QPoint cp, int cnt, Alien* al);
void updateAlienPos(Alien * al); void updateAlienPos(Alien * al);
int loadAlienImages(int PicType); int loadPixmap(int PicType, AlienImages * pixmaps);
bool loadPixmaps(Alien * al);
}; };
#endif // ALIENS_H #endif // ALIENS_H

BIN
aliens.o

Binary file not shown.

View File

@@ -16,7 +16,7 @@
struct FPVector struct FPVector
{ {
QPoint pnt; QPointF pnt;
float angle; float angle;
}; };
@@ -32,10 +32,11 @@ struct FPVector
};*/ };*/
/*struct AlienImages struct AlienImages
{ {
vector<QPixmap> pix; QVector<QPixmap> pix;
};*/ int type;
};
struct Alien struct Alien

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
main.o

Binary file not shown.

View File

@@ -8,7 +8,7 @@ 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;
@@ -18,7 +18,7 @@ MainWindow::MainWindow(QWidget *parent)
adp->drawgrid(); adp->drawgrid();
connect(timer, SIGNAL(timeout()), this, SLOT(ADrender())); connect(timer, SIGNAL(timeout()), this, SLOT(ADrender()));
aliens = new Aliens(destx, desty, this->width() / cellsize ,this->height() / cellsize, cellsize); aliens = new Aliens(destx, desty, this->width() / cellsize ,this->height() / cellsize, cellsize);
aliens->AddAlien(); if (!aliens->AddAlien()) qDebug() << "Error Loading";
this->setGeometry(100,100,this->width(),this->height()); this->setGeometry(100,100,this->width(),this->height());
//qDebug() << "QT version" << qVersion(); //qDebug() << "QT version" << qVersion();
//AnimAlien = 0; //AnimAlien = 0;
@@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::ADrender() void MainWindow::ADrender()
{ {
//aliens->AddAlien();
adp->drawAliens(aliens->curAliens[0].path, &aliens->curAliens[0].Position); adp->drawAliens(aliens->curAliens[0].path, &aliens->curAliens[0].Position);
this->repaint(); this->repaint();
} }
@@ -72,10 +73,10 @@ void MainWindow::SetCell(int x, int y)
//qDebug() << "click: " << cp.x() << ";" << cp.y(); //qDebug() << "click: " << cp.x() << ";" << cp.y();
aliens->Cells[cp.x()][cp.y()] = - 1; aliens->Cells[cp.x()][cp.y()] = - 1;
adp->drawcell(cp); adp->drawcell(cp);
aliens->clearAliens(); //aliens->recreatePath();
adp->StepAlien=0; //adp->StepAlien=0;
adp->AnimAlien=0; //adp->AnimAlien=0;
if (!aliens->AddAlien()) ClearCell(x,y); if (!aliens->recreatePath()) ClearCell(x,y);
} }
} }
@@ -90,8 +91,10 @@ void MainWindow::ClearCell(int x, int y)
//qDebug() << "click: " << cp.x() << ";" << cp.y(); //qDebug() << "click: " << cp.x() << ";" << cp.y();
aliens->Cells[cp.x()][cp.y()] = 0; aliens->Cells[cp.x()][cp.y()] = 0;
adp->clearcell(cp); adp->clearcell(cp);
aliens->clearAliens(); qDebug() << aliens->recreatePath();
aliens->AddAlien(); //aliens->clearAliens();
//aliens->AddAlien();
} }
} }

Binary file not shown.

View File

@@ -31,7 +31,18 @@
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="widget"/> <widget class="QWidget" name="widget">
<widget class="QWidget" name="paintWidget" native="true">
<property name="geometry">
<rect>
<x>40</x>
<y>20</y>
<width>361</width>
<height>181</height>
</rect>
</property>
</widget>
</widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
** Meta object code from reading C++ file 'mainwindow.h' ** Meta object code from reading C++ file 'mainwindow.h'
** **
** Created: Thu Sep 3 22:52:32 2009 ** Created: Fri Sep 4 20:48:45 2009
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2) ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!

Binary file not shown.

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
** Meta object code from reading C++ file 'udpsender.h' ** Meta object code from reading C++ file 'udpsender.h'
** **
** Created: Thu Sep 3 22:52:35 2009 ** Created: Thu Sep 3 23:47:54 2009
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2) ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!

Binary file not shown.

BIN
towers.o

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,7 @@
/******************************************************************************** /********************************************************************************
** Form generated from reading ui file 'mainwindow.ui' ** Form generated from reading ui file 'mainwindow.ui'
** **
** Created: Thu Sep 3 22:52:10 2009 ** Created: Fri Sep 4 20:29:58 2009
** by: Qt User Interface Compiler version 4.5.2 ** by: Qt User Interface Compiler version 4.5.2
** **
** WARNING! All changes made in this file will be lost when recompiling ui file! ** WARNING! All changes made in this file will be lost when recompiling ui file!
@@ -24,6 +24,7 @@ class Ui_MainWindow
{ {
public: public:
QWidget *widget; QWidget *widget;
QWidget *paintWidget;
void setupUi(QMainWindow *MainWindow) void setupUi(QMainWindow *MainWindow)
{ {
@@ -39,6 +40,9 @@ public:
MainWindow->setBaseSize(QSize(800, 400)); MainWindow->setBaseSize(QSize(800, 400));
widget = new QWidget(MainWindow); widget = new QWidget(MainWindow);
widget->setObjectName(QString::fromUtf8("widget")); widget->setObjectName(QString::fromUtf8("widget"));
paintWidget = new QWidget(widget);
paintWidget->setObjectName(QString::fromUtf8("paintWidget"));
paintWidget->setGeometry(QRect(40, 20, 361, 181));
MainWindow->setCentralWidget(widget); MainWindow->setCentralWidget(widget);
retranslateUi(MainWindow); retranslateUi(MainWindow);