]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
Tests with Qt
authorcboissie <clemzbox@gmail.com>
Thu, 12 May 2011 05:17:20 +0000 (07:17 +0200)
committercboissie <clemzbox@gmail.com>
Thu, 12 May 2011 05:17:20 +0000 (07:17 +0200)
15 files changed:
Bug_Attack.pro
mainwindow.cpp
mainwindow.h
mainwindow.ui
map.cpp [new file with mode: 0644]
map.h [new file with mode: 0644]
media/maps/map.txt [new file with mode: 0644]
media/textures/goal.png [new file with mode: 0644]
media/textures/hpath.jpg [new file with mode: 0644]
media/textures/mud.jpg [new file with mode: 0644]
media/textures/nepath.jpg [new file with mode: 0644]
media/textures/nopath.jpg [new file with mode: 0644]
media/textures/vpath.jpg [new file with mode: 0644]
tile.cpp
tile.h

index 35561fe8d1e56660e84693c353a2febf349d270c..0253ae5001ee36b9806438f5b30434a94adaab04 100644 (file)
@@ -12,9 +12,11 @@ TEMPLATE = app
 
 SOURCES += main.cpp\
         mainwindow.cpp \
-    tile.cpp
+    tile.cpp \
+    map.cpp
 
 HEADERS  += mainwindow.h \
-    tile.h
+    tile.h \
+    map.h
 
 FORMS    += mainwindow.ui
index f8847ffef9de55e58314ea244a1d0a014d950fcf..91d14cf410dbf84cc1a91a3d4517dd40c418000b 100644 (file)
@@ -14,19 +14,10 @@ MainWindow::MainWindow(QWidget *parent) :
     _view = ui->graphicsView;
     _view->setScene(_scene);
 
-    QPixmap grass("media/textures/grass.jpg");
-    grass = grass.scaled(32,32,Qt::IgnoreAspectRatio);
-    for(int i = 0; i < 16; ++i){
-        for(int j = 0; j < 16 ; ++j){
-
-            _grassTile = _scene->addPixmap(grass);
-            _grassTile->setPos(32*i,32*j);
-
-        }
-     }
+    _currentMap = new Map(_scene);
+    _currentMap->LoadBackground();
 
     _view->show();
-
 }
 
 MainWindow::~MainWindow()
index 5342c7951153c23354706ed8fb89bc9fe76a70ad..cd2ed0c9413469a099b77174a872f0ec2de60922 100644 (file)
@@ -6,6 +6,8 @@
 #include <QGraphicsView>
 #include <QGraphicsPixmapItem>
 
+#include "map.h"
+
 namespace Ui {
     class MainWindow;
 }
@@ -24,7 +26,9 @@ private:
 
     QGraphicsScene *_scene;
     QGraphicsView *_view;
-    QGraphicsPixmapItem *_grassTile;
+
+    Map *_currentMap;
+
 };
 
 #endif // MAINWINDOW_H
index 1c681f6a856951da3b3940026671c3a51ff6260c..9d1d5c98433566059c26e0109569f3482838fa4b 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
new file mode 100644 (file)
index 0000000..f8a872b
--- /dev/null
+++ b/map.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <fstream>
+#include "map.h"
+
+
+
+Map::Map(QGraphicsScene* scene)
+{
+
+    // Container
+    _scene = scene;
+
+ /*   // 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()){
+        QByteArray line = mapFile.readLine();
+        QList<QByteArray> tileNumber = line.split(' ');
+        for(int x = 0; x < tileNumber.size(); ++x)
+             _mapTiles[x][y] = new Tile(tileNumber[x].toInt());
+        y++;
+    }
+
+    // Close file
+    mapFile.close();*/
+
+    std::ifstream fichier("media/maps/map.txt");
+    int i, j;
+    int num;
+    if(fichier)
+    {
+        for(i = 0; i < 16; i++)
+        {
+            for(j = 0; j < 16; j++)
+            {
+                fichier >> num;
+                std::cout << num << std::endl;
+                _mapTiles[i][j] = new Tile(num);
+            }
+        }
+    }
+}
+
+void Map::LoadBackground(void) {
+
+    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(){
+
+
+}
diff --git a/map.h b/map.h
new file mode 100644 (file)
index 0000000..02c7803
--- /dev/null
+++ b/map.h
@@ -0,0 +1,25 @@
+#ifndef MAP_H
+#define MAP_H
+
+#include <QFile>
+#include <QList>
+#include <QGraphicsScene>
+#include "tile.h"
+
+class Map
+{
+
+private:
+
+    // QList<int>* _ennemyList;
+    Tile* _mapTiles[16][16];
+    QGraphicsScene* _scene;
+
+
+public:
+    Map(QGraphicsScene* scene);
+    ~Map();
+    void LoadBackground(void);
+};
+
+#endif // MAP_H
diff --git a/media/maps/map.txt b/media/maps/map.txt
new file mode 100644 (file)
index 0000000..b8715a2
--- /dev/null
@@ -0,0 +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  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  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  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  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/textures/goal.png b/media/textures/goal.png
new file mode 100644 (file)
index 0000000..531163d
Binary files /dev/null and b/media/textures/goal.png differ
diff --git a/media/textures/hpath.jpg b/media/textures/hpath.jpg
new file mode 100644 (file)
index 0000000..992566b
Binary files /dev/null and b/media/textures/hpath.jpg differ
diff --git a/media/textures/mud.jpg b/media/textures/mud.jpg
new file mode 100644 (file)
index 0000000..ea47f91
Binary files /dev/null and b/media/textures/mud.jpg differ
diff --git a/media/textures/nepath.jpg b/media/textures/nepath.jpg
new file mode 100644 (file)
index 0000000..236d708
Binary files /dev/null and b/media/textures/nepath.jpg differ
diff --git a/media/textures/nopath.jpg b/media/textures/nopath.jpg
new file mode 100644 (file)
index 0000000..5b380a4
Binary files /dev/null and b/media/textures/nopath.jpg differ
diff --git a/media/textures/vpath.jpg b/media/textures/vpath.jpg
new file mode 100644 (file)
index 0000000..ef351c8
Binary files /dev/null and b/media/textures/vpath.jpg differ
index 2b5a245f904646f7a3f9e653ee1c0c88c6e77524..7683c9cd1645ab40c1ebd7e2e637ef0935e8a470 100644 (file)
--- a/tile.cpp
+++ b/tile.cpp
@@ -1,8 +1,43 @@
 #include "tile.h"
+#include <iostream>
+using namespace std;
 
-Tile::Tile():QGraphicsPixmapItem()
+Tile::Tile(int tileNumber)
 {
-    this->setPixmap(QPixmap("media/textures/grass.jpg"));
+    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);
 
+}
+
+QString Tile::TexName(int n){
+
+    // Normal textures
+    if(n>0 && n<32){
+
+        n%=16; // To keep a value between 0 and 10
 
+        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==64)
+        return "mud";
+    // Special textures
+    return "grass";
 }
+
+Tile::~Tile(){}
diff --git a/tile.h b/tile.h
index 562cff21d278e15fccb6899acab9647b6e160685..b5919395436a9f82e1ca5329c35b85f317227191 100644 (file)
--- a/tile.h
+++ b/tile.h
@@ -6,7 +6,13 @@
 class Tile : public QGraphicsPixmapItem
 {
 public:
-    Tile();
+
+    Tile(int tileNumber);
+    ~Tile(void);
+
+    QString TexName(int n);
+
+
 };
 
 #endif // TILE_H