the Alien going right!

This commit is contained in:
2009-09-03 22:56:39 +04:00
parent 7ecbd3764c
commit 5ec3aa2be9
26 changed files with 203 additions and 160 deletions

View File

@@ -1 +0,0 @@
hello

152
Makefile
View File

@@ -1,21 +1,21 @@
############################################################################# #############################################################################
# Makefile for building: wavetrace # Makefile for building: aliendefender
# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 2 15:18:59 2009 # Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 3 22:49:40 2009
# Project: wavetrace.pro # Project: aliendefender.pro
# Template: app # Template: app
# Command: /usr/bin/qmake -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro # Command: /usr/bin/qmake -unix -o Makefile aliendefender.pro
############################################################################# #############################################################################
####### Compiler, tools and options ####### Compiler, tools and options
CC = gcc CC = gcc
CXX = g++ CXX = g++
DEFINES = -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) CFLAGS = -pipe -march=native -O2 -pipe -fomit-frame-pointer -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) CXXFLAGS = -pipe -march=native -O2 -pipe -fomit-frame-pointer -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 = LFLAGS = -Wl,-O1
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 =
@@ -57,30 +57,30 @@ OBJECTS = main.o \
towers.o \ towers.o \
moc_mainwindow.o \ moc_mainwindow.o \
moc_udpsender.o moc_udpsender.o
DIST = ../../../../share/qt4/mkspecs/common/g++.conf \ DIST = ../../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 \
../../../../share/qt4/mkspecs/qconfig.pri \ ../../share/qt4/mkspecs/qconfig.pri \
../../../../share/qt4/mkspecs/features/qt_functions.prf \ ../../share/qt4/mkspecs/features/qt_functions.prf \
../../../../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/debug.prf \ ../../share/qt4/mkspecs/features/release.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 \
../../../../share/qt4/mkspecs/features/unix/opengl.prf \ ../../share/qt4/mkspecs/features/unix/opengl.prf \
../../../../share/qt4/mkspecs/features/unix/thread.prf \ ../../share/qt4/mkspecs/features/unix/thread.prf \
../../../../share/qt4/mkspecs/features/moc.prf \ ../../share/qt4/mkspecs/features/moc.prf \
../../../../share/qt4/mkspecs/features/resources.prf \ ../../share/qt4/mkspecs/features/resources.prf \
../../../../share/qt4/mkspecs/features/uic.prf \ ../../share/qt4/mkspecs/features/uic.prf \
../../../../share/qt4/mkspecs/features/yacc.prf \ ../../share/qt4/mkspecs/features/yacc.prf \
../../../../share/qt4/mkspecs/features/lex.prf \ ../../share/qt4/mkspecs/features/lex.prf \
../../../../share/qt4/mkspecs/features/include_source_dir.prf \ ../../share/qt4/mkspecs/features/include_source_dir.prf \
wavetrace.pro aliendefender.pro
QMAKE_TARGET = wavetrace QMAKE_TARGET = aliendefender
DESTDIR = DESTDIR =
TARGET = wavetrace TARGET = aliendefender
first: all first: all
####### Implicit rules ####### Implicit rules
@@ -109,61 +109,61 @@ all: Makefile $(TARGET)
$(TARGET): ui_mainwindow.h $(OBJECTS) $(TARGET): ui_mainwindow.h $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: wavetrace.pro ../../../../share/qt4/mkspecs/linux-g++/qmake.conf ../../../../share/qt4/mkspecs/common/g++.conf \ Makefile: aliendefender.pro ../../share/qt4/mkspecs/linux-g++/qmake.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 \
../../../../share/qt4/mkspecs/qconfig.pri \ ../../share/qt4/mkspecs/qconfig.pri \
../../../../share/qt4/mkspecs/features/qt_functions.prf \ ../../share/qt4/mkspecs/features/qt_functions.prf \
../../../../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/debug.prf \ ../../share/qt4/mkspecs/features/release.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 \
../../../../share/qt4/mkspecs/features/unix/opengl.prf \ ../../share/qt4/mkspecs/features/unix/opengl.prf \
../../../../share/qt4/mkspecs/features/unix/thread.prf \ ../../share/qt4/mkspecs/features/unix/thread.prf \
../../../../share/qt4/mkspecs/features/moc.prf \ ../../share/qt4/mkspecs/features/moc.prf \
../../../../share/qt4/mkspecs/features/resources.prf \ ../../share/qt4/mkspecs/features/resources.prf \
../../../../share/qt4/mkspecs/features/uic.prf \ ../../share/qt4/mkspecs/features/uic.prf \
../../../../share/qt4/mkspecs/features/yacc.prf \ ../../share/qt4/mkspecs/features/yacc.prf \
../../../../share/qt4/mkspecs/features/lex.prf \ ../../share/qt4/mkspecs/features/lex.prf \
../../../../share/qt4/mkspecs/features/include_source_dir.prf \ ../../share/qt4/mkspecs/features/include_source_dir.prf \
/usr/lib/qt4/libQtOpenGL.prl \ /usr/lib/qt4/libQtOpenGL.prl \
/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) -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro $(QMAKE) -unix -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:
../../../../share/qt4/mkspecs/qconfig.pri: ../../share/qt4/mkspecs/qconfig.pri:
../../../../share/qt4/mkspecs/features/qt_functions.prf: ../../share/qt4/mkspecs/features/qt_functions.prf:
../../../../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/debug.prf: ../../share/qt4/mkspecs/features/release.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:
../../../../share/qt4/mkspecs/features/unix/opengl.prf: ../../share/qt4/mkspecs/features/unix/opengl.prf:
../../../../share/qt4/mkspecs/features/unix/thread.prf: ../../share/qt4/mkspecs/features/unix/thread.prf:
../../../../share/qt4/mkspecs/features/moc.prf: ../../share/qt4/mkspecs/features/moc.prf:
../../../../share/qt4/mkspecs/features/resources.prf: ../../share/qt4/mkspecs/features/resources.prf:
../../../../share/qt4/mkspecs/features/uic.prf: ../../share/qt4/mkspecs/features/uic.prf:
../../../../share/qt4/mkspecs/features/yacc.prf: ../../share/qt4/mkspecs/features/yacc.prf:
../../../../share/qt4/mkspecs/features/lex.prf: ../../share/qt4/mkspecs/features/lex.prf:
../../../../share/qt4/mkspecs/features/include_source_dir.prf: ../../share/qt4/mkspecs/features/include_source_dir.prf:
/usr/lib/qt4/libQtOpenGL.prl: /usr/lib/qt4/libQtOpenGL.prl:
/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: FORCE qmake: FORCE
@$(QMAKE) -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro @$(QMAKE) -unix -o Makefile aliendefender.pro
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/wavetrace1.0.0 || $(MKDIR) .tmp/wavetrace1.0.0 @$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.h adpainter.h aliens.h basestruct.h udpsender.h towers.h .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp adpainter.cpp aliens.cpp udpsender.cpp towers.cpp .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/wavetrace1.0.0/ && (cd `dirname .tmp/wavetrace1.0.0` && $(TAR) wavetrace1.0.0.tar wavetrace1.0.0 && $(COMPRESS) wavetrace1.0.0.tar) && $(MOVE) `dirname .tmp/wavetrace1.0.0`/wavetrace1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/wavetrace1.0.0 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents mainwindow.h adpainter.h aliens.h basestruct.h udpsender.h towers.h .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp adpainter.cpp aliens.cpp udpsender.cpp towers.cpp .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/aliendefender1.0.0/ && (cd `dirname .tmp/aliendefender1.0.0` && $(TAR) aliendefender1.0.0.tar aliendefender1.0.0 && $(COMPRESS) aliendefender1.0.0.tar) && $(MOVE) `dirname .tmp/aliendefender1.0.0`/aliendefender1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/aliendefender1.0.0
clean:compiler_clean clean:compiler_clean

View File

@@ -57,12 +57,13 @@ void adpainter::drawgrid()
} }
void adpainter::drawAliens(deque<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]; //unsigned char dd[4];
//int gg; //int gg;
arctg = 0; arctg = 0;
//qDebug() << path.size();
//QTransform rotated; //QTransform rotated;
painter.begin(buff); painter.begin(buff);
pen->setColor(QColor::fromRgb(qRgb(80,200,100))); pen->setColor(QColor::fromRgb(qRgb(80,200,100)));
@@ -71,22 +72,23 @@ void adpainter::drawAliens(deque<QPointF> path, FPVector * position)
painter.setPen(*pen); painter.setPen(*pen);
painter.setBrush(*brush); painter.setBrush(*brush);
painter.drawPixmap(0,0,*background); painter.drawPixmap(0,0,*background);
for (unsigned int i = 0; i < path.size(); i++){ for (int i = 0; i < path.size(); i++){
painter.drawEllipse(path[i].x() * cellsize +1, path[i].y() * cellsize +1, cellsize - 2, cellsize - 2); 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; tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize;
tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize; tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize;
if (StepAlien + 2 < path.size()) { if (StepAlien + 1 < path.size()) {
tmpdx1 = position->pnt.x() - path.at(StepAlien+2).x()*cellsize; tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize;
tmpdy1 = position->pnt.y() - path.at(StepAlien+2).y()*cellsize; tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize;
} }
arctg = atanf(tmpdx1/tmpdy1); arctg = atanf(tmpdx1/tmpdy1);
//memcpy(&gg,&arctg,4); //memcpy(&gg,&arctg,4);
if (tmpdy1 != 0) position->angle = 180*(-arctg)/3.1415; position->angle = 180*(-arctg)/3.1415;
if (tmpdy1 < 0) position->angle = 180 + position->angle;
if (AlienPix.size() > 0) { if (AlienPix.size() > 0) {
//painter.rotate((arctg/3.1415)*180); //painter.rotate((arctg/3.1415)*180);
//rotated.rotateRadians(arctg/* + 3.1415/2*/); //rotated.rotateRadians(arctg/* + 3.1415/2*/);
//qDebug() << "angle:" << arctg; qDebug() << "angle:" << position->angle;
//rotated.reset(); //rotated.reset();
if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++; if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++;
else { else {
@@ -108,16 +110,16 @@ void adpainter::drawAliens(deque<QPointF> path, FPVector * position)
} }
} }
//painter.save(); //painter.save();
painter.translate(position->pnt.x()-cellsize,position->pnt.y()-cellsize); painter.translate(position->pnt.x()+cellsize/2, position->pnt.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(position->angle); painter.rotate(position->angle);
//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/2, cellsize/2, cellsize*2, cellsize*2, AlienPix.at(AnimAlien)); painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix.at(AnimAlien));
AnimAlien++; AnimAlien++;
//painter.restore(); //painter.restore();
if (AnimAlien >= AlienPix.size()) AnimAlien = 0; if (AnimAlien >= AlienPix.size()) AnimAlien = 0;

View File

@@ -3,7 +3,7 @@
#include "basestruct.h" #include "basestruct.h"
#include <vector> //#include <vector>
#include <cmath> #include <cmath>
#include <QPainter> #include <QPainter>
@@ -18,8 +18,8 @@
#include <QPoint> #include <QPoint>
#include <QDebug> #include <QDebug>
using std::deque; //using std::deque;
using std::vector; //using std::vector;
using std::atan; using std::atan;
class adpainter class adpainter
@@ -31,15 +31,15 @@ public:
void clearcell(QPoint pnt); void clearcell(QPoint pnt);
void clear(); void clear();
QPixmap * getPixmap(); QPixmap * getPixmap();
void drawAliens(deque<QPointF> path, FPVector * position);//int xa, int ya); void drawAliens(QVector<QPointF> path, FPVector * position);//int xa, int ya);
unsigned int AnimAlien, StepAlien; int AnimAlien, StepAlien;
private: private:
QPixmap * buff; QPixmap * buff;
QPixmap * background; QPixmap * background;
QPainter painter; QPainter painter;
QPen * pen; QPen * pen;
QBrush * brush; QBrush * brush;
vector<QPixmap> AlienPix; QVector<QPixmap> AlienPix;
int cellsize; int cellsize;
}; };

Binary file not shown.

BIN
aliendefender Executable file

Binary file not shown.

View File

@@ -3,7 +3,7 @@
# ------------------------------------------------- # -------------------------------------------------
QT += network \ QT += network \
opengl opengl
TARGET = wavetrace TARGET = aliendefender
TEMPLATE = app TEMPLATE = app
SOURCES += main.cpp \ SOURCES += main.cpp \
mainwindow.cpp \ mainwindow.cpp \

View File

@@ -1,16 +1,16 @@
#include "aliens.h" #include "aliens.h"
using std::vector; //using std::vector;
Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize) Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
{ {
cellsize = alcellsize; cellsize = alcellsize;
DestPoint.setX(TmpDestx); DestPoint.setX(TmpDestx - 1);
DestPoint.setY(TmpDesty); DestPoint.setY(TmpDesty);
fw = afw; fw = afw;
fh = afh; fh = afh;
AliensCnt = -1; //AliensCnt = -1;
CurWave = 0; //CurWave = 0;
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++) {
@@ -21,6 +21,29 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
} }
int Aliens::loadAlienImages(int PicType)
{
int i = 1;
QString str1,str2;
QPixmap tmpAlPixmap;
str1.setNum(i);
str2.setNum(PicType);
while (i != 0) {
str1.setNum(i);
tmpAlPixmap.load("./images/Aliens/Al_" + str2 + "_" + str1 + ".png");
qDebug() << tmpAlPixmap.isNull();
if (!tmpAlPixmap.isNull()) {
//AlienPix.push_back(tmpAlPixmap);
tmpAlPixmap = 0;
i++;
}
else i = 0;
}
//qDebug() << "pictures:" << AlienPix.size();
return i;
}
void Aliens::clearCells() void Aliens::clearCells()
{ {
for (int i = 0; i < fw; i++) for (int j = 0; j < fh; j++) Cells[i][j] = 0; for (int i = 0; i < fw; i++) for (int j = 0; j < fh; j++) Cells[i][j] = 0;
@@ -29,33 +52,32 @@ 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(al); //srcAliens[CurWave]);
// curAliens[AliensCnt].Level = CurWave + 1; //curAliens[AliensCnt].Level = CurWave + 1;
curAliens[AliensCnt].Position.pnt.setX(0); curAliens[0].Position.pnt.setX(0);
curAliens[AliensCnt].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6); curAliens[0].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[AliensCnt].DestPnt = DestPoint; curAliens[0].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];
} }
ok = CreatePath(&curAliens[AliensCnt]); return CreatePath(&curAliens[0]);
return ok;
} }
bool Aliens::CreatePath(Alien * al) bool Aliens::CreatePath(Alien * al)
{ {
QPointF tp; QPointF tp;
deque<QPointF> tmpPnt; QVector<QPointF> tmpPnt;
//tmpPnt.clear(); //tmpPnt.clear();
// AliensTmpDestX = fw - 1;//al->Destpnt.x(); // AliensTmpDestX = fw - 1;//al->Destpnt.x();
// AliensTmpDestY = fh / 2;//al->Destpnt.y(); // AliensTmpDestY = fh / 2;//al->Destpnt.y();
@@ -68,7 +90,7 @@ bool Aliens::CreatePath(Alien * al)
tmpPnt.clear(); tmpPnt.clear();
tp = al->path[0]; tp = al->path[0];
tmpPnt.push_back(tp); tmpPnt.push_back(tp);
for (unsigned int i = 0; i < al->path.size() - 1; i++) for (int i = 0; i < al->path.size() - 1; i++)
{ {
tp.setX((al->path[i].x() + al->path[i + 1].x()) / 2); tp.setX((al->path[i].x() + al->path[i + 1].x()) / 2);
tp.setY((al->path[i].y() + al->path[i + 1].y()) / 2); tp.setY((al->path[i].y() + al->path[i + 1].y()) / 2);
@@ -76,17 +98,12 @@ 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);
al->path.swap(tmpPnt); qDebug() << tmpPnt.size();
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);
} }
int i = 0;
tmpPnt.clear(); tmpPnt.clear();
while(1)
{
tp = al->path[0];
break;
}
return true; return true;
} }
return false; return false;
@@ -94,6 +111,12 @@ bool Aliens::CreatePath(Alien * al)
} }
void Aliens::updateAlienPos(Alien * al)
{
}
/*bool Aliens::PathIntersect(Alien* Al, Rectangle rect) /*bool Aliens::PathIntersect(Alien* Al, Rectangle rect)
{ {
//PathIntersect = False //PathIntersect = False
@@ -110,15 +133,17 @@ bool Aliens::WaveTrace(Alien * al) {
int step = 2; int step = 2;
QPoint cp, tp; QPoint cp, tp;
QRect fr(0, 0, fw, fh); QRect fr(0, 0, fw, fh);
vector<QPoint> tmpp, curp; QVector<QPoint> tmpp, curp;
cp = al->Position.pnt; cp = al->Position.pnt;
curp.push_back(cp); curp.push_back(cp);
TmpCells[cp.x()][cp.y()] = 1; TmpCells[cp.x()][cp.y()] = 1;
while (!stop) { while (!stop) {
tmpp = curp; qDebug() << "trace";
tmpp = curp;
curp.clear(); curp.clear();
qDebug() << tmpp.size();
stop = true; stop = true;
for (unsigned int i = 0; i < tmpp.size(); i++) { for (int i = 0; i < tmpp.size(); i++) {
cp = tmpp[i]; cp = tmpp[i];
if (cp == al->DestPnt) { if (cp == al->DestPnt) {
TmpCells[cp.x()][cp.y()] = step; TmpCells[cp.x()][cp.y()] = step;
@@ -292,6 +317,6 @@ void Aliens::InvWaveTrace(QPoint cp, int cnt, Alien * al)
void Aliens::clearAliens() void Aliens::clearAliens()
{ {
AliensCnt = - 1; //AliensCnt = - 1;
curAliens.clear(); curAliens.clear();
} }

View File

@@ -9,22 +9,27 @@ class Aliens
public: public:
Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize); Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize);
deque<Alien> srcAliens; QVector<Alien> srcAliens;
deque<Alien> curAliens; QVector<Alien> curAliens;
//vector< vector<int> > TmpCells; //vector< vector<int> > TmpCells;
int ** Cells; int ** Cells;
int fw, fh, AliensCnt, CurWave;
QPoint DestPoint;
//bool PathIntersect(Alien* Al, Rectangle rect); //bool PathIntersect(Alien* Al, Rectangle rect);
bool AddAlien(); bool AddAlien();
void clearAliens(); void clearAliens();
void clearCells(); void clearCells();
private: private:
int cellsize; int cellsize;
int ** TmpCells; int ** TmpCells;
int fw, fh;
QPoint DestPoint;
QVector< QVector<QPixmap> > AliensPixmaps;
//AlienImages AliensPixmaps[1];
bool CreatePath(Alien* al); bool CreatePath(Alien* al);
bool WaveTrace(Alien* al); bool WaveTrace(Alien* al);
void InvWaveTrace(QPoint cp, int cnt, Alien* al); void InvWaveTrace(QPoint cp, int cnt, Alien* al);
void updateAlienPos(Alien * al);
int loadAlienImages(int PicType);
}; };
#endif // ALIENS_H #endif // ALIENS_H

BIN
aliens.o

Binary file not shown.

View File

@@ -1,15 +1,17 @@
#ifndef BASESTRUCT_H #ifndef BASESTRUCT_H
#define BASESTRUCT_H #define BASESTRUCT_H
#include <vector> #include <QVector>
#include <deque> //#include <deque>
#include <QPoint> #include <QPoint>
#include <QString>
#include <QPixmap>
#include <QPointF> #include <QPointF>
#include <QRect> #include <QRect>
#include <QDebug> #include <QDebug>
using std::vector; //using std::vector;
using std::deque; //using std::deque;
struct FPVector struct FPVector
@@ -18,8 +20,8 @@ struct FPVector
float angle; float angle;
}; };
/*
struct Effect /*struct Effect
{ {
float Health; float Health;
float Speed; float Speed;
@@ -27,27 +29,35 @@ struct Effect
int CntHealth; int CntHealth;
int CntSpeed; int CntSpeed;
int CntArmor; int CntArmor;
}; };*/
*/
/*struct AlienImages
{
vector<QPixmap> pix;
};*/
struct Alien struct Alien
{ {
// unsigned char AName[64]; // unsigned char AName[64];
FPVector Position; FPVector Position;
/* int FlX; int PicType;
int FlY; //int FlX;
int Armor; //int FlY;
int Level; //int Armor;
int Money; //int Level;
//int Money;
int PathIndex; int PathIndex;
int PicIndl; int PicIndex;
int MaxFrame; //int PicIndl;
float Health; //int MaxFrame;
//float Health;
float Speed; float Speed;
float PicFrame; float PicFrame;
float PicInc; //float PicI;
float Regeneration;*/ //float Regeneration;
deque<QPointF> path;//path() As Point QVector<QPointF> path;//path() As Point
QPoint DestPnt; QPoint DestPnt;
// Effect Effects; // Effect Effects;
}; };

BIN
main.o

Binary file not shown.

View File

@@ -5,12 +5,13 @@
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) : QMainWindow(parent), ui(new Ui::MainWindow)
{ {
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 / 2; destx = this->width() / cellsize;
desty = this->height() / cellsize; desty = this->height() / cellsize / 2;
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
adp = new adpainter(this->width(),this->height(),cellsize); adp = new adpainter(this->width(),this->height(),cellsize);
adp->clear(); adp->clear();
@@ -22,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
//qDebug() << "QT version" << qVersion(); //qDebug() << "QT version" << qVersion();
//AnimAlien = 0; //AnimAlien = 0;
timer->start(50); timer->start(50);
qDebug() << "Load DONE!";
} }

Binary file not shown.

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: Mon Aug 31 09:51:05 2009 ** Created: Thu Sep 3 22:52:32 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: Mon Aug 31 09:51:08 2009 ** Created: Thu Sep 3 22:52:35 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

@@ -7,8 +7,8 @@ class towers
{ {
public: public:
towers(); towers();
deque<Tower> srcTowers; QVector<Tower> srcTowers;
deque<Tower> curTowers; QVector<Tower> curTowers;
void AddTower(QPointF point, int ** cells); void AddTower(QPointF point, int ** cells);
}; };

BIN
towers.o

Binary file not shown.

View File

@@ -26,10 +26,10 @@ void UdpSender::slotRead()
QByteArray * recdata = new QByteArray(); QByteArray * recdata = new QByteArray();
*recdata = sock->readAll(); *recdata = sock->readAll();
s = *recdata; s = *recdata;
cout << "Received data: "; qDebug() << "Received data: " << s;
for (int i = 0; i < s.length(); i++) cout << s[i].toAscii(); //for (int i = 0; i < s.length(); i++) cout << s[i].toAscii();
cout << endl; //cout << endl;
qDebug() << sock->write(recstr.toUtf8()); //qDebug() << sock->write(recstr.toUtf8());
qDebug() << sock->socketDescriptor(); qDebug() << sock->socketDescriptor();
} }

View File

@@ -1,9 +1,9 @@
#include <QUdpSocket> #include <QUdpSocket>
#include <QObject> #include <QObject>
#include <iostream> //#include <iostream>
using std::cout; //using std::cout;
using std::endl; //using std::endl;
class UdpSender : public QObject class UdpSender : public QObject
{ {

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: Mon Aug 31 09:50:43 2009 ** Created: Thu Sep 3 22:52:10 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!

BIN
wavetrace

Binary file not shown.