From bfaf2e63e64169abbb1a4c079a937091060574b7 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 5 Apr 2011 12:26:04 +0200 Subject: forgot some commits.. replace std::map with QMap --- pacman-c++/actor.cpp | 6 +----- pacman-c++/block.cpp | 6 +++--- pacman-c++/block.h | 6 ++---- pacman-c++/bonuspoint.cpp | 13 ++++++++++--- pacman-c++/client.cpp | 2 +- pacman-c++/constants.h | 7 ++++++- pacman-c++/mainwidget.cpp | 3 ++- pacman-c++/pacman.qrc | 3 ++- 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 @@ #include #include -#define SPRITE_MARGIN 2 -#define SPRITE_PLAYER_WIDTH 16 -#define SPRITE_PLAYER_HEIGHT 16 - static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) { return (progress == 1.0) ? end : start; @@ -37,7 +33,7 @@ Actor::Actor(Color color, QGraphicsItem *parent) PixmapItem *img = new PixmapItem(m_pix, this); int x = i * 20 + SPRITE_MARGIN; int y = m_direction * 20 + SPRITE_MARGIN; - img->setSprite(x, y, SPRITE_PLAYER_WIDTH, SPRITE_PLAYER_HEIGHT); + img->setSprite(x, y, SPRITE_WIDTH, SPRITE_HEIGHT); img->setZValue(zValue()); img->setVisible(false); 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 @@ #include "block.h" #include "constants.h" -#include +#include -std::map Block::m_pixmaps; +QMap Block::m_pixmaps; Block::Block(Color color, QGraphicsItem *parent) : PixmapItem(parent) @@ -12,6 +12,6 @@ Block::Block(Color color, QGraphicsItem *parent) QString pixmapName = ":/" + QString("block%1").arg(color); m_pixmaps[color] = QPixmap(pixmapName); } - setPixmap(m_pixmaps.find(color)->second); + setPixmap(m_pixmaps.find(color).value()); qDebug() << "loading block w color: " << color; } 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 @@ #ifndef BLOCK_H #define BLOCK_H - #include "pixmapitem.h" #include "constants.h" -#include - +#include class Block : public PixmapItem @@ -15,7 +13,7 @@ public: private: // map for saving QPixmaps for reuse - static std::map m_pixmaps; + static QMap m_pixmaps; }; #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 @@ #include "bonuspoint.h" +#include "constants.h" +#include + +#define BONUSPOINTS_NUM_SPRITES 4 namespace { - QPixmap *pixmap = 0; + QPixmap *pixmap = NULL; } BonusPoint::BonusPoint(QGraphicsItem *parent) : PixmapItem(parent) { - if (pixmap == 0) - pixmap = new QPixmap(":/cherry"); + if (pixmap == NULL) + pixmap = new QPixmap(":/bonuspoints"); setPixmap(*pixmap); + + int rand = (int) (BONUSPOINTS_NUM_SPRITES * (qrand() / (RAND_MAX + 1.0))); + setSprite(rand * 20 + SPRITE_MARGIN, SPRITE_MARGIN, SPRITE_WIDTH, SPRITE_HEIGHT); } 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) { QApplication app(argc, argv); app.setApplicationName("pacman-client"); - qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); Client client; 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 @@ #ifndef CONSTANTS_H #define CONSTANTS_H +#define SPRITE_MARGIN 2 +#define SPRITE_WIDTH 16 +#define SPRITE_HEIGHT 16 + const unsigned int map_size[2] = { 20, 20 }; const unsigned int field_size[2] = { 16, 16 }; @@ -22,6 +26,7 @@ namespace transmission const field_t bonuspoint = (1 << 4); const field_t pacman = (1 << 5); + const field_t direction_none = 0; const field_t direction_left = (1 << 6); const field_t direction_right = (1 << 7); const field_t direction_up = (1 << 8); @@ -29,7 +34,7 @@ namespace transmission const mask_t color_mask = noColor | red | blue | green; const mask_t type_mask = block | bonuspoint; - const mask_t direction_mask = direction_left | direction_right | direction_up | direction_down; + const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; typedef field_t** map_t; } 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() Actor::Movement direction; switch (cur & transmission::direction_mask) { - case 0: + case transmission::direction_none: + direction = Actor::None; break; case transmission::direction_left: 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 @@ pics/block1.png pics/block2.png pics/block4.png - pics/cherry.png + pics/bonuspoints.png + pics/points.png -- cgit v1.2.3