diff --git a/AlienDefender-readme.txt b/AlienDefender-readme.txt new file mode 100644 index 0000000..11e8bd7 --- /dev/null +++ b/AlienDefender-readme.txt @@ -0,0 +1,8 @@ +hello +this is the source code of wavetrace(base part of game) +to compilling this code you must have QT4 library and gcc compiller +to make this project you cad do: + $ qmake -project + $ qmake + $ make +or open the .pro file in Qt-Creator and run aplication. diff --git a/Makefile b/Makefile index ecd7eff..7bcbf19 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: wavetrace -# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ???. 29 18:07:48 2009 +# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 2 15:18:59 2009 # Project: wavetrace.pro # Template: app # Command: /usr/bin/qmake -Wall -spec ../../../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile wavetrace.pro @@ -46,13 +46,17 @@ SOURCES = main.cpp \ mainwindow.cpp \ adpainter.cpp \ aliens.cpp \ - towers.cpp moc_mainwindow.cpp + udpsender.cpp \ + towers.cpp moc_mainwindow.cpp \ + moc_udpsender.cpp OBJECTS = main.o \ mainwindow.o \ adpainter.o \ aliens.o \ + udpsender.o \ towers.o \ - moc_mainwindow.o + moc_mainwindow.o \ + moc_udpsender.o DIST = ../../../../share/qt4/mkspecs/common/g++.conf \ ../../../../share/qt4/mkspecs/common/unix.conf \ ../../../../share/qt4/mkspecs/common/linux.conf \ @@ -159,7 +163,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) .tmp/wavetrace1.0.0 || $(MKDIR) .tmp/wavetrace1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents mainwindow.h adpainter.h aliens.h basestruct.h towers.h .tmp/wavetrace1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp adpainter.cpp aliens.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/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 clean:compiler_clean @@ -178,15 +182,19 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean mocables: compiler_moc_header_make_all compiler_moc_source_make_all -compiler_moc_header_make_all: moc_mainwindow.cpp +compiler_moc_header_make_all: moc_mainwindow.cpp moc_udpsender.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_mainwindow.cpp + -$(DEL_FILE) moc_mainwindow.cpp moc_udpsender.cpp moc_mainwindow.cpp: adpainter.h \ basestruct.h \ aliens.h \ + udpsender.h \ mainwindow.h /usr/bin/moc $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp +moc_udpsender.cpp: udpsender.h + /usr/bin/moc $(DEFINES) $(INCPATH) udpsender.h -o moc_udpsender.cpp + compiler_rcc_make_all: compiler_rcc_clean: compiler_image_collection_make_all: qmake_image_collection.cpp @@ -213,13 +221,15 @@ compiler_clean: compiler_moc_header_clean compiler_uic_clean main.o: main.cpp mainwindow.h \ adpainter.h \ basestruct.h \ - aliens.h + aliens.h \ + udpsender.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp mainwindow.o: mainwindow.cpp mainwindow.h \ adpainter.h \ basestruct.h \ aliens.h \ + udpsender.h \ ui_mainwindow.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp @@ -231,6 +241,9 @@ aliens.o: aliens.cpp aliens.h \ basestruct.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o aliens.o aliens.cpp +udpsender.o: udpsender.cpp udpsender.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o udpsender.o udpsender.cpp + towers.o: towers.cpp towers.h \ basestruct.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o towers.o towers.cpp @@ -238,6 +251,9 @@ towers.o: towers.cpp towers.h \ moc_mainwindow.o: moc_mainwindow.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp +moc_udpsender.o: moc_udpsender.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_udpsender.o moc_udpsender.cpp + ####### Install install: FORCE diff --git a/adpainter.cpp b/adpainter.cpp index 5186d38..f9a11fe 100644 --- a/adpainter.cpp +++ b/adpainter.cpp @@ -60,8 +60,10 @@ void adpainter::drawgrid() void adpainter::drawAliens(deque path, FPVector * position) { float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1; + //unsigned char dd[4]; + //int gg; arctg = 0; - QTransform rotated; + //QTransform rotated; painter.begin(buff); pen->setColor(QColor::fromRgb(qRgb(80,200,100))); brush->setColor(QColor::fromRgb(qRgb(230,10,10))); @@ -74,35 +76,50 @@ void adpainter::drawAliens(deque path, FPVector * position) } 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 (StepAlien + 2 < path.size()) { + tmpdx1 = position->pnt.x() - path.at(StepAlien+2).x()*cellsize; + tmpdy1 = position->pnt.y() - path.at(StepAlien+2).y()*cellsize; + } + arctg = atanf(tmpdx1/tmpdy1); + //memcpy(&gg,&arctg,4); + if (tmpdy1 != 0) position->angle = 180*(-arctg)/3.1415; 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(); + //rotated.rotateRadians(arctg/* + 3.1415/2*/); + //qDebug() << "angle:" << arctg; + //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 (tmpdy < 0) { + position->pnt.ry()++; + //position->angle = - position->angle; + } + else { + position->pnt.ry()--; + } } if (qAbs(tmpdx) >= qAbs(tmpdy)) { - if (tmpdx < 0) position->pnt.rx()++; + if (tmpdx < 0) { + position->pnt.rx()++; + //position->angle = - position->angle; + } else position->pnt.rx()--; } } + //painter.save(); + painter.translate(position->pnt.x()-cellsize,position->pnt.y()-cellsize); + //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); + //position->pnt.setX(path.at(0).x()); + //position->pnt.setY(path.at(0).y()); + painter.drawPixmap(cellsize/2, cellsize/2, cellsize*2, cellsize*2, AlienPix.at(AnimAlien)); + AnimAlien++; + //painter.restore(); if (AnimAlien >= AlienPix.size()) AnimAlien = 0; if (StepAlien >= path.size()) StepAlien = 0; //qDebug() << StepAlien; diff --git a/adpainter.o b/adpainter.o index 894e588..355cdac 100644 Binary files a/adpainter.o and b/adpainter.o differ diff --git a/aliens.cpp b/aliens.cpp index bcf6832..8b3f778 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -80,6 +80,13 @@ bool Aliens::CreatePath(Alien * al) al->Position.pnt.setX(al->path.at(0).x()*cellsize); al->Position.pnt.setY(al->path.at(0).y()*cellsize); } + int i = 0; + tmpPnt.clear(); + while(1) + { + tp = al->path[0]; + break; + } return true; } return false; diff --git a/aliens.o b/aliens.o index 6e11285..ffeee2b 100644 Binary files a/aliens.o and b/aliens.o differ diff --git a/main.o b/main.o index badf38f..9c7060c 100644 Binary files a/main.o and b/main.o differ diff --git a/mainwindow.cpp b/mainwindow.cpp index d2e65ea..ca4b0ac 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + sndr = new UdpSender("127.0.0.1",10101); + sndr->connectSend("hellow"); cellsize = 16; destx = this->width() / cellsize / 2; desty = this->height() / cellsize; diff --git a/mainwindow.h b/mainwindow.h index cbabe4c..27d1edb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -6,6 +6,7 @@ #include #include "adpainter.h" #include "aliens.h" +#include "udpsender.h" namespace Ui { @@ -30,6 +31,7 @@ private: void mousePressEvent ( QMouseEvent * event ); Ui::MainWindow *ui; Aliens * aliens; + UdpSender * sndr; adpainter * adp; bool mousebt; int cellsize, destx, desty; diff --git a/mainwindow.o b/mainwindow.o index 932d025..3fa7721 100644 Binary files a/mainwindow.o and b/mainwindow.o differ diff --git a/moc_mainwindow.cpp b/moc_mainwindow.cpp index 0c6d2a0..df95c2a 100644 --- a/moc_mainwindow.cpp +++ b/moc_mainwindow.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'mainwindow.h' ** -** Created: Sat Aug 29 11:41:18 2009 +** Created: Mon Aug 31 09:51:05 2009 ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2) ** ** WARNING! All changes made in this file will be lost! diff --git a/moc_mainwindow.o b/moc_mainwindow.o index 431f920..bdf3b6b 100644 Binary files a/moc_mainwindow.o and b/moc_mainwindow.o differ diff --git a/moc_udpsender.cpp b/moc_udpsender.cpp new file mode 100644 index 0000000..e6593ef --- /dev/null +++ b/moc_udpsender.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'udpsender.h' +** +** Created: Mon Aug 31 09:51:08 2009 +** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "udpsender.h" +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'udpsender.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 61 +#error "This file was generated using the moc from 4.5.2. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_UdpSender[] = { + + // content: + 2, // revision + 0, // classname + 0, 0, // classinfo + 1, 12, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + + // slots: signature, parameters, type, tag, flags + 11, 10, 10, 10, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_UdpSender[] = { + "UdpSender\0\0slotRead()\0" +}; + +const QMetaObject UdpSender::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_UdpSender, + qt_meta_data_UdpSender, 0 } +}; + +const QMetaObject *UdpSender::metaObject() const +{ + return &staticMetaObject; +} + +void *UdpSender::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_UdpSender)) + return static_cast(const_cast< UdpSender*>(this)); + return QObject::qt_metacast(_clname); +} + +int UdpSender::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + switch (_id) { + case 0: slotRead(); break; + default: ; + } + _id -= 1; + } + return _id; +} +QT_END_MOC_NAMESPACE diff --git a/moc_udpsender.o b/moc_udpsender.o new file mode 100644 index 0000000..2557300 Binary files /dev/null and b/moc_udpsender.o differ diff --git a/udpsender.cpp b/udpsender.cpp new file mode 100644 index 0000000..b39f3ea --- /dev/null +++ b/udpsender.cpp @@ -0,0 +1,45 @@ +#include "udpsender.h" + + +UdpSender::UdpSender(QString IP, quint16 Port) +{ + sock = new QUdpSocket(); + qDebug() << sock->state(); + //cout << sock->socketDescriptor() << endl; + //qDebug() << sock->socketDescriptor(); + addr = QHostAddress(IP); + port = Port; + connect(sock, SIGNAL(readyRead()),this, SLOT(slotRead())); +} + + +UdpSender::~UdpSender() +{ + sock->close(); + delete sock; +} + + +void UdpSender::slotRead() +{ + QString s; + QByteArray * recdata = new QByteArray(); + *recdata = sock->readAll(); + s = *recdata; + cout << "Received data: "; + for (int i = 0; i < s.length(); i++) cout << s[i].toAscii(); + cout << endl; + qDebug() << sock->write(recstr.toUtf8()); + qDebug() << sock->socketDescriptor(); +} + + +void UdpSender::connectSend(QString s) +{ + sz = s.length(); + sock->connectToHost(addr,port); + qDebug() << sock->error(); + qDebug() << sock->state(); + qDebug() << sock->socketDescriptor(); + if (sock->write(s.toUtf8())>0) qDebug() << "writen!"; +} diff --git a/udpsender.h b/udpsender.h new file mode 100644 index 0000000..1151d9e --- /dev/null +++ b/udpsender.h @@ -0,0 +1,24 @@ +#include +#include +#include + +using std::cout; +using std::endl; + +class UdpSender : public QObject +{ + Q_OBJECT + public: + QString recstr; + UdpSender(QString IP, quint16 Port); + ~UdpSender(); + void connectSend(QString s); + public slots: + void slotRead(); + private: + QUdpSocket * sock; + QHostAddress addr; + quint16 port; + quint32 sz; + QByteArray * senddata; +}; diff --git a/udpsender.o b/udpsender.o new file mode 100644 index 0000000..035c395 Binary files /dev/null and b/udpsender.o differ diff --git a/ui_mainwindow.h b/ui_mainwindow.h index 6ed57b4..38b4522 100644 --- a/ui_mainwindow.h +++ b/ui_mainwindow.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading ui file 'mainwindow.ui' ** -** Created: Sat Aug 29 00:10:28 2009 +** Created: Mon Aug 31 09:50:43 2009 ** by: Qt User Interface Compiler version 4.5.2 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! diff --git a/wavetrace b/wavetrace index 3502497..c3fcce7 100755 Binary files a/wavetrace and b/wavetrace differ diff --git a/wavetrace.pro b/wavetrace.pro index 9bd819c..2caa513 100644 --- a/wavetrace.pro +++ b/wavetrace.pro @@ -9,10 +9,12 @@ SOURCES += main.cpp \ mainwindow.cpp \ adpainter.cpp \ aliens.cpp \ + udpsender.cpp \ towers.cpp HEADERS += mainwindow.h \ adpainter.h \ aliens.h \ basestruct.h \ + udpsender.h \ towers.h FORMS += mainwindow.ui