From: cboissie Date: Thu, 19 May 2011 00:42:06 +0000 (+0200) Subject: New version with turret test, moving insect and 8 direction tiles X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=32f4baf8128752547021d1e14ece916aefc5980f;p=Bug_Attack.git New version with turret test, moving insect and 8 direction tiles --- diff --git a/Bug_Attack.pro b/Bug_Attack.pro index 0253ae5..afff092 100644 --- a/Bug_Attack.pro +++ b/Bug_Attack.pro @@ -13,10 +13,21 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ tile.cpp \ - map.cpp + map.cpp \ + entity.cpp \ + monster.cpp \ + cafard.cpp \ + defenser.cpp \ + watergun.cpp HEADERS += mainwindow.h \ tile.h \ - map.h + map.h \ + entity.h \ + monster.h \ + cafard.h \ + types.h \ + defenser.h \ + watergun.h FORMS += mainwindow.ui diff --git a/cafard.cpp b/cafard.cpp new file mode 100644 index 0000000..2d35fc7 --- /dev/null +++ b/cafard.cpp @@ -0,0 +1,53 @@ +#include "cafard.h" +#include +using namespace TYPE; + +Cafard::Cafard(Map* map, int posx,int posy, int size):Monster(posx,posy,size),_map(map) +{ + // Données du cafard + _type = T_RAMPANT; + _hp = 10*size*size; + _resistance = 5*size*size; + _speed = 2; + + // Images et animations + for(int i = 0; i < 3; ++i) { + QPixmap* animTemp = new QPixmap("./media/textures/ennemies/cafard" + QString::number(i+1) + ".png"); + *animTemp = animTemp->scaled(size*32,size*32); + _animPixmap.push_back(animTemp); + } + _animState = 0; // Première frame de l'animation à 0 + + // Image et taille + this->setPixmap(*_animPixmap.first()); + + // Position + this->setPos(_x,_y); +} + +void Cafard::advance(int phase) { + + // Si 'phase' vaut 0, rien ne se passe + if(!phase) + return; + // ...sinon, on met à jour l'item + + // Met à jour l'image de l'animation + this->setPixmap(*_animPixmap[_animState]); + this->increaseAnimationStep(); + + // Déplace l'ennemi selon sa vitesse et la direction induite par le terrain + Tile& currentTile = _map->getTileAt((_x+16)/32,(_y+16)/32); + QVector2D dirVect = currentTile.getDirection(); + + _x += _speed*dirVect.x(); + _y += _speed*dirVect.y(); + + this->setPos(_x,_y); + + // Oriente l'image dans le bon sens + // (nb : transformation par rapport au centre de l'image) + this->setTransformOriginPoint(this->boundingRect().center().x(),this->boundingRect().center().y()); + this->setRotation(dirVect.y()*90); + +} diff --git a/cafard.h b/cafard.h new file mode 100644 index 0000000..cddfa18 --- /dev/null +++ b/cafard.h @@ -0,0 +1,21 @@ +#ifndef CAFARD_H +#define CAFARD_H + +#include "entity.h" +#include "monster.h" +#include "map.h" + +class Map; + +class Cafard : public Monster +{ +public: + Cafard(Map* map,int posx,int posy, int size); + +protected: + void advance(int phase); + + Map* _map; +}; + +#endif // CAFARD_H diff --git a/defenser.cpp b/defenser.cpp new file mode 100644 index 0000000..6b98369 --- /dev/null +++ b/defenser.cpp @@ -0,0 +1,4 @@ +#include "defenser.h" + +Defenser::Defenser(int posx,int posy,int level,TYPE::ENTITY target) + :Entity(posx,posy),_level(level),_target(target) {} diff --git a/defenser.h b/defenser.h new file mode 100644 index 0000000..e40434b --- /dev/null +++ b/defenser.h @@ -0,0 +1,21 @@ +#ifndef DEFENSER_H +#define DEFENSER_H + +#include "entity.h" + +class Defenser : public Entity +{ +public: + Defenser(int posx,int posy,int level,TYPE::ENTITY target); + + virtual int getCost(void) const = 0; + +protected: + int _level; + TYPE::ENTITY _target; + int _rate; + int _range; + int _power; +}; + +#endif // DEFENSER_H diff --git a/entity.cpp b/entity.cpp new file mode 100644 index 0000000..abdbfc5 --- /dev/null +++ b/entity.cpp @@ -0,0 +1,16 @@ +#include "entity.h" + +Entity::Entity(int posX, int posY): _x(posX),_y(posY) { +} + +int Entity::getX(void) const { return _x; } +int Entity::getY(void) const { return _y; } + +void Entity::increaseAnimationStep(void) { + + // Avance à la frame suivante de l'animation + _animState++; + if(_animState >= _animPixmap.size()) + _animState = 0; + +} diff --git a/entity.h b/entity.h new file mode 100644 index 0000000..4485e60 --- /dev/null +++ b/entity.h @@ -0,0 +1,38 @@ +#ifndef ENTITY_H +#define ENTITY_H + +#include +#include +#include + +#include "types.h" + +class Entity : public QGraphicsPixmapItem // , public QObject +{ + + // Q_OBJECT // Utilisé pour les signaux/slots + +public: + + Entity(int posX, int posY); + void increaseAnimationStep(void); + int getX() const; + int getY() const; + + + +protected: + + virtual void advance(int phase) = 0; + + QList _animPixmap; + int _x; + int _y; + int _animState; // Frame courante de l'animation + TYPE::ENTITY _type; + + +}; + +#endif // ENTITY_H + diff --git a/mainwindow.cpp b/mainwindow.cpp index 91d14cf..1ee5d9f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,18 +8,27 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + /// Test : try to draw some tiles into the QGraphicView - _scene = new QGraphicsScene(parent); + _sceneMap = new Map(parent); _view = ui->graphicsView; - _view->setScene(_scene); - - _currentMap = new Map(_scene); - _currentMap->LoadBackground(); + _view->setScene(_sceneMap); + _view->setRenderHint(QPainter::Antialiasing); + _view->setCacheMode(QGraphicsView::CacheBackground); + _view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); _view->show(); + + // Lancement du timer (boucle principale du jeu) + QObject::connect(&timer, SIGNAL(timeout()), _sceneMap, SLOT(advance())); + timer.start(1000 / 20); // 10 FPS + + } + MainWindow::~MainWindow() { delete ui; diff --git a/mainwindow.h b/mainwindow.h index cd2ed0c..5da4844 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,10 +2,13 @@ #define MAINWINDOW_H #include -#include +#include "map.h" #include #include +#include +#include + #include "map.h" namespace Ui { @@ -24,10 +27,9 @@ private: Ui::MainWindow *ui; - QGraphicsScene *_scene; QGraphicsView *_view; - - Map *_currentMap; + QTimer timer; + Map* _sceneMap; }; diff --git a/mainwindow.ui b/mainwindow.ui index 9d1d5c9..1c681f6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -199,6 +199,9 @@ Qt::ScrollBarAlwaysOff + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + diff --git a/map.cpp b/map.cpp index f8a872b..8a5a5da 100644 --- a/map.cpp +++ b/map.cpp @@ -4,19 +4,12 @@ -Map::Map(QGraphicsScene* scene) +Map::Map(QObject *parent):QGraphicsScene(parent) { - - // Container - _scene = scene; - - /* // Loads map file + /* // Loads map file QFile mapFile("media/maps/map.txt"); if(!mapFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; - - - // Reads map data and creates corresponding map tiles int y = 0; while(!mapFile.atEnd()){ @@ -26,7 +19,6 @@ Map::Map(QGraphicsScene* scene) _mapTiles[x][y] = new Tile(tileNumber[x].toInt()); y++; } - // Close file mapFile.close();*/ @@ -40,24 +32,37 @@ Map::Map(QGraphicsScene* scene) for(j = 0; j < 16; j++) { fichier >> num; - std::cout << num << std::endl; - _mapTiles[i][j] = new Tile(num); + _mapTiles[j][i] = new Tile(num, j, i); + this->addItem(_mapTiles[j][i]); } } } -} + fichier.close(); -void Map::LoadBackground(void) { + _entities.push_front(new Cafard(this,32*2,0,1)); + this->addItem(_entities.first()); - for(int x = 0 ; x < 16 ; ++x){ - for(int y = 0 ; y < 16 ; ++y){ - _mapTiles[x][y]->setPos(y*32,x*32); - _scene->addItem(_mapTiles[x][y]); - } - } } -Map::~Map(){ +// Gestion du clic de la souris +void Map::mousePressEvent(QGraphicsSceneMouseEvent *event) { + qreal mx = event->scenePos().x(); + qreal my = event->scenePos().y(); + + if(event->button() == Qt::LeftButton && + this->getTileAt(mx/32,my/32).turretAllowed()) + { + std::cout << "clic at : " << mx << "," << my << std::endl; + _entities.push_front(new WaterGun(((int)(mx/32))*32, + ((int)(my/32))*32, + 1, + (TYPE::ENTITY)(TYPE::T_RAMPANT | TYPE::T_VOLANT)) + ); + this->addItem(_entities.first()); + + } } + +Tile& Map::getTileAt(int x, int y) const { return *_mapTiles[x][y]; } diff --git a/map.h b/map.h index 02c7803..314fa49 100644 --- a/map.h +++ b/map.h @@ -4,22 +4,30 @@ #include #include #include +#include +#include + #include "tile.h" +#include "entity.h" +#include "cafard.h" +#include "watergun.h" + -class Map +class Map : public QGraphicsScene { private: // QList* _ennemyList; Tile* _mapTiles[16][16]; + QList _entities; QGraphicsScene* _scene; public: - Map(QGraphicsScene* scene); - ~Map(); - void LoadBackground(void); + Map(QObject* parent); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + Tile& getTileAt(int x, int y) const; }; #endif // MAP_H diff --git a/media/maps/map.txt b/media/maps/map.txt index b8715a2..eb80bce 100644 --- a/media/maps/map.txt +++ b/media/maps/map.txt @@ -1,16 +1,16 @@ 0 0 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 6 4 4 4 4 4 4 4 4 6 0 0 0 0 +0 0 6 4 4 4 4 4 4 4 4 134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 6 4 6 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 -0 0 10 8 8 8 8 8 8 8 8 8 8 10 0 0 +0 0 0 0 0 138 8 8 137 0 0 6 4 134 0 0 +0 0 0 0 0 2 0 0 1 0 0 0 0 2 0 0 +0 0 0 0 0 2 0 0 1 0 0 0 0 2 0 0 +0 0 138 8 8 10 0 0 9 8 8 8 8 10 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 64 64 64 0 0 0 0 0 0 0 -0 0 6 4 6 0 64 64 64 64 0 0 0 0 0 0 +0 0 6 4 134 0 64 64 64 64 0 0 0 0 0 0 0 0 0 0 2 0 0 64 64 64 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 6 4 4 4 4 4 4 4 4 6 0 0 +0 0 0 0 6 4 4 4 4 4 4 4 4 134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 0 0 diff --git a/media/maps/waves.txt b/media/maps/waves.txt new file mode 100644 index 0000000..579c8f4 --- /dev/null +++ b/media/maps/waves.txt @@ -0,0 +1,7 @@ +Quinze petites fourmis;fourmi:1:15:20 +Des cafards...;cafard:1:15:20 +Invasion de guêpes;guepe:1:15:20 +Ca gratte...;moustique:1:15:20 +Les fourmis et une grande guêpe;fourmi:1:15:25;guepe:1.7:1:25 +Multiplication;cafard:2:7:30 +Sept cafards, trois moustiques et dix fourmis géantes;cafard:1:7:25;moustique:1.1:3:30;fourmi:3:10:40 \ No newline at end of file diff --git a/media/textures/ennemies/cafard1.png b/media/textures/ennemies/cafard1.png new file mode 100644 index 0000000..1614ffa Binary files /dev/null and b/media/textures/ennemies/cafard1.png differ diff --git a/media/textures/ennemies/cafard2.png b/media/textures/ennemies/cafard2.png new file mode 100644 index 0000000..c46576c Binary files /dev/null and b/media/textures/ennemies/cafard2.png differ diff --git a/media/textures/ennemies/cafard3.png b/media/textures/ennemies/cafard3.png new file mode 100644 index 0000000..2efa922 Binary files /dev/null and b/media/textures/ennemies/cafard3.png differ diff --git a/media/textures/ennemies/fourmi1.png b/media/textures/ennemies/fourmi1.png new file mode 100644 index 0000000..74810b6 Binary files /dev/null and b/media/textures/ennemies/fourmi1.png differ diff --git a/media/textures/ennemies/fourmi2.png b/media/textures/ennemies/fourmi2.png new file mode 100644 index 0000000..5cf3a07 Binary files /dev/null and b/media/textures/ennemies/fourmi2.png differ diff --git a/media/textures/ennemies/fourmi3.png b/media/textures/ennemies/fourmi3.png new file mode 100644 index 0000000..3ec02ae Binary files /dev/null and b/media/textures/ennemies/fourmi3.png differ diff --git a/media/textures/ennemies/guepe1.png b/media/textures/ennemies/guepe1.png new file mode 100644 index 0000000..e76fe23 Binary files /dev/null and b/media/textures/ennemies/guepe1.png differ diff --git a/media/textures/ennemies/guepe2.png b/media/textures/ennemies/guepe2.png new file mode 100644 index 0000000..6c06da0 Binary files /dev/null and b/media/textures/ennemies/guepe2.png differ diff --git a/media/textures/ennemies/moustiquevolant1.png b/media/textures/ennemies/moustiquevolant1.png new file mode 100644 index 0000000..983055f Binary files /dev/null and b/media/textures/ennemies/moustiquevolant1.png differ diff --git a/media/textures/ennemies/moustiquevolant2.png b/media/textures/ennemies/moustiquevolant2.png new file mode 100644 index 0000000..2e62919 Binary files /dev/null and b/media/textures/ennemies/moustiquevolant2.png differ diff --git a/media/textures/goal.png b/media/textures/goal.png deleted file mode 100644 index 531163d..0000000 Binary files a/media/textures/goal.png and /dev/null differ diff --git a/media/textures/grass.jpg b/media/textures/grass.jpg deleted file mode 100644 index 04caa28..0000000 Binary files a/media/textures/grass.jpg and /dev/null differ diff --git a/media/textures/hpath.jpg b/media/textures/hpath.jpg deleted file mode 100644 index 992566b..0000000 Binary files a/media/textures/hpath.jpg and /dev/null differ diff --git a/media/textures/mud.jpg b/media/textures/mud.jpg deleted file mode 100644 index ea47f91..0000000 Binary files a/media/textures/mud.jpg and /dev/null differ diff --git a/media/textures/nepath.jpg b/media/textures/nepath.jpg deleted file mode 100644 index 236d708..0000000 Binary files a/media/textures/nepath.jpg and /dev/null differ diff --git a/media/textures/nopath.jpg b/media/textures/nopath.jpg deleted file mode 100644 index 5b380a4..0000000 Binary files a/media/textures/nopath.jpg and /dev/null differ diff --git a/media/textures/plain/goal.png b/media/textures/plain/goal.png new file mode 100644 index 0000000..b26f252 Binary files /dev/null and b/media/textures/plain/goal.png differ diff --git a/media/textures/plain/grass.png b/media/textures/plain/grass.png new file mode 100644 index 0000000..bc177ce Binary files /dev/null and b/media/textures/plain/grass.png differ diff --git a/media/textures/plain/hpath.png b/media/textures/plain/hpath.png new file mode 100644 index 0000000..c5df789 Binary files /dev/null and b/media/textures/plain/hpath.png differ diff --git a/media/textures/plain/mud.png b/media/textures/plain/mud.png new file mode 100644 index 0000000..7bb5cea Binary files /dev/null and b/media/textures/plain/mud.png differ diff --git a/media/textures/plain/ne.png b/media/textures/plain/ne.png new file mode 100644 index 0000000..93cdf07 Binary files /dev/null and b/media/textures/plain/ne.png differ diff --git a/media/textures/plain/nw.png b/media/textures/plain/nw.png new file mode 100644 index 0000000..f8127fb Binary files /dev/null and b/media/textures/plain/nw.png differ diff --git a/media/textures/plain/se.png b/media/textures/plain/se.png new file mode 100644 index 0000000..a106ffb Binary files /dev/null and b/media/textures/plain/se.png differ diff --git a/media/textures/plain/sw.png b/media/textures/plain/sw.png new file mode 100644 index 0000000..1ed2764 Binary files /dev/null and b/media/textures/plain/sw.png differ diff --git a/media/textures/plain/vpath.png b/media/textures/plain/vpath.png new file mode 100644 index 0000000..3967d8a Binary files /dev/null and b/media/textures/plain/vpath.png differ diff --git a/media/textures/tilea2.png b/media/textures/tilea2.png new file mode 100644 index 0000000..1348d5a Binary files /dev/null and b/media/textures/tilea2.png differ diff --git a/media/textures/vpath.jpg b/media/textures/vpath.jpg deleted file mode 100644 index ef351c8..0000000 Binary files a/media/textures/vpath.jpg and /dev/null differ diff --git a/monster.cpp b/monster.cpp new file mode 100644 index 0000000..9315f33 --- /dev/null +++ b/monster.cpp @@ -0,0 +1,8 @@ +#include "monster.h" + +Monster::Monster(int posx,int posy, int size):Entity(posx,posy),_size(size){ } + + +int Monster::getHP(void) const { return _hp; } +int Monster::getResistance(void) const { return _resistance; } + diff --git a/monster.h b/monster.h new file mode 100644 index 0000000..e81f6e5 --- /dev/null +++ b/monster.h @@ -0,0 +1,24 @@ +#ifndef MONSTER_H +#define MONSTER_H + +#include "entity.h" + + +class Monster : public Entity { + +public: + Monster(int posx, int posy, int size); + int getResistance(void) const; + int getHP(void) const; + +protected: + int _size; + int _hp; + int _resistance; + int _speed; +}; + + + +#endif // MONSTER_H + diff --git a/tile.cpp b/tile.cpp index 7683c9c..3f05a5d 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1,42 +1,97 @@ #include "tile.h" #include using namespace std; +using namespace TYPE; -Tile::Tile(int tileNumber) +Tile::Tile(int tileNumber, int x, int y):_tileNumber(tileNumber) { - QString filePath("media/textures/"); + // Direction associée au tile + int direction_bit_mask = tileNumber % 16; // Modulo 16 en cas de tile de départ + + // Déplacement horizontal + // Ouest + if((direction_bit_mask & WEST) == WEST) + _dir.setX(-1); + // Est + if((direction_bit_mask & EAST) == EAST) + _dir.setX(1); + // Déplacement vertical + // Nord + if((direction_bit_mask & NORTH) == NORTH) + _dir.setY(-1); + // Sud + if((direction_bit_mask & SOUTH) == SOUTH) + _dir.setY(1); + + + // DEBUG std::cout << "at " << x << "," << y << " ,tileNumber : " << tileNumber << ", dir.setX: " << _dir.x() << ", dir.setY: " << _dir.y() << std::endl; + + // Positionne relativement à la scène + this->setPos(x*32,y*32); + + + /* QString filePath("./media/textures/"); filePath+= TexName(tileNumber); // TEST filePath+= QString(".jpg"); - cout << filePath.toStdString() << endl; - QPixmap texFile(filePath); - texFile.scaled(32,32,Qt::IgnoreAspectRatio); - this->setPixmap(texFile); + cout << filePath.toStdString() << endl;*/ + _pixmap = new QPixmap("media/textures/plain/" + TexName(tileNumber) + ".png"); + if (_pixmap->isNull()) + cout << "pixmap null" << endl; + + _x = x; + _y = y; + *_pixmap = _pixmap->scaled(32,32,Qt::IgnoreAspectRatio); + this->setPixmap(*_pixmap); } +int Tile::getX() const { return _x; } +int Tile::getY() const { return _y; } +QVector2D Tile::getDirection(void) const { return _dir; } + +bool Tile::turretAllowed(void) const { + + if(_tileNumber == 0) + return true; + return false; +} + QString Tile::TexName(int n){ // Normal textures - if(n>0 && n<32){ - - n%=16; // To keep a value between 0 and 10 + if((n & (TYPE::NORTH | TYPE::EAST | TYPE::UP)) == (TYPE::NORTH | TYPE::EAST | TYPE::UP)) + return "nw"; + if((n & (TYPE::NORTH | TYPE::EAST)) == (TYPE::NORTH | TYPE::EAST)) + return "se"; + if((n & (TYPE::NORTH | TYPE::WEST | TYPE::UP)) == (TYPE::NORTH | TYPE::WEST | TYPE::UP)) + return "ne"; + if((n & (TYPE::NORTH | TYPE::WEST)) == (TYPE::NORTH | TYPE::WEST)) + return "sw"; + if((n & (TYPE::SOUTH | TYPE::EAST | TYPE::UP)) == (TYPE::SOUTH | TYPE::EAST | TYPE::UP)) + return "ne"; + if((n & (TYPE::SOUTH | TYPE::EAST)) == (TYPE::SOUTH | TYPE::EAST)) + return "sw"; + if((n & (TYPE::SOUTH | TYPE::WEST | TYPE::UP)) == (TYPE::SOUTH | TYPE::WEST | TYPE::UP)) + return "nw"; + if((n & (TYPE::SOUTH | TYPE::WEST)) == (TYPE::SOUTH | TYPE::WEST)) + return "se"; - if(n==0) - return "grass"; - if(n==1 || n==2) - return "hpath"; - if(n==4 || n==8) - return "vpath"; - if(n==5 || n==10) - return "nepath"; - if(n==6 || n==9) - return "nopath"; + if( ((n & TYPE::NORTH) == TYPE::NORTH) || + ((n & TYPE::SOUTH) == TYPE::SOUTH) + ) + return "vpath"; + if( ((n & TYPE::EAST) == TYPE::EAST) || + ((n & TYPE::WEST) == TYPE::WEST) + ) + return "hpath"; - } + // Special textures + if(n==32) + return "goal"; if(n==64) return "mud"; - // Special textures + return "grass"; } diff --git a/tile.h b/tile.h index b591939..ad62b61 100644 --- a/tile.h +++ b/tile.h @@ -2,17 +2,30 @@ #define TILE_H #include +#include +#include "types.h" + +// Masque binaire pour déterminer l'orientation d'un tile class Tile : public QGraphicsPixmapItem { public: - Tile(int tileNumber); + Tile(int tileNumber, int x, int y); ~Tile(void); + int getX() const; + int getY() const; + bool turretAllowed(void) const; + QVector2D getDirection(void) const; - QString TexName(int n); + QString TexName(int n); +private: + QPixmap *_pixmap; + int _x, _y; + int _tileNumber; + QVector2D _dir; }; #endif // TILE_H diff --git a/types.h b/types.h new file mode 100644 index 0000000..3a0a232 --- /dev/null +++ b/types.h @@ -0,0 +1,14 @@ +#ifndef TYPES_H +#define TYPES_H + +namespace TYPE { + +// Utilisation du bit 2^7 pour coder une information supplémentaire +// concernant les diagonales (cf doc) + +typedef enum DIRECTION { NORTH = 1 , SOUTH = 2 , EAST = 4 , WEST = 8, UP = 128 } DIRECTION; +typedef enum ENTITY { T_RAMPANT = 1, T_VOLANT = 2 } ENTITY; + +} + +#endif // TYPES_H diff --git a/watergun.cpp b/watergun.cpp new file mode 100644 index 0000000..c3145cf --- /dev/null +++ b/watergun.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "watergun.h" + +WaterGun::WaterGun(int posx,int posy,int level,TYPE::ENTITY target) + : Defenser(posx,posy,level,target) +{ + updateStats(); + this->setPos(_x,_y); +} + +int WaterGun::getCost(void) const{ + + switch(_level) { + case 1: return 8; + case 2: return 20; + default: return 45; + } +} + +void WaterGun::updateStats(void) { + + _range = (2 + _level/2)*50; + _rate = 4 - _level/2; + _power = 5 * _level * sqrt(_level); // level ^ 1.5 + +} + +QRectF WaterGun::boundingRect() const { + return QRectF(-100,-100,200,200); +} + +void WaterGun::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*) { + + painter->setBrush(QBrush(Qt::red)); + // Dessine la tourelle + painter->drawRect(0,0,32,32); + + // Dessine la portée de la tourelle + painter->setBrush(QBrush(Qt::blue,Qt::NoBrush)); + painter->drawEllipse(-32 - 2,-32 - 2,_range,_range); + +} + +void WaterGun::advance(int phase) { + + if(!phase) + return; + + + +} diff --git a/watergun.h b/watergun.h new file mode 100644 index 0000000..7abf855 --- /dev/null +++ b/watergun.h @@ -0,0 +1,24 @@ +#ifndef WATERGUN_H +#define WATERGUN_H + +#include +#include "defenser.h" +#include "map.h" + +class Map; + +class WaterGun : public Defenser +{ +public: + WaterGun(int posx,int posy,int level,TYPE::ENTITY target); + int getCost(void) const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget*); + QRectF boundingRect() const; +protected: + void advance(int phase); + void updateStats(void); + + Map* _map; +}; + +#endif // WATERGUN_H