diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dbb5328 --- /dev/null +++ b/Makefile @@ -0,0 +1,311 @@ +############################################################################# +# Makefile for building: aliendefender +# Generated by qmake (2.01a) (Qt 4.6.2) on: ?? ???? 28 22:43:44 2010 +# Project: aliendefender.pro +# Template: app +# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. +LINK = g++ +LFLAGS = +LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/bin/qmake-qt4 +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = map.cpp \ + game_data.cpp \ + aliens.cpp \ + towers.cpp \ + main.cpp \ + splashes.cpp \ + adcore.cpp moc_map.cpp \ + moc_game_data.cpp \ + moc_aliens.cpp \ + moc_towers.cpp \ + moc_splashes.cpp \ + moc_adcore.cpp +OBJECTS = map.o \ + game_data.o \ + aliens.o \ + towers.o \ + main.o \ + splashes.o \ + adcore.o \ + moc_map.o \ + moc_game_data.o \ + moc_aliens.o \ + moc_towers.o \ + moc_splashes.o \ + moc_adcore.o +DIST = /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/debug.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + aliendefender.pro +QMAKE_TARGET = aliendefender +DESTDIR = +TARGET = aliendefender + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: aliendefender.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/debug.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/libQtGui.prl \ + /usr/lib/libQtCore.prl + $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro +/usr/share/qt4/mkspecs/common/g++.conf: +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/usr/share/qt4/mkspecs/features/qt_config.prf: +/usr/share/qt4/mkspecs/features/exclusive_builds.prf: +/usr/share/qt4/mkspecs/features/default_pre.prf: +/usr/share/qt4/mkspecs/features/debug.prf: +/usr/share/qt4/mkspecs/features/default_post.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/share/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/libQtGui.prl: +/usr/lib/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/aliendefender1.0.0 || $(MKDIR) .tmp/aliendefender1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents base_types.h map.h game_data.h aliens.h towers.h splashes.h adcore.h .tmp/aliendefender1.0.0/ && $(COPY_FILE) --parents map.cpp game_data.cpp aliens.cpp towers.cpp main.cpp splashes.cpp adcore.cpp .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 + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +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_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_map.cpp moc_game_data.cpp moc_aliens.cpp moc_towers.cpp moc_splashes.cpp moc_adcore.cpp +moc_map.cpp: base_types.h \ + map.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) map.h -o moc_map.cpp + +moc_game_data.cpp: map.h \ + base_types.h \ + game_data.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) game_data.h -o moc_game_data.cpp + +moc_aliens.cpp: game_data.h \ + map.h \ + base_types.h \ + aliens.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) aliens.h -o moc_aliens.cpp + +moc_towers.cpp: game_data.h \ + map.h \ + base_types.h \ + towers.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) towers.h -o moc_towers.cpp + +moc_splashes.cpp: game_data.h \ + map.h \ + base_types.h \ + splashes.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) splashes.h -o moc_splashes.cpp + +moc_adcore.cpp: aliens.h \ + game_data.h \ + map.h \ + base_types.h \ + towers.h \ + splashes.h \ + adcore.h + /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) adcore.h -o moc_adcore.cpp + +compiler_rcc_make_all: +compiler_rcc_clean: +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean + +####### Compile + +map.o: map.cpp map.h \ + base_types.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o map.o map.cpp + +game_data.o: game_data.cpp game_data.h \ + map.h \ + base_types.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o game_data.o game_data.cpp + +aliens.o: aliens.cpp aliens.h \ + game_data.h \ + map.h \ + base_types.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o aliens.o aliens.cpp + +towers.o: towers.cpp towers.h \ + game_data.h \ + map.h \ + base_types.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o towers.o towers.cpp + +main.o: main.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +splashes.o: splashes.cpp splashes.h \ + game_data.h \ + map.h \ + base_types.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o splashes.o splashes.cpp + +adcore.o: adcore.cpp adcore.h \ + aliens.h \ + game_data.h \ + map.h \ + base_types.h \ + towers.h \ + splashes.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o adcore.o adcore.cpp + +moc_map.o: moc_map.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_map.o moc_map.cpp + +moc_game_data.o: moc_game_data.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_game_data.o moc_game_data.cpp + +moc_aliens.o: moc_aliens.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_aliens.o moc_aliens.cpp + +moc_towers.o: moc_towers.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_towers.o moc_towers.cpp + +moc_splashes.o: moc_splashes.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_splashes.o moc_splashes.cpp + +moc_adcore.o: moc_adcore.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_adcore.o moc_adcore.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/adcore.cpp b/adcore.cpp new file mode 100644 index 0000000..b222f8f --- /dev/null +++ b/adcore.cpp @@ -0,0 +1,20 @@ +#include "adcore.h" + +adCore::adCore(QObject *parent) : + QThread(parent) +{ + step = 0; + admap = new Map(1,QSize(100,100)); + addata = new Game_Data(admap); + adaliens = new Aliens(addata); + adtowers = new Towers(addata); + adsplashes = new Splashes(addata); +} + +void adCore::next() +{ + adtowers->update(); + adsplashes->update(); + adaliens->update(); + step++; +} diff --git a/adcore.h b/adcore.h new file mode 100644 index 0000000..466e7b0 --- /dev/null +++ b/adcore.h @@ -0,0 +1,30 @@ +#ifndef ADCORE_H +#define ADCORE_H + +#include +#include + +#include "aliens.h" +#include "towers.h" +#include "splashes.h" + +class adCore : public QThread +{ +Q_OBJECT +public: + explicit adCore(QObject *parent = 0); + +signals: + +public slots: + void next(); +private: + Map *admap; + Game_Data *addata; + Aliens *adaliens; + Towers *adtowers; + Splashes *adsplashes; + int step; +}; + +#endif // ADCORE_H diff --git a/alien.cpp b/alien.cpp deleted file mode 100644 index 564a6dc..0000000 --- a/alien.cpp +++ /dev/null @@ -1,300 +0,0 @@ -#include "alien.h" - -#include - -Alien::Alien(games *parent, float alienspeed) -{ - game = parent; - Speed = alienspeed; - TmpCells = new int*[game->size.width()]; - for (int i = 0; i < game->size.width(); i++) - TmpCells[i] = new int[game->size.height()]; - position = game->start*game->cellsize; - path.clear(); - PicIndex = 0; - RecreatePath(); -} - - -bool Alien::RecreatePath() -{ - for (int i = 0; i < game->size.width(); i++) - { - for (int j = 0; j < game->size.height(); j++) - { - if (game->Cells[i][j] < 0 ) TmpCells[i][j] = -1; - else TmpCells[i][j] = 0; - } - } - QPointF tp; - QPoint start; - QVector srcPath; - QVector tmpPath; - PathIndex = 1; - start.setX(qRound(position.x()/(float)game->cellsize)); - start.setY(qRound(position.y()/(float)game->cellsize)); - if (game->Cells[start.x()][start.y()] < 0) return false; - srcPath = InvWaveTrace(game->finish,WaveTrace(start,game->finish)); - for (int i=0; iCells[srcPath.at(i).x()][srcPath.at(i).y()] = 5; - tmpPath.push_back(QPointF(srcPath.at(i))); - } - srcPath.clear(); - //qDebug() << tmpPath.size(); - if (!tmpPath.isEmpty()) - { - for (int j=0; j<4; j++) - { - path.clear(); - tp = tmpPath.at(0); - path.push_back(tp); - for (int i = 0; i < tmpPath.size() - 1; i++) - { - //if (j > 1) path.push_back(tmpPath[i]); - 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); - } - tp = tmpPath.at(tmpPath.size() - 1); - path.push_back(tp); - tmpPath = path; - } - tmpPath.clear(); - if (path.size() > 10) - { - path.remove(1); - path.remove(1); - path.remove(path.size()-2); - path.remove(path.size()-2); - } - return true; - } - return false; -} - - -bool Alien::update() -{ - float tmpdx,tmpdy,angl,arctg = 0; - tmpdx = position.x() - path.at(PathIndex).x()*game->cellsize; - tmpdy = position.y() - path.at(PathIndex).y()*game->cellsize; - while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*Speed*game->cellsize) - { - PathIndex++; - if (PathIndex >= path.size()) return false; - /*{ - 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"; - } - arctg = std::atan(tmpdx/tmpdy); - if (tmpdy < 0) arctg=arctg+3.1416f; - angl = 180.0f*(-arctg)/3.1416f; - /*if (PathIndex > 1) - { - 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; - position.setX(position.x() - -Speed*(float)game->cellsize*std::sin(arctg)); - position.setY(position.y() - -Speed*(float)game->cellsize*std::cos(arctg)); - PicIndex++; - return true; -} - - -int Alien::WaveTrace(QPoint start, QPoint finish) -{ - bool stop = false; - int step = 2; - QPoint cp, tp; - QRect fr(0, 0, game->size.width(), game->size.height()); - QVector tmpp, curp; - cp = start; - curp.push_back(cp); - TmpCells[cp.x()][cp.y()] = 1; - //qDebug() << "trace"; - while (!stop) { - tmpp = curp; - curp.clear(); - stop = true; - for (int i = 0; i < tmpp.size(); i++) { - cp = tmpp.at(i); - if (cp == finish) { - TmpCells[cp.x()][cp.y()] = step; - //qDebug() << "trace done!"; - return step; - } - tp.setX(cp.x() - 1); - tp.setY(cp.y()); - if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) { - TmpCells[tp.x()][tp.y()] = step; - curp.push_back(tp); - stop = false; - } - tp.setX(cp.x() + 1); - if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) { - TmpCells[tp.x()][tp.y()] = step; - curp.push_back(tp); - stop = false; - } - tp.setX(cp.x()); - tp.setY(cp.y() - 1); - if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) { - TmpCells[tp.x()][tp.y()] = step; - curp.push_back(tp); - stop = false; - } - tp.setY(cp.y() + 1); - if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) { - TmpCells[tp.x()][tp.y()] = step; - curp.push_back(tp); - stop = false; - } - } - step++; - } - //qDebug() << "trace false"; - return -1; -} - - -QVector Alien::InvWaveTrace(QPoint finish, int cnt) -{ - QPoint wp, Ppnt; - QVector alpath; - if (cnt < 2) return alpath; - int Ind, c, xpp, ypp, xnn, ynn; - unsigned char chk; - Ppnt = wp = finish; - xnn=0; - xpp=0; - ynn=0; - ypp=0; - cnt--; - alpath.push_front(Ppnt); - while (cnt > 1) - { - cnt--; - chk = 0; - Ind = 0; - c = 0; - if (wp.x() - 1 >= 0 && TmpCells[wp.x()-1][wp.y()] == cnt) - { - chk = chk | 0x01; - c++; - } - if (wp.x() + 1 < game->size.width() && TmpCells[wp.x()+1][wp.y()] == cnt) - { - chk = chk | 0x02; - c++; - } - if (wp.y() - 1 >= 0 && TmpCells[wp.x()][wp.y()-1] == cnt) - { - chk = chk | 0x04; - c++; - } - if (wp.y() + 1 < game->size.height() && TmpCells[wp.x()][wp.y()+1] == cnt) - { - chk = chk | 0x08; - c++; - } - if (c == 0 || chk == 0) qDebug() << "ERROR!!!"; - if (c > 1) - { - if ((chk & 0x01)==0x01 && (chk & 0x04)==0x04) - { - if (xnn <= ynn && Ind == 0){ - wp.rx()--; - xnn++; - if (xnn == ynn) xnn++; - Ind = 1; - } else if (Ind == 0) { - wp.ry()--; - ynn++; - ynn++; - Ind = 1; - } - } - if ((chk & 0x02)==0x02 && (chk & 0x04)==0x04) - { - if (xpp <= ynn && Ind == 0){ - wp.rx()++; - xpp++; - if (xpp == ynn) xpp++; - Ind = 1; - } else if (Ind == 0) { - wp.ry()--; - ynn++; - ynn++; - Ind = 1; - } - } - if ((chk & 0x01)==0x01 && (chk & 0x08)==0x08) - { - if (xnn <= ypp && Ind == 0){ - wp.rx()--; - xnn++; - if (xnn == ypp) xnn++; - Ind = 1; - } else if (Ind == 0) { - wp.ry()++; - ypp++; - ypp++; - Ind = 1; - } - } - if ((chk & 0x02)==0x02 && (chk & 0x08)==0x08) - { - if (xpp <= ypp && Ind == 0){ - wp.rx()++; - xpp++; - if (xpp == ypp) xpp++; - Ind = 1; - } else if (Ind == 0) { - wp.ry()++; - ypp++; - ypp++; - Ind = 1; - } - } - } - if (c == 1 || Ind == 0) - { - xnn=0; - xpp=0; - ynn=0; - ypp=0; - if ((chk & 0x01)==0x01) { - wp.rx()--; - xnn++; - } - else if ((chk & 0x02)==0x02) { - wp.rx()++; - xpp++; - } - else if ((chk & 0x04)==0x04) { - wp.ry()--; - ynn++; - } - else if ((chk & 0x08)==0x08) { - wp.ry()++; - ypp++; - } - } - Ppnt = wp; - alpath.push_front(Ppnt); - } - return alpath; -} diff --git a/alien.h b/alien.h deleted file mode 100644 index 18c0084..0000000 --- a/alien.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef ALIEN_H -#define ALIEN_H - -#include "games.h" - -class Alien -{ -public: - Alien(games *parent, float alienspeed = 0.1); - bool RecreatePath(); - //bool testTrace() {return (WaveTrace(data->start,data->finish) > 0);} - void setPos(QPointF pos) {position = pos;} - bool update(); - void resetIndexPic() {PicIndex = 0;} - QPointF Pos() const {return position;} - float Angl() const {return angle;} - int indexPix() const {return PicIndex;} - QVector path; -private: - int ** TmpCells; - games *game; - QPointF position; - float angle; - //int PicType; - //int FlX; - //int FlY; - //int Armor; - //int Level; - //int Money; - int PathIndex; - int PicIndex; - //int PicIndl; - //int MaxFrame; - //float Health; - float Speed; - //float PicFrame; - //float PicI; - //float Regeneration; - - int WaveTrace(QPoint start, QPoint finish); - QVector InvWaveTrace(QPoint finish, int cnt); -}; - -#endif // ALIEN_H diff --git a/aliendefender.pro b/aliendefender.pro index a2b180b..069029b 100644 --- a/aliendefender.pro +++ b/aliendefender.pro @@ -1,26 +1,15 @@ -# ------------------------------------------------- -# Project created by QtCreator 2009-08-17T19:38:55 -# ------------------------------------------------- -QT += network \ - opengl -TARGET = aliendefender -TEMPLATE = app -SOURCES += main.cpp \ - mainwindow.cpp \ - aliens.cpp \ - udpsender.cpp \ - towers.cpp \ - map.cpp \ - games.cpp \ - alien.cpp -HEADERS += mainwindow.h \ - aliens.h \ - basestruct.h \ - udpsender.h \ - towers.h \ +HEADERS += base_types.h \ map.h \ - games.h \ - alien.h \ - uwidget.h -FORMS += mainwindow.ui + game_data.h \ + aliens.h \ + towers.h \ + splashes.h \ + adcore.h +SOURCES += map.cpp \ + game_data.cpp \ + aliens.cpp \ + towers.cpp \ + main.cpp \ + splashes.cpp \ + adcore.cpp RESOURCES += images.qrc diff --git a/aliendefender.pro.user b/aliendefender.pro.user index 25769a5..f344427 100644 --- a/aliendefender.pro.user +++ b/aliendefender.pro.user @@ -1,318 +1,241 @@ + + RunConfiguration0-BaseEnvironmentBase + 2 + RunConfiguration0-CommandLineArguments - + RunConfiguration0-ProFile - wavetrace.pro + aliendefender.pro RunConfiguration0-RunConfiguration.name - aliendefender + aliendefender RunConfiguration0-UseDyldImageSuffix - false + false RunConfiguration0-UseTerminal - false + false RunConfiguration0-UserEnvironmentChanges - + RunConfiguration0-UserSetName - true + false + + + RunConfiguration0-UserSetWorkingDirectory + false + + + RunConfiguration0-UserWorkingDirectory + RunConfiguration0-type - Qt4ProjectManager.Qt4RunConfiguration - - - RunConfiguration1-CommandLineArguments - - - - RunConfiguration1-ProFile - aliendefender.pro - - - RunConfiguration1-RunConfiguration.name - aliendefender - - - RunConfiguration1-UseDyldImageSuffix - false - - - RunConfiguration1-UseTerminal - false - - - RunConfiguration1-UserEnvironmentChanges - - - - RunConfiguration1-UserSetName - false - - - RunConfiguration1-type - Qt4ProjectManager.Qt4RunConfiguration + Qt4ProjectManager.Qt4RunConfiguration activeRunConfiguration - 1 + 0 activebuildconfiguration - Debug + Debug buildConfiguration-Debug - - Debug - 0 - 2 - - 2 - /home/andrey/documents/sm11/Alien Defender/ad + + Debug + 0 + 0 + 2 buildConfiguration-Release - - Release - 0 - 2 - - 0 + + Release + 0 + 0 buildconfiguration-Debug-buildstep0 - - Debug - - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-rwgGTf2llu,guid=47f9f0046990c9c4983a622a4b6c11df - DESKTOP_SESSION=gnome - DESKTOP_STARTUP_ID= - DISPLAY=:0.0 - GDMSESSION=gnome - GDM_KEYBOARD_LAYOUT=us - GDM_LANG=ru_RU.UTF-8 - GNOME_DESKTOP_SESSION_ID=this-is-deprecated - GNOME_KEYRING_SOCKET=/tmp/keyring-cqyv3T/socket - GTK_MODULES=canberra-gtk-module - GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2 - HOME=/home/andrey - LANG=ru_RU.UTF-8 - LANGUAGE= - LD_LIBRARY_PATH=/usr/lib/qtcreator: - LOGNAME=andrey - ORBIT_SOCKETDIR=/tmp/orbit-andrey - PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games - PWD=/home/andrey - QTDIR=/usr - SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1283,unix/buull-eeePC:/tmp/.ICE-unix/1283 - SHELL=/bin/bash - SPEECHD_PORT=7560 - SSH_AGENT_PID=1356 - SSH_AUTH_SOCK=/tmp/keyring-cqyv3T/socket.ssh - USER=andrey - USERNAME=andrey - XAUTHORITY=/var/run/gdm/auth-for-andrey-FKbzYa/database - XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ - XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1265373654.150132-179730100 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-p5HnkClUWv,guid=600e78a10ff64ffb1ced7c414c4c6498 + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=us + GDM_LANG=ru_RU.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-wgH6gj + GTK_MODULES=canberra-gtk-module + HOME=/home/andrey + LANG=ru_RU.UTF-8 + LD_LIBRARY_PATH=/usr/lib/qtcreator: + LOGNAME=andrey + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-andrey + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/andrey + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1203,unix/buull-eeePC:/tmp/.ICE-unix/1203 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1245 + SSH_AUTH_SOCK=/tmp/keyring-wgH6gj/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-MPPKxH/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1280074903.597291-1238668786 - - /home/andrey/projects/aliendefender/aliendefender.pro - -spec - /usr/share/qt4/mkspecs/linux-g++ - -r - CONFIG+=debug_and_release - -Wall - - /usr/bin/qmake-qt4 - false - /home/andrey/projects/aliendefender - - - -Wall + + /home/andrey/aliendefender/aliendefender.pro + -spec + linux-g++ + -r + CONFIG+=debug + /usr/bin/qmake-qt4 + false + /home/andrey/aliendefender buildconfiguration-Debug-buildstep1 - - Debug - - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-rwgGTf2llu,guid=47f9f0046990c9c4983a622a4b6c11df - DESKTOP_SESSION=gnome - DESKTOP_STARTUP_ID= - DISPLAY=:0.0 - GDMSESSION=gnome - GDM_KEYBOARD_LAYOUT=us - GDM_LANG=ru_RU.UTF-8 - GNOME_DESKTOP_SESSION_ID=this-is-deprecated - GNOME_KEYRING_SOCKET=/tmp/keyring-cqyv3T/socket - GTK_MODULES=canberra-gtk-module - GTK_RC_FILES=/etc/gtk/gtkrc:/home/andrey/.gtkrc-1.2-gnome2 - HOME=/home/andrey - LANG=ru_RU.UTF-8 - LANGUAGE= - LD_LIBRARY_PATH=/usr/lib/qtcreator: - LOGNAME=andrey - ORBIT_SOCKETDIR=/tmp/orbit-andrey - PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games - PWD=/home/andrey - QTDIR=/usr - SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1283,unix/buull-eeePC:/tmp/.ICE-unix/1283 - SHELL=/bin/bash - SPEECHD_PORT=7560 - SSH_AGENT_PID=1356 - SSH_AUTH_SOCK=/tmp/keyring-cqyv3T/socket.ssh - USER=andrey - USERNAME=andrey - XAUTHORITY=/var/run/gdm/auth-for-andrey-FKbzYa/database - XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ - XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1265373654.150132-179730100 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-p5HnkClUWv,guid=600e78a10ff64ffb1ced7c414c4c6498 + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=us + GDM_LANG=ru_RU.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-wgH6gj + GTK_MODULES=canberra-gtk-module + HOME=/home/andrey + LANG=ru_RU.UTF-8 + LD_LIBRARY_PATH=/usr/lib/qtcreator: + LOGNAME=andrey + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-andrey + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/andrey + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1203,unix/buull-eeePC:/tmp/.ICE-unix/1203 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1245 + SSH_AUTH_SOCK=/tmp/keyring-wgH6gj/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-MPPKxH/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1280074903.597291-1238668786 - false - - -j3 - -w - - /usr/bin/make - true - /home/andrey/projects/aliendefender - - -j3 + false + + -w + /usr/bin/make + true + /home/andrey/aliendefender buildconfiguration-Debug-cleanstep0 - - Debug - - ALLUSERSPROFILE=C:\Documents and Settings\All Users - APPDATA=C:\Documents and Settings\Andrey\Application Data - COMMONPROGRAMFILES=C:\Program Files\Common Files - COMPUTERNAME=COMP - COMSPEC=C:\WINDOWS\system32\cmd.exe - FP_NO_HOST_CHECK=NO - HOMEDRIVE=C: - HOMEPATH=\Documents and Settings\Andrey - INCLUDE=C:\Program Files\Microsoft Visual Studio\VC98\atl\include;C:\Program Files\Microsoft Visual Studio\VC98\mfc\include;C:\Program Files\Microsoft Visual Studio\VC98\include - LIB=C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib;C:\Program Files\Microsoft Visual Studio\VC98\lib - LOGONSERVER=\\COMP - MSDEVDIR=C:\Program Files\Microsoft Visual Studio\Common\MSDev98 - NUMBER_OF_PROCESSORS=2 - OS=Windows_NT - PATH=D:\Qt\2010.01\mingw\bin;D:\Qt\2010.01\qt\bin;C:\Program Files\PC Connectivity Solution\;C:\Program Files\JavaFX\javafx-sdk1.2\bin;C:\Program Files\JavaFX\javafx-sdk1.2\emulator\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\IVI Foundation\VISA\WinNT\Bin;C:\Program Files\Borland\Delphi7\Bin;C:\Program Files\Borland\Delphi7\Projects\Bpl;C:\Program Files\Git\cmd;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;C:\Program Files\OpenVPN\bin - PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH - PROCESSOR_ARCHITECTURE=x86 - PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel - PROCESSOR_LEVEL=6 - PROCESSOR_REVISION=1706 - PROGRAMFILES=C:\Program Files - QTDIR=D:/Qt/2010.01/qt - SESSIONNAME=Console - SYSTEMDRIVE=C: - SYSTEMROOT=C:\WINDOWS - TEMP=C:\DOCUME~1\Andrey\LOCALS~1\Temp - TMP=C:\DOCUME~1\Andrey\LOCALS~1\Temp - USERDOMAIN=COMP - USERNAME=Andrey - USERPROFILE=C:\Documents and Settings\Andrey - VS90COMNTOOLS=D:\Programming\Microsoft Visual Studio 9.0\Common7\Tools\ - VXIPNPPATH=C:\Program Files\IVI Foundation\VISA\ - WINDIR=C:\WINDOWS - - true - - clean - -w - - D:/Qt/2010.01/mingw/bin/mingw32-make.exe - true - C:/aliendefender - true - - clean + + Debug + true + + clean buildconfiguration-Release-buildstep0 - - Release - + + Release buildconfiguration-Release-buildstep1 - - Release + + Release buildconfiguration-Release-cleanstep0 - - Release + + Release buildconfigurations - - Debug - Release + + Debug + Release buildstep0 - - - + + + buildstep1 - - + + buildsteps - - trolltech.qt4projectmanager.qmake - trolltech.qt4projectmanager.make + + trolltech.qt4projectmanager.qmake + trolltech.qt4projectmanager.make cleanstep0 - - - true + + + true cleansteps - - trolltech.qt4projectmanager.make + + trolltech.qt4projectmanager.make defaultFileEncoding - UTF-8 + System project - + diff --git a/aliens.cpp b/aliens.cpp index 15c9eec..0ae0353 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -1,105 +1,13 @@ #include "aliens.h" -Aliens::Aliens(games *parent) +Aliens::Aliens(Game_Data *gamedata, QObject *parent) : + QObject(parent) { - game = parent; - int x = loadPixmaps(); - if (x > 0) qDebug() << "Found" << x << "alien pictures"; - else qDebug() << "ERROR alien pictures not found!!"; - testAlien = new Alien(game); + GameData = gamedata; } -bool Aliens::AddAlien() +void Aliens::update() { - curAliens.push_back(new Alien(game,0.2)); - return !curAliens.isEmpty(); -} - -/* -void Aliens::clearAliens() -{ - curAliens.clear(); -} -*/ - - -bool Aliens::retrace() -{ - for (int i = 0; i < game->size.width(); i++) - { - for (int j = 0; j < game->size.height(); j++) - { - if (game->Cells[i][j] == 5) game->Cells[i][j]=0; - } - } - if (!testAlien->RecreatePath()) return false; - for (int i=0; i < curAliens.size(); i ++) - if (!curAliens.at(i)->RecreatePath()) return false; - return true; -} - - -int Aliens::loadPixmaps() -{ - QString str; - QPixmap tmpAlPixmap; - int i=1; - str.setNum(i); - while (i != 0) { - str.setNum(i); - tmpAlPixmap.load(":/aliens/images/Aliens/Al_00_" + str + ".png"); - if (!tmpAlPixmap.isNull()) { - AlienPix.push_back(tmpAlPixmap); - tmpAlPixmap = 0; - i++; - } - else i = 0; - } - return AlienPix.size(); -} - - -void Aliens::drawAliens() -{ - int n=0; - while (n < curAliens.size()) - { - if (!curAliens.at(n)->update()) DelAlien(n); - else - { - if (curAliens.at(n)->indexPix() >= AlienPix.size()) - curAliens.at(n)->resetIndexPic(); - n++; - } - } - QPainter painter(game->buff); - QPen pen(QColor(80,200,100)); - QBrush brush(QColor(230,10,10),Qt::SolidPattern); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawPixmap(0,0,*game->background); - for (int i=0; i < curAliens.size(); i ++) - { - /*for (int j = 0; j < curAliens.at(i)->path.size(); j++) - painter.drawEllipse(curAliens.at(i)->path.at(j).x()*game->cellsize +4, - curAliens.at(i)->path.at(j).y()*game->cellsize +4, - game->cellsize - 8, - game->cellsize - 8);*/ - painter.save(); - painter.translate(curAliens.at(i)->Pos().x()+game->cellsize/2, - curAliens.at(i)->Pos().y()+game->cellsize/2); - painter.rotate(curAliens.at(i)->Angl()); - painter.drawPixmap(-game->cellsize, -game->cellsize, - game->cellsize*2, game->cellsize*2, - AlienPix[curAliens.at(i)->indexPix()]); - painter.restore(); - } - painter.end(); -} - - -void Aliens::DelAlien(int index) -{ - curAliens.remove(index); + } diff --git a/aliens.h b/aliens.h index f1f2818..1c433fa 100644 --- a/aliens.h +++ b/aliens.h @@ -1,27 +1,31 @@ #ifndef ALIENS_H #define ALIENS_H -#include "alien.h" +#include -class Aliens +#include "game_data.h" + + +class Aliens : public QObject { +Q_OBJECT public: - Aliens(games *parent); - bool AddAlien(); + explicit Aliens(Game_Data * gamedata, QObject *parent = 0); + void AddAlien(int srcId); + void DelAlienById(int Id); void DelAlien(int index); - void drawAliens(); - bool retrace(); - int size() const {return curAliens.size();} - //void clearAliens(); - Alien * alienAt(int index) const {return curAliens.at(index);} + void retrace(); + void nextWave(); + void update(); + int size() const {return GameData->curAliens.size();} +signals: + void AlienFinish(); +public slots: + //void getDamage(float dmg); private: - games * game; - Alien * testAlien; - QVector srcAliens; - QVector curAliens; - QVector AlienPix; - - int loadPixmaps(); + Game_Data * GameData; + QPointF globStart; + QPointF globFinish; }; #endif // ALIENS_H diff --git a/base_types.h b/base_types.h new file mode 100644 index 0000000..e586c15 --- /dev/null +++ b/base_types.h @@ -0,0 +1,55 @@ +#ifndef BASE_TYPES_H +#define BASE_TYPES_H + +#include +#include + +struct Alien +{ + int Id; + int type; + QPointF pos; + float angle; // -180 .. 180 + float speed; // cells per thick (speed=1 is 60cells by 1 sec for 60fps e.g.) + float health; + QPoint finish; + QVector path; + unsigned int gold; +}; + + +struct Tower +{ + int Id; + int type; + int AlienId; // aim alien + QPoint pos; // not QPointF because tower fixed on grid + float angle; // -180 .. 180 + float range; + float speed; // shots per thick (e.g. speed=1 is 60 shots by 1sec for 60fps e.g. ) +}; + + +struct Splash +{ + int Id; + int type; + int TowerId; // parent tower + int AlienId; // aim alien (different from tower.AlienId) + int lifetime; // in msec + float radius; + QPointF pos; +}; + + +struct wave +{ + int Id; + QVector types; // some types of aliens (e.g. 2 fly and 3 grount in one wave) + QVector counts; // count aliens of each type + int wait_time; // time in sec + unsigned int gold; +}; + + +#endif // BASE_TYPES_H diff --git a/basestruct.h b/basestruct.h deleted file mode 100644 index 46c3867..0000000 --- a/basestruct.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef BASESTRUCT_H -#define BASESTRUCT_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* -struct FPVector -{ - QPointF pnt; - float angle; -}; -*/ - -/* -struct GameData -{ - QSize size; - QPoint start; - QPoint finish; - QPixmap * buff; - int cellsize; - int ** Cells; -}; -*/ - -/*struct Effect -{ - float Health; - float Speed; - int Armor; - int CntHealth; - int CntSpeed; - int CntArmor; -};*/ - - - - -struct Tower -{ - //unsigned char TName[64]; - //Rectangle Position; - //float angle; - //int flx; - //int fly; - QPoint Center; - //Point FirePnt; - //int BaseType; - //int Damage; - //float Radius; - //float DamageRadius; - //float FireSpeed; - //float DPS; - //int Level; - //int Cost; - //int UpgradeCost; - //int Aim; - //int FireCnt; - //Effect Effects; -}; - -/* -struct Splash -{ - FPVector Position; - int flx; - int fly; - Point DestPnt; - int DestAlien; - int BaseType; - int Damage; - float DamageRadius; - float Speed; - Effect Effects; - int PicInd; - float PicFrame; - int MaxFrame; -}; - -*/ -#endif // BASESTRUCT_H diff --git a/debug/aliendefender.exe b/debug/aliendefender.exe deleted file mode 100644 index 5e6cc80..0000000 Binary files a/debug/aliendefender.exe and /dev/null differ diff --git a/game_data.cpp b/game_data.cpp new file mode 100644 index 0000000..596b9e8 --- /dev/null +++ b/game_data.cpp @@ -0,0 +1,7 @@ +#include "game_data.h" + +Game_Data::Game_Data(Map *mapp, QObject *parent) : + QObject(parent) +{ + map = mapp; +} diff --git a/game_data.h b/game_data.h new file mode 100644 index 0000000..d8e44e1 --- /dev/null +++ b/game_data.h @@ -0,0 +1,30 @@ +#ifndef GAME_DATA_H +#define GAME_DATA_H + +#include + +#include "map.h" + +class Game_Data : public QObject +{ +Q_OBJECT +public: + explicit Game_Data(Map * map, QObject *parent = 0); + QVector srcAliens; + QVector curAliens; + QVector srcTowers; + QVector curTowers; + QVector srcSplashes; + QVector curSplashes; + QVector waves; + Map * map; + unsigned long int adMoney; + int selectAlienId; + int curWave; +signals: + +public slots: + +}; + +#endif // GAME_DATA_H diff --git a/games.cpp b/games.cpp deleted file mode 100644 index d4659b3..0000000 --- a/games.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#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; - } - Cells[start.x()][start.y()] = 10; - Cells[finish.x()][finish.y()] = 10; - qDebug() << start << finish; -} diff --git a/games.h b/games.h deleted file mode 100644 index ed84a5e..0000000 --- a/games.h +++ /dev/null @@ -1,19 +0,0 @@ -#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 diff --git a/main.cpp b/main.cpp index a348a41..b9fbe58 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,11 @@ +#include #include -#include "mainwindow.h" + +#include "adcore.h" int main(int argc, char *argv[]) { - QApplication a(argc, argv); - MainWindow w; - w.show(); - w.resize(666,444); - return a.exec(); + adCore core; + QApplication a(argc, argv); + return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp deleted file mode 100644 index 6940758..0000000 --- a/mainwindow.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), ui(new Ui::MainWindow) -{ - qDebug() << "Load START!"; - ui->setupUi(this); - wd = new USWidget(ui->frGame); - //ui->frGame->addWidget(wd); - wd->resize(ui->frGame->size()); - connect(wd,SIGNAL(paintEvent(QPaintEvent*)),this,SLOT(paint(QPaintEvent*))); - connect(wd,SIGNAL(mouseMoveEvent(QMouseEvent*)), - this,SLOT(mouse_move(QMouseEvent*))); - connect(wd,SIGNAL(mousePressEvent(QMouseEvent*)), - this,SLOT(mouse_press(QMouseEvent*))); - //sndr = new UdpSender("127.0.0.1",10101); - //sndr->connectSend("hellow"); - int cellsize = 16; - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(ADrender())); - qDebug() << wd->size(); - GameMain = new games(wd->size(),QPoint(0,wd->height()/2), - QPoint(wd->width()-cellsize,wd->height()/2), - cellsize); - maliens = new Aliens(GameMain); - maliens->AddAlien(); - mmap = new map(GameMain); - mmap->clear(); - mmap->drawgrid(); - mtowers = new towers(GameMain); - //this->setGeometry(100,100,this->width(),this->height()); - timer->start(50); - mousebt = 0; - qDebug() << "Load DONE!"; -} - - -void MainWindow::resizeEvent(QResizeEvent *) -{ - int cellsize = 16; - wd->resize(ui->frGame->size()); - delete mtowers; - delete mmap; - delete maliens; - delete GameMain; - GameMain = new games(wd->size(),QPoint(0,wd->height()/2), - QPoint(wd->width()-cellsize,wd->height()/2), - cellsize); - maliens = new Aliens(GameMain); - maliens->AddAlien(); - mmap = new map(GameMain); - mmap->clear(); - mmap->drawgrid(); - mtowers = new towers(GameMain); -} - - -void MainWindow::ADrender() -{ - QString str; - maliens->drawAliens(); - str.setNum(maliens->size()); - ui->lbCount->setText(QString::fromUtf8("Количество: ")+str+QString::fromUtf8(" шт")); - wd->repaint(); -} - - -void MainWindow::paint(QPaintEvent* ) -{ - QPainter painter; - painter.begin(wd); - painter.drawPixmap(0,0,*GameMain->buff); - painter.end(); -} - - -void MainWindow::mouse_move(QMouseEvent *event) -{ - if (mousebt == 1) ClearCell(event->pos()); - if (mousebt == 2) SetCell(event->pos()); -} - - -void MainWindow::mouse_press(QMouseEvent *event) -{ - if (event->button() == Qt::RightButton) { - ClearCell(event->pos()); - mousebt = 1; - return; - } - if(event->button() == Qt::LeftButton) { - SetCell(event->pos()); - mousebt = 2; - return; - } - mousebt = 0; -} - - -void MainWindow::SetCell(QPoint pos) -{ - bool trace = false; - QPoint cp; - QRect wdrect(0, 0, (wd->width()/GameMain->cellsize)*GameMain->cellsize, - (wd->height()/GameMain->cellsize)*GameMain->cellsize); - if (wdrect.contains(pos)) { - cp.setX(pos.x()/GameMain->cellsize); - cp.setY(pos.y()/GameMain->cellsize); - //qDebug() << cp << GameMain->Cells[cp.x()][cp.y()]; - if (GameMain->Cells[cp.x()][cp.y()] == 10) return; - mtowers->drawcell(cp); - if (GameMain->Cells[cp.x()][cp.y()] == 5) trace = true; - GameMain->Cells[cp.x()][cp.y()] = - 1; - if (trace) - if (!maliens->retrace()) ClearCell(pos); - } -} - - -void MainWindow::ClearCell(QPoint pos) -{ - QPoint cp; - QRect wdrect(0, 0, (wd->width()/GameMain->cellsize)*GameMain->cellsize, - (wd->height()/GameMain->cellsize)*GameMain->cellsize); - if (wdrect.contains(pos)) { - cp.setX(pos.x()/GameMain->cellsize); - cp.setY(pos.y()/GameMain->cellsize); - if (GameMain->Cells[cp.x()][cp.y()] == 10) return; - GameMain->Cells[cp.x()][cp.y()] = 0; - mtowers->clearcell(cp); - maliens->retrace(); - } -} - - -void MainWindow::keyPressEvent(QKeyEvent * e) -{ - //qDebug() << e->key(); - switch(e->key()) { - case 65: - maliens->AddAlien(); - break; - case 68: - if (maliens->size() > 0) maliens->DelAlien(maliens->size()-1); - break; - } -} - - -MainWindow::~MainWindow() -{ - delete ui; - delete mtowers; - delete mmap; - delete maliens; - delete GameMain; -} - -void MainWindow::on_pushButton_clicked() -{ - this->close(); -} - -void MainWindow::on_pushButton_3_clicked() -{ - if (maliens->size() > 0) maliens->DelAlien(maliens->size()-1); -} - -void MainWindow::on_pushButton_2_clicked() -{ - maliens->AddAlien(); -} diff --git a/mainwindow.h b/mainwindow.h deleted file mode 100644 index 80ba847..0000000 --- a/mainwindow.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include -#include -#include "aliens.h" -#include "map.h" -#include "towers.h" -#include "udpsender.h" -#include "uwidget.h" - -namespace Ui -{ - class MainWindow; -} - - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); -public slots: - void ADrender(); - void paint(QPaintEvent*); - void mouse_move(QMouseEvent *e); - void mouse_press(QMouseEvent *e); -private: - void SetCell(QPoint pos); - void ClearCell(QPoint pos); - void resizeEvent(QResizeEvent *); - void keyPressEvent(QKeyEvent *e); - Ui::MainWindow *ui; - Aliens * maliens; - map * mmap; - towers * mtowers; - USWidget * wd; - //UdpSender * sndr; - games * GameMain; - QTimer *timer; - int mousebt; - -private slots: - void on_pushButton_2_clicked(); - void on_pushButton_3_clicked(); - void on_pushButton_clicked(); -}; - - -#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui deleted file mode 100644 index 18da8e5..0000000 --- a/mainwindow.ui +++ /dev/null @@ -1,90 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 400 - - - - - 0 - 0 - - - - - 800 - 400 - - - - - 800 - 400 - - - - MainWindow - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - - - - - - - Добавить - - - - - - - Удалить - - - - - - - TextLabel - - - - - - - Выход - - - - - - - - - - - - diff --git a/map.cpp b/map.cpp index c5e1534..27e9458 100644 --- a/map.cpp +++ b/map.cpp @@ -1,31 +1,7 @@ #include "map.h" - -map::map(games *parent) +Map::Map(int Id, QSize size, QObject *parent) : + QObject(parent) { - game = parent; -} - - -void map::clear() -{ - QPainter painter(game->background); - QPen pen(QColor(150,150,150)); - painter.setPen(pen); - painter.fillRect(game->background->rect(),QColor(150,150,150)); - painter.end(); -} - - -void map::drawgrid() -{ - int i; - QPainter painter(game->background); - QPen pen(QColor(100,100,100)); - painter.setPen(pen); - for (i = 0; i < game->background->width()/game->cellsize; i++) - painter.drawLine(i*game->cellsize,0,i*game->cellsize,game->background->height()); - for (i = 0; i < game->background->height()/game->cellsize; i++) - painter.drawLine(0,i*game->cellsize,game->background->width(),i*game->cellsize); - painter.end(); + mapId=Id; } diff --git a/map.h b/map.h index 90a63b5..ad6a07c 100644 --- a/map.h +++ b/map.h @@ -1,16 +1,30 @@ #ifndef MAP_H #define MAP_H -#include "games.h" +#include +#include +#include +#include -class map +#include "base_types.h" + + +class Map : public QObject { +Q_OBJECT public: - map(games *parent); - void clear(); - void drawgrid(); + explicit Map(int Id, QSize size, QObject *parent = 0); + int Id() const {return mapId;} + int addTowerOnMap(); + int delTowerOnMap(); + QVector CreatePath(QPoint start, QPoint finish); +signals: + void RecreateAlienPath(); +public slots: + private: - games * game; + int **Cells; + int mapId; }; #endif // MAP_H diff --git a/object_script.aliendefender.Debug b/object_script.aliendefender.Debug deleted file mode 100644 index 73bf06f..0000000 --- a/object_script.aliendefender.Debug +++ /dev/null @@ -1,14 +0,0 @@ -INPUT( -./debug\main.o -./debug\mainwindow.o -./debug\adpainter.o -./debug\aliens.o -./debug\udpsender.o -./debug\towers.o -./debug\map.o -./debug\games.o -./debug\alien.o -./debug\moc_mainwindow.o -./debug\moc_udpsender.o -./debug\qrc_images.o -); diff --git a/object_script.aliendefender.Release b/object_script.aliendefender.Release deleted file mode 100644 index 650130c..0000000 --- a/object_script.aliendefender.Release +++ /dev/null @@ -1,14 +0,0 @@ -INPUT( -./release\main.o -./release\mainwindow.o -./release\adpainter.o -./release\aliens.o -./release\udpsender.o -./release\towers.o -./release\map.o -./release\games.o -./release\alien.o -./release\moc_mainwindow.o -./release\moc_udpsender.o -./release\qrc_images.o -); diff --git a/release/adpainter.o b/release/adpainter.o deleted file mode 100644 index 79c0eb9..0000000 Binary files a/release/adpainter.o and /dev/null differ diff --git a/splashes.cpp b/splashes.cpp new file mode 100644 index 0000000..7931c61 --- /dev/null +++ b/splashes.cpp @@ -0,0 +1,13 @@ +#include "splashes.h" + +Splashes::Splashes(Game_Data *gamedata, QObject *parent) : + QObject(parent) +{ + GameData = gamedata; +} + + +void Splashes::update() +{ + +} diff --git a/splashes.h b/splashes.h new file mode 100644 index 0000000..b24a2e3 --- /dev/null +++ b/splashes.h @@ -0,0 +1,27 @@ +#ifndef SPLASHES_H +#define SPLASHES_H + +#include + +#include "game_data.h" + +class Splashes : public QObject +{ +Q_OBJECT +public: + explicit Splashes(Game_Data * gamedata, QObject *parent = 0); + void AddSplash(int srcId); + void DelSplashById(int Id); + void DelSplash(int index); + void update(); + int size() const {return GameData->curSplashes.size();} + +signals: + +public slots: + +private: + Game_Data *GameData; +}; + +#endif // SPLASHES_H diff --git a/towers.cpp b/towers.cpp index d523b7c..d2212a0 100644 --- a/towers.cpp +++ b/towers.cpp @@ -1,37 +1,13 @@ #include "towers.h" -towers::towers(games *parent) +Towers::Towers(Game_Data *gamedata, QObject *parent) : + QObject(parent) { - game = parent; + GameData = gamedata; } -void towers::drawcell(QPoint pnt) -{ - QPainter painter(game->background); - QPen pen(QColor(0,0,0)); - QBrush brush(QColor(0,0,0),Qt::SolidPattern); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawRect(pnt.x()*game->cellsize+1,pnt.y()*game->cellsize+1,game->cellsize - 2, game->cellsize - 2); - painter.end(); -} - - -void towers::clearcell(QPoint pnt) -{ - QPainter painter(game->background); - QPen pen(QColor::fromRgb(qRgb(150,150,150))); - QBrush brush(QColor(150,150,150),Qt::SolidPattern); - painter.setPen(pen); - painter.setBrush(brush); - painter.drawRect(pnt.x()*game->cellsize+1,pnt.y()*game->cellsize+1,game->cellsize - 2, game->cellsize - 2); - painter.end(); -} - -/* -void towers::AddTower(QPoint point, int type) +void Towers::update() { } -*/ diff --git a/towers.h b/towers.h index 50770c9..a85e71c 100644 --- a/towers.h +++ b/towers.h @@ -1,19 +1,26 @@ #ifndef TOWERS_H #define TOWERS_H -#include "games.h" +#include -class towers +#include "game_data.h" + +class Towers : public QObject { +Q_OBJECT public: - towers(games *parent); - //QVector srcTowers; - //QVector curTowers; - //void AddTower(QPoint point, int type); - void drawcell(QPoint pnt); - void clearcell(QPoint pnt); + explicit Towers(Game_Data * gamedata, QObject *parent = 0); + void AddTower(int srcId); + void DelTowerById(int Id); + void DelTower(int index); + void update(); + int size() const {return GameData->curTowers.size();} +signals: + //void Shot(); +public slots: + private: - games * game; + Game_Data * GameData; }; #endif // TOWERS_H diff --git a/udpsender.cpp b/udpsender.cpp deleted file mode 100644 index 5c5bd48..0000000 --- a/udpsender.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#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; - qDebug() << "Received data: " << s; - //for (int i = 0; i < s.length(); i++) cout << s[i].toAscii(); - //cout << endl; - //qDebug() << sock->write(recstr.toUtf8()); - qDebug() << sock->socketDescriptor(); - emit dataResieved(recdata); -} - - -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 deleted file mode 100644 index 4f7ad95..0000000 --- a/udpsender.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -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; - signals: - void dataResieved(QByteArray * data); -}; diff --git a/uwidget.h b/uwidget.h deleted file mode 100755 index b819696..0000000 --- a/uwidget.h +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -class UGLWidget: public QGLWidget { - Q_OBJECT -public: - UGLWidget(QWidget * parent = 0): QGLWidget(parent) {setGeometry(0, 0, 0, 0);} -signals: - void closeEvent(QCloseEvent * e); - void dragEnterEvent(QDragEnterEvent * e); - void dragLeaveEvent(QDragLeaveEvent * e); - void dragMoveEvent(QDragMoveEvent * e); - void dropEvent(QDropEvent * e); - void enterEvent(QEvent * e); - void hideEvent(QHideEvent * e); - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void leaveEvent(QEvent * e); - void mouseDoubleClickEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mousePressEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void moveEvent(QMoveEvent * e); - void glDraw(); - void paintGL(); - void resizeEvent(QResizeEvent * e); - void showEvent(QShowEvent * e); - void wheelEvent(QWheelEvent * e); - void paintEvent(QPaintEvent * e); -}; - - -class USWidget: public QWidget { - Q_OBJECT -public: - USWidget(QWidget * parent = 0): QWidget(parent) {setGeometry(0, 0, 0, 0);} -signals: - void closeEvent(QCloseEvent * e); - void dragEnterEvent(QDragEnterEvent * e); - void dragLeaveEvent(QDragLeaveEvent * e); - void dragMoveEvent(QDragMoveEvent * e); - void dropEvent(QDropEvent * e); - void enterEvent(QEvent * e); - void hideEvent(QHideEvent * e); - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void leaveEvent(QEvent * e); - void mouseDoubleClickEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mousePressEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void moveEvent(QMoveEvent * e); - void resizeEvent(QResizeEvent * e); - void showEvent(QShowEvent * e); - void wheelEvent(QWheelEvent * e); - void paintEvent(QPaintEvent * e); -};