summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-05 12:26:04 +0200
committermanuel <manuel@mausz.at>2011-04-05 12:26:04 +0200
commitbfaf2e63e64169abbb1a4c079a937091060574b7 (patch)
tree4054c7cce1f9e8aaa467ef51e28c581c40986b93
parent897bc2bb42d79369d2f915d0da4e3b7f3b1a6fce (diff)
downloadfoop-bfaf2e63e64169abbb1a4c079a937091060574b7.tar.gz
foop-bfaf2e63e64169abbb1a4c079a937091060574b7.tar.bz2
foop-bfaf2e63e64169abbb1a4c079a937091060574b7.zip
forgot some commits..
replace std::map with QMap
-rw-r--r--pacman-c++/actor.cpp6
-rw-r--r--pacman-c++/block.cpp6
-rw-r--r--pacman-c++/block.h6
-rw-r--r--pacman-c++/bonuspoint.cpp13
-rw-r--r--pacman-c++/client.cpp2
-rw-r--r--pacman-c++/constants.h7
-rw-r--r--pacman-c++/mainwidget.cpp3
-rw-r--r--pacman-c++/pacman.qrc3
8 files changed, 27 insertions, 19 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index 2df238b..d900e57 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -6,10 +6,6 @@
6#include <QtCore/QVariantAnimation> 6#include <QtCore/QVariantAnimation>
7#include <QDebug> 7#include <QDebug>
8 8
9#define SPRITE_MARGIN 2
10#define SPRITE_PLAYER_WIDTH 16
11#define SPRITE_PLAYER_HEIGHT 16
12
13static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) 9static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress)
14{ 10{
15 return (progress == 1.0) ? end : start; 11 return (progress == 1.0) ? end : start;
@@ -37,7 +33,7 @@ Actor::Actor(Color color, QGraphicsItem *parent)
37 PixmapItem *img = new PixmapItem(m_pix, this); 33 PixmapItem *img = new PixmapItem(m_pix, this);
38 int x = i * 20 + SPRITE_MARGIN; 34 int x = i * 20 + SPRITE_MARGIN;
39 int y = m_direction * 20 + SPRITE_MARGIN; 35 int y = m_direction * 20 + SPRITE_MARGIN;
40 img->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); 36 img->setSprite(x, y, SPRITE_WIDTH, SPRITE_HEIGHT);
41 img->setZValue(zValue()); 37 img->setZValue(zValue());
42 img->setVisible(false); 38 img->setVisible(false);
43 img->setPos(QPointF(200, 0)); 39 img->setPos(QPointF(200, 0));
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index 6383b3a..87c69a7 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -1,8 +1,8 @@
1#include "block.h" 1#include "block.h"
2#include "constants.h" 2#include "constants.h"
3#include <QtGui> 3#include <QtDebug>
4 4
5std::map<Color, QPixmap> Block::m_pixmaps; 5QMap<Color, QPixmap> Block::m_pixmaps;
6 6
7Block::Block(Color color, QGraphicsItem *parent) 7Block::Block(Color color, QGraphicsItem *parent)
8 : PixmapItem(parent) 8 : PixmapItem(parent)
@@ -12,6 +12,6 @@ Block::Block(Color color, QGraphicsItem *parent)
12 QString pixmapName = ":/" + QString("block%1").arg(color); 12 QString pixmapName = ":/" + QString("block%1").arg(color);
13 m_pixmaps[color] = QPixmap(pixmapName); 13 m_pixmaps[color] = QPixmap(pixmapName);
14 } 14 }
15 setPixmap(m_pixmaps.find(color)->second); 15 setPixmap(m_pixmaps.find(color).value());
16 qDebug() << "loading block w color: " << color; 16 qDebug() << "loading block w color: " << color;
17} 17}
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index 793d4a8..034a626 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -1,11 +1,9 @@
1#ifndef BLOCK_H 1#ifndef BLOCK_H
2#define BLOCK_H 2#define BLOCK_H
3 3
4
5#include "pixmapitem.h" 4#include "pixmapitem.h"
6#include "constants.h" 5#include "constants.h"
7#include <map> 6#include <QMap>
8
9 7
10class Block 8class Block
11 : public PixmapItem 9 : public PixmapItem
@@ -15,7 +13,7 @@ public:
15 13
16 private: 14 private:
17 // map for saving QPixmaps for reuse 15 // map for saving QPixmaps for reuse
18 static std::map<Color, QPixmap> m_pixmaps; 16 static QMap<Color, QPixmap> m_pixmaps;
19}; 17};
20 18
21#endif // BLOCK_H 19#endif // BLOCK_H
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp
index e2fdba0..8ebc195 100644
--- a/pacman-c++/bonuspoint.cpp
+++ b/pacman-c++/bonuspoint.cpp
@@ -1,14 +1,21 @@
1#include "bonuspoint.h" 1#include "bonuspoint.h"
2#include "constants.h"
3#include <QDebug>
4
5#define BONUSPOINTS_NUM_SPRITES 4
2 6
3namespace 7namespace
4{ 8{
5 QPixmap *pixmap = 0; 9 QPixmap *pixmap = NULL;
6} 10}
7 11
8BonusPoint::BonusPoint(QGraphicsItem *parent) 12BonusPoint::BonusPoint(QGraphicsItem *parent)
9 : PixmapItem(parent) 13 : PixmapItem(parent)
10{ 14{
11 if (pixmap == 0) 15 if (pixmap == NULL)
12 pixmap = new QPixmap(":/cherry"); 16 pixmap = new QPixmap(":/bonuspoints");
13 setPixmap(*pixmap); 17 setPixmap(*pixmap);
18
19 int rand = (int) (BONUSPOINTS_NUM_SPRITES * (qrand() / (RAND_MAX + 1.0)));
20 setSprite(rand * 20 + SPRITE_MARGIN, SPRITE_MARGIN, SPRITE_WIDTH, SPRITE_HEIGHT);
14} 21}
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp
index 416bd12..736de35 100644
--- a/pacman-c++/client.cpp
+++ b/pacman-c++/client.cpp
@@ -11,7 +11,7 @@ int main(int argc, char ** argv) {
11 QApplication app(argc, argv); 11 QApplication app(argc, argv);
12 app.setApplicationName("pacman-client"); 12 app.setApplicationName("pacman-client");
13 13
14 qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); 14 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
15 15
16 Client client; 16 Client client;
17 client.show(); 17 client.show();
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h
index d9362d8..56d29b7 100644
--- a/pacman-c++/constants.h
+++ b/pacman-c++/constants.h
@@ -1,6 +1,10 @@
1#ifndef CONSTANTS_H 1#ifndef CONSTANTS_H
2#define CONSTANTS_H 2#define CONSTANTS_H
3 3
4#define SPRITE_MARGIN 2
5#define SPRITE_WIDTH 16
6#define SPRITE_HEIGHT 16
7
4const unsigned int map_size[2] = { 20, 20 }; 8const unsigned int map_size[2] = { 20, 20 };
5const unsigned int field_size[2] = { 16, 16 }; 9const unsigned int field_size[2] = { 16, 16 };
6 10
@@ -22,6 +26,7 @@ namespace transmission
22 const field_t bonuspoint = (1 << 4); 26 const field_t bonuspoint = (1 << 4);
23 const field_t pacman = (1 << 5); 27 const field_t pacman = (1 << 5);
24 28
29 const field_t direction_none = 0;
25 const field_t direction_left = (1 << 6); 30 const field_t direction_left = (1 << 6);
26 const field_t direction_right = (1 << 7); 31 const field_t direction_right = (1 << 7);
27 const field_t direction_up = (1 << 8); 32 const field_t direction_up = (1 << 8);
@@ -29,7 +34,7 @@ namespace transmission
29 34
30 const mask_t color_mask = noColor | red | blue | green; 35 const mask_t color_mask = noColor | red | blue | green;
31 const mask_t type_mask = block | bonuspoint; 36 const mask_t type_mask = block | bonuspoint;
32 const mask_t direction_mask = direction_left | direction_right | direction_up | direction_down; 37 const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down;
33 38
34 typedef field_t** map_t; 39 typedef field_t** map_t;
35} 40}
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index 90d31b2..9fdf125 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -103,7 +103,8 @@ void MainWidget::loadDummyMap()
103 Actor::Movement direction; 103 Actor::Movement direction;
104 switch (cur & transmission::direction_mask) 104 switch (cur & transmission::direction_mask)
105 { 105 {
106 case 0: 106 case transmission::direction_none:
107 direction = Actor::None;
107 break; 108 break;
108 case transmission::direction_left: 109 case transmission::direction_left:
109 direction = Actor::Left; 110 direction = Actor::Left;
diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc
index 1d82831..feb4276 100644
--- a/pacman-c++/pacman.qrc
+++ b/pacman-c++/pacman.qrc
@@ -8,6 +8,7 @@
8 <file alias="block1">pics/block1.png</file> 8 <file alias="block1">pics/block1.png</file>
9 <file alias="block2">pics/block2.png</file> 9 <file alias="block2">pics/block2.png</file>
10 <file alias="block4">pics/block4.png</file> 10 <file alias="block4">pics/block4.png</file>
11 <file alias="cherry">pics/cherry.png</file> 11 <file alias="bonuspoints">pics/bonuspoints.png</file>
12 <file alias="points">pics/points.png</file>
12 </qresource> 13 </qresource>
13</RCC> 14</RCC>