]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
New version with turret test, moving insect and 8 direction tiles
authorcboissie <clemzbox@gmail.com>
Thu, 19 May 2011 00:42:06 +0000 (02:42 +0200)
committercboissie <clemzbox@gmail.com>
Thu, 19 May 2011 00:42:06 +0000 (02:42 +0200)
48 files changed:
Bug_Attack.pro
cafard.cpp [new file with mode: 0644]
cafard.h [new file with mode: 0644]
defenser.cpp [new file with mode: 0644]
defenser.h [new file with mode: 0644]
entity.cpp [new file with mode: 0644]
entity.h [new file with mode: 0644]
mainwindow.cpp
mainwindow.h
mainwindow.ui
map.cpp
map.h
media/maps/map.txt
media/maps/waves.txt [new file with mode: 0644]
media/textures/ennemies/cafard1.png [new file with mode: 0644]
media/textures/ennemies/cafard2.png [new file with mode: 0644]
media/textures/ennemies/cafard3.png [new file with mode: 0644]
media/textures/ennemies/fourmi1.png [new file with mode: 0644]
media/textures/ennemies/fourmi2.png [new file with mode: 0644]
media/textures/ennemies/fourmi3.png [new file with mode: 0644]
media/textures/ennemies/guepe1.png [new file with mode: 0644]
media/textures/ennemies/guepe2.png [new file with mode: 0644]
media/textures/ennemies/moustiquevolant1.png [new file with mode: 0644]
media/textures/ennemies/moustiquevolant2.png [new file with mode: 0644]
media/textures/goal.png [deleted file]
media/textures/grass.jpg [deleted file]
media/textures/hpath.jpg [deleted file]
media/textures/mud.jpg [deleted file]
media/textures/nepath.jpg [deleted file]
media/textures/nopath.jpg [deleted file]
media/textures/plain/goal.png [new file with mode: 0644]
media/textures/plain/grass.png [new file with mode: 0644]
media/textures/plain/hpath.png [new file with mode: 0644]
media/textures/plain/mud.png [new file with mode: 0644]
media/textures/plain/ne.png [new file with mode: 0644]
media/textures/plain/nw.png [new file with mode: 0644]
media/textures/plain/se.png [new file with mode: 0644]
media/textures/plain/sw.png [new file with mode: 0644]
media/textures/plain/vpath.png [new file with mode: 0644]
media/textures/tilea2.png [new file with mode: 0644]
media/textures/vpath.jpg [deleted file]
monster.cpp [new file with mode: 0644]
monster.h [new file with mode: 0644]
tile.cpp
tile.h
types.h [new file with mode: 0644]
watergun.cpp [new file with mode: 0644]
watergun.h [new file with mode: 0644]

index 0253ae5001ee36b9806438f5b30434a94adaab04..afff092b8b219c727109462b91ba4cb8702f1ef8 100644 (file)
@@ -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 (file)
index 0000000..2d35fc7
--- /dev/null
@@ -0,0 +1,53 @@
+#include "cafard.h"
+#include <iostream>
+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 (file)
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 (file)
index 0000000..6b98369
--- /dev/null
@@ -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 (file)
index 0000000..e40434b
--- /dev/null
@@ -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 (file)
index 0000000..abdbfc5
--- /dev/null
@@ -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 (file)
index 0000000..4485e60
--- /dev/null
+++ b/entity.h
@@ -0,0 +1,38 @@
+#ifndef ENTITY_H
+#define ENTITY_H
+
+#include <QGraphicsPixmapItem>
+#include <QPixmap>
+#include <QList>
+
+#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<QPixmap*> _animPixmap;
+    int _x;
+    int _y;
+    int _animState; // Frame courante de l'animation
+    TYPE::ENTITY _type;
+
+
+};
+
+#endif // ENTITY_H
+
index 91d14cf410dbf84cc1a91a3d4517dd40c418000b..1ee5d9f9200ce8a6c02cde37cbcadeb9675604fd 100644 (file)
@@ -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;
index cd2ed0c9413469a099b77174a872f0ec2de60922..5da48441e8a4f2d186e9b4afff295f25f9ed9f66 100644 (file)
@@ -2,10 +2,13 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
-#include <QGraphicsScene>
+#include "map.h"
 #include <QGraphicsView>
 #include <QGraphicsPixmapItem>
 
+#include <QTimer>
+#include <QTime>
+
 #include "map.h"
 
 namespace Ui {
@@ -24,10 +27,9 @@ private:
     Ui::MainWindow *ui;
 
 
-    QGraphicsScene *_scene;
     QGraphicsView *_view;
-
-    Map *_currentMap;
+    QTimer timer;
+    Map* _sceneMap;
 
 };
 
index 9d1d5c98433566059c26e0109569f3482838fa4b..1c681f6a856951da3b3940026671c3a51ff6260c 100644 (file)
     <property name="horizontalScrollBarPolicy">
      <enum>Qt::ScrollBarAlwaysOff</enum>
     </property>
+    <property name="alignment">
+     <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+    </property>
    </widget>
   </widget>
  </widget>
diff --git a/map.cpp b/map.cpp
index f8a872bb108001af5a5a97ba1e2db2f6122feeb1..8a5a5da746690c0bd3736dc544a0dd1d4e614368 100644 (file)
--- 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 02c780353f2124ec828ade62e6432cd68ab49c64..314fa49d74bab82ff0a817d913bdf6d95e6aafb5 100644 (file)
--- a/map.h
+++ b/map.h
@@ -4,22 +4,30 @@
 #include <QFile>
 #include <QList>
 #include <QGraphicsScene>
+#include <QGraphicsSceneMouseEvent>
+#include <QMouseEvent>
+
 #include "tile.h"
+#include "entity.h"
+#include "cafard.h"
+#include "watergun.h"
+
 
-class Map
+class Map : public QGraphicsScene
 {
 
 private:
 
     // QList<int>* _ennemyList;
     Tile* _mapTiles[16][16];
+    QList<Entity*> _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
index b8715a2bada1d6978452cbe16c5ec20e76961828..eb80bce47db705ae0d22657cb76151d1e489c418 100644 (file)
@@ -1,16 +1,16 @@
 0  0  18 0  0  0  0  0  0  0  0  0  0  0  0  0  \r
 0  0  2  0  0  0  0  0  0  0  0  0  0  0  0  0  \r
-0  0  6  4  4  4  4  4  4  4  4  6  0  0  0  0  \r
+0  0  6  4  4  4  4  4  4  4  4  134  0  0  0  0  \r
 0  0  0  0  0  0  0  0  0  0  0  2  0  0  0  0  \r
-0  0  0  0  0  0  0  0  0  0  0  6  4  6  0  0  \r
-0  0  0  0  0  0  0  0  0  0  0  0  0  2  0  0  \r
-0  0  0  0  0  0  0  0  0  0  0  0  0  2  0  0  \r
-0  0  10 8  8  8  8  8  8  8  8  8  8  10 0  0  \r
+0  0  0    0  0  138  8  8  137  0  0  6  4  134  0  0  \r
+0  0  0    0  0  2  0  0  1  0  0  0  0  2  0  0  \r
+0  0  0    0  0  2  0  0  1  0  0  0  0  2  0  0  \r
+0  0  138  8  8  10  0  0  9  8  8  8  8  10 0  0  \r
 0  0  2  0  0  0  0  0  0  0  0  0  0  0  0  0  \r
 0  0  2  0  0  0  64 64 64 0  0  0  0  0  0  0  \r
-0  0  6  4  6  0  64 64 64 64 0  0  0  0  0  0  \r
+0  0  6  4  134  0  64 64 64 64 0  0  0  0  0  0  \r
 0  0  0  0  2  0  0  64 64 64 0  0  0  0  0  0  \r
 0  0  0  0  2  0  0  0  0  0  0  0  0  0  0  0  \r
-0  0  0  0  6  4  4  4  4  4  4  4  4  6  0  0  \r
+0  0  0  0  6  4  4  4  4  4  4  4  4  134  0  0  \r
 0  0  0  0  0  0  0  0  0  0  0  0  0  2  0  0  \r
 0  0  0  0  0  0  0  0  0  0  0  0  0  32 0  0  \r
diff --git a/media/maps/waves.txt b/media/maps/waves.txt
new file mode 100644 (file)
index 0000000..579c8f4
--- /dev/null
@@ -0,0 +1,7 @@
+Quinze petites fourmis;fourmi:1:15:20\r
+Des cafards...;cafard:1:15:20\r
+Invasion de guêpes;guepe:1:15:20\r
+Ca gratte...;moustique:1:15:20\r
+Les fourmis et une grande guêpe;fourmi:1:15:25;guepe:1.7:1:25\r
+Multiplication;cafard:2:7:30\r
+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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..9315f33
--- /dev/null
@@ -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 (file)
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
+
index 7683c9cd1645ab40c1ebd7e2e637ef0935e8a470..3f05a5d8d9abd4e2d83139cf06c9b04dc993288d 100644 (file)
--- a/tile.cpp
+++ b/tile.cpp
@@ -1,42 +1,97 @@
 #include "tile.h"
 #include <iostream>
 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 b5919395436a9f82e1ca5329c35b85f317227191..ad62b617546ba8f2d8b0b6da456a52b5cd3ec206 100644 (file)
--- a/tile.h
+++ b/tile.h
@@ -2,17 +2,30 @@
 #define TILE_H
 
 #include <QGraphicsPixmapItem>
+#include <QVector2D>
+#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 (file)
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 (file)
index 0000000..c3145cf
--- /dev/null
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <math.h>
+#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 (file)
index 0000000..7abf855
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef WATERGUN_H
+#define WATERGUN_H
+
+#include <QPainter>
+#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