diff options
| -rw-r--r-- | pacman-c++/actor.cpp | 8 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 13 | ||||
| -rw-r--r-- | pacman-c++/block.cpp | 17 | ||||
| -rw-r--r-- | pacman-c++/block.h | 10 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.cpp | 13 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.h | 15 | ||||
| -rw-r--r-- | pacman-c++/constants.h | 20 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 61 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 5 | ||||
| -rw-r--r-- | pacman-c++/pacman.pro | 2 | ||||
| -rw-r--r-- | pacman-c++/pacman.qrc | 6 | ||||
| -rw-r--r-- | pacman-c++/pics/actor3.png | bin | 703 -> 0 bytes | |||
| -rw-r--r-- | pacman-c++/pics/actor4.png | bin | 706 -> 703 bytes | |||
| -rw-r--r-- | pacman-c++/pics/actor8.png | bin | 0 -> 706 bytes | |||
| -rw-r--r-- | pacman-c++/pics/block0.png | bin | 0 -> 181 bytes | |||
| -rw-r--r-- | pacman-c++/pics/block2.png | bin | 0 -> 195 bytes | |||
| -rw-r--r-- | pacman-c++/pics/block4.png | bin | 0 -> 180 bytes | |||
| -rw-r--r-- | pacman-c++/pics/cherry.png | bin | 0 -> 214 bytes |
18 files changed, 139 insertions, 31 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 5f668fc..2df238b 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -15,14 +15,14 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal | |||
| 15 | return (progress == 1.0) ? end : start; | 15 | return (progress == 1.0) ? end : start; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | Actor::Actor(Type type, QGraphicsItem *parent) | 18 | Actor::Actor(Color color, QGraphicsItem *parent) |
| 19 | : PixmapItem(parent), m_type(type), m_direction(Actor::None) | 19 | : PixmapItem(parent), m_color(color), m_direction(Actor::None) |
| 20 | { | 20 | { |
| 21 | m_pix = ":/" + QString("actor%1").arg(m_type); | 21 | m_pix = ":/" + QString("actor%1").arg(m_color); |
| 22 | // DON'T set any pixmap here. we've a pixmap in the animation | 22 | // DON'T set any pixmap here. we've a pixmap in the animation |
| 23 | //setPixmap(m_pix); | 23 | //setPixmap(m_pix); |
| 24 | // higher player "over" lower player | 24 | // higher player "over" lower player |
| 25 | setZValue(m_type * 10); | 25 | setZValue(m_color * 10); |
| 26 | 26 | ||
| 27 | m_direction = Actor::Left; | 27 | m_direction = Actor::Left; |
| 28 | 28 | ||
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index 3cee699..d2d7875 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | #include "pixmapitem.h" | 4 | #include "pixmapitem.h" |
| 5 | 5 | ||
| 6 | #include "constants.h" | ||
| 7 | |||
| 6 | class Actor | 8 | class Actor |
| 7 | : public PixmapItem | 9 | : public PixmapItem |
| 8 | { | 10 | { |
| @@ -15,18 +17,11 @@ public: | |||
| 15 | Down | 17 | Down |
| 16 | }; | 18 | }; |
| 17 | 19 | ||
| 18 | enum Type { | 20 | Actor(Color color, QGraphicsItem *parent = 0); |
| 19 | Player1 = 1, // red | ||
| 20 | Player2, // blue | ||
| 21 | Player3, // green | ||
| 22 | Player4, // yellow | ||
| 23 | }; | ||
| 24 | |||
| 25 | Actor(Type type, QGraphicsItem *parent = 0); | ||
| 26 | 21 | ||
| 27 | private: | 22 | private: |
| 28 | QPixmap m_pix; | 23 | QPixmap m_pix; |
| 29 | Type m_type; | 24 | Color m_color; |
| 30 | Movement m_direction; | 25 | Movement m_direction; |
| 31 | }; | 26 | }; |
| 32 | 27 | ||
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp index d5435f3..4240dd4 100644 --- a/pacman-c++/block.cpp +++ b/pacman-c++/block.cpp | |||
| @@ -1,12 +1,17 @@ | |||
| 1 | #include "block.h" | 1 | #include "block.h" |
| 2 | 2 | ||
| 3 | #include <Qt> | 3 | #include <QtGui> |
| 4 | 4 | ||
| 5 | Block::Block(Actor::Type type) | 5 | #include "constants.h" |
| 6 | |||
| 7 | std::map<Color, QPixmap> Block::m_pixmaps; | ||
| 8 | |||
| 9 | Block::Block(Color color) | ||
| 6 | { | 10 | { |
| 7 | if (m_pixmaps.find(type) == m_pixmaps.end()) { | 11 | if (m_pixmaps.find(color) == m_pixmaps.end()) { |
| 8 | QString pixmapName = ":/" + QString("block%1").arg(type); | 12 | QString pixmapName = ":/" + QString("block%1").arg(color); |
| 9 | m_pixmaps[type] = QPixmap( pixmapName ); | 13 | m_pixmaps[color] = QPixmap( pixmapName ); |
| 10 | } | 14 | } |
| 11 | setPixmap( m_pixmaps.find(type)->second ); | 15 | setPixmap( m_pixmaps.find(color)->second ); |
| 16 | qDebug() << "loading block w color: " << color; | ||
| 12 | } | 17 | } |
diff --git a/pacman-c++/block.h b/pacman-c++/block.h index 1e76aa9..f19b590 100644 --- a/pacman-c++/block.h +++ b/pacman-c++/block.h | |||
| @@ -1,20 +1,22 @@ | |||
| 1 | #ifndef BLOCK_H | 1 | #ifndef BLOCK_H |
| 2 | #define BLOCK_H | 2 | #define BLOCK_H |
| 3 | 3 | ||
| 4 | #include <map> | ||
| 5 | 4 | ||
| 6 | #include "pixmapitem.h" | 5 | #include "pixmapitem.h" |
| 7 | #include "actor.h" | 6 | |
| 7 | #include <map> | ||
| 8 | |||
| 9 | #include "constants.h" | ||
| 8 | 10 | ||
| 9 | 11 | ||
| 10 | class Block | 12 | class Block |
| 11 | : public PixmapItem { | 13 | : public PixmapItem { |
| 12 | public: | 14 | public: |
| 13 | Block(Actor::Type type); | 15 | Block(Color color); |
| 14 | 16 | ||
| 15 | private: | 17 | private: |
| 16 | // map for saving QPixmaps for reuse | 18 | // map for saving QPixmaps for reuse |
| 17 | std::map<Actor::Type, QPixmap> m_pixmaps; | 19 | static std::map<Color, QPixmap> m_pixmaps; |
| 18 | 20 | ||
| 19 | }; | 21 | }; |
| 20 | 22 | ||
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp new file mode 100644 index 0000000..67c8250 --- /dev/null +++ b/pacman-c++/bonuspoint.cpp | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #include "bonuspoint.h" | ||
| 2 | |||
| 3 | namespace { | ||
| 4 | QPixmap *pixmap = 0; | ||
| 5 | } | ||
| 6 | |||
| 7 | BonusPoint::BonusPoint() | ||
| 8 | { | ||
| 9 | if (pixmap == 0) { | ||
| 10 | pixmap = new QPixmap(":/cherry"); | ||
| 11 | } | ||
| 12 | setPixmap(*pixmap); | ||
| 13 | } | ||
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h new file mode 100644 index 0000000..cfae4b4 --- /dev/null +++ b/pacman-c++/bonuspoint.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef BONUSPOINT_H | ||
| 2 | #define BONUSPOINT_H | ||
| 3 | |||
| 4 | #include "pixmapitem.h" | ||
| 5 | |||
| 6 | class BonusPoint | ||
| 7 | : public PixmapItem | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | BonusPoint(); | ||
| 11 | private: | ||
| 12 | |||
| 13 | }; | ||
| 14 | |||
| 15 | #endif // BONUSPOINT_H \ No newline at end of file | ||
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index 278f2b3..a8907b1 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h | |||
| @@ -4,20 +4,26 @@ | |||
| 4 | const unsigned int map_size[2] = { 20, 20 }; | 4 | const unsigned int map_size[2] = { 20, 20 }; |
| 5 | const unsigned int field_size[2] = { 16, 16 }; | 5 | const unsigned int field_size[2] = { 16, 16 }; |
| 6 | 6 | ||
| 7 | enum Color { | ||
| 8 | noColor = 0, | ||
| 9 | red = (1 << 0), | ||
| 10 | blue = (1 << 1), | ||
| 11 | green = (1 << 2), | ||
| 12 | }; | ||
| 13 | |||
| 7 | // constants for data transmission to client | 14 | // constants for data transmission to client |
| 8 | namespace transmission { | 15 | namespace transmission { |
| 9 | 16 | ||
| 10 | typedef unsigned int field_t; | 17 | typedef unsigned int field_t; |
| 11 | const field_t red = (1 << 0); | 18 | typedef unsigned int mask_t; |
| 12 | const field_t blue = (1 << 1); | ||
| 13 | const field_t green = (1 << 2); | ||
| 14 | 19 | ||
| 15 | const field_t box = (1 << 3); | 20 | const field_t block = (1 << 3); |
| 16 | const field_t foo = (1 << 4); | 21 | const field_t bonuspoint = (1 << 4); |
| 22 | |||
| 23 | const mask_t color_mask = noColor | red | blue | green; | ||
| 24 | const mask_t type_mask = block | bonuspoint; | ||
| 17 | 25 | ||
| 18 | typedef field_t** map_t; | 26 | typedef field_t** map_t; |
| 19 | } | 27 | } |
| 20 | 28 | ||
| 21 | |||
| 22 | |||
| 23 | #endif // CONSTANTS_H \ No newline at end of file | 29 | #endif // CONSTANTS_H \ No newline at end of file |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 982c809..72d9c8a 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | #include "actor.h" | 3 | #include "actor.h" |
| 4 | #include "block.h" | 4 | #include "block.h" |
| 5 | #include "bonuspoint.h" | ||
| 6 | #include "constants.h" | ||
| 5 | 7 | ||
| 6 | MainWidget::MainWidget() { | 8 | MainWidget::MainWidget() { |
| 7 | 9 | ||
| @@ -26,8 +28,62 @@ MainWidget::MainWidget() { | |||
| 26 | loadDummyMap(); | 28 | loadDummyMap(); |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 31 | // temporary | ||
| 32 | transmission::map_t createDummyMap() { | ||
| 33 | transmission::map_t map; | ||
| 34 | map = new transmission::field_t*[map_size[0]]; | ||
| 35 | for (unsigned int i=0; i<map_size[0]; ++i) { | ||
| 36 | map[i] = new transmission::field_t[map_size[1]]; | ||
| 37 | } | ||
| 38 | for (unsigned int x=0; x<map_size[0]; ++x) { | ||
| 39 | for (unsigned int y=0; y<map_size[1]; ++y) { | ||
| 40 | transmission::field_t &cur = map[x][y]; | ||
| 41 | cur = 0; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | map[4][3] |= green; | ||
| 46 | map[4][3] |= transmission::block; | ||
| 47 | |||
| 48 | map[5][3] |= noColor; | ||
| 49 | map[5][3] |= transmission::block; | ||
| 50 | map[6][3] |= noColor; | ||
| 51 | map[6][3] |= transmission::block; | ||
| 52 | map[7][3] |= red; | ||
| 53 | map[7][3] |= transmission::block; | ||
| 54 | |||
| 55 | map[7][5] |= transmission::bonuspoint; | ||
| 56 | |||
| 57 | return map; | ||
| 58 | } | ||
| 29 | void MainWidget::loadDummyMap() | 59 | void MainWidget::loadDummyMap() |
| 30 | { | 60 | { |
| 61 | transmission::map_t map = createDummyMap(); | ||
| 62 | |||
| 63 | for (unsigned int x=0; x<map_size[0]; ++x) { | ||
| 64 | for (unsigned int y=0; y<map_size[1]; ++y) { | ||
| 65 | const transmission::field_t &cur = map[x][y]; | ||
| 66 | if (cur == 0) { | ||
| 67 | continue; | ||
| 68 | } | ||
| 69 | qDebug() << "not 0 at " << x << "," << y << ":" << cur; | ||
| 70 | |||
| 71 | Color color = static_cast<Color>(cur & transmission::color_mask); | ||
| 72 | qDebug() << "col " << color; | ||
| 73 | |||
| 74 | PixmapItem *item = 0; | ||
| 75 | if (cur & transmission::block) { | ||
| 76 | item = new Block(color); | ||
| 77 | } else if (cur & transmission::bonuspoint) { | ||
| 78 | item = new BonusPoint(); | ||
| 79 | } | ||
| 80 | Q_ASSERT(item != 0); | ||
| 81 | scene->addItem(item); | ||
| 82 | item->setPos( mapPositionToCoord(x, y) ); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | /* | ||
| 31 | Actor *actor3 = new Actor(Actor::Player3); | 87 | Actor *actor3 = new Actor(Actor::Player3); |
| 32 | scene->addItem(actor3); | 88 | scene->addItem(actor3); |
| 33 | actor3->setPos(140, 100); | 89 | actor3->setPos(140, 100); |
| @@ -37,5 +93,10 @@ void MainWidget::loadDummyMap() | |||
| 37 | scene->addItem(b); | 93 | scene->addItem(b); |
| 38 | b->setPos( 100 + i*16, 200); | 94 | b->setPos( 100 + i*16, 200); |
| 39 | } | 95 | } |
| 96 | */ | ||
| 97 | } | ||
| 40 | 98 | ||
| 99 | QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) | ||
| 100 | { | ||
| 101 | return QPoint(x * field_size[0], y * field_size[1]); | ||
| 41 | } | 102 | } |
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index d1ec761..4cdb3b8 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | #include <QtGui> | 4 | #include <QtGui> |
| 5 | 5 | ||
| 6 | #include "constants.h" | ||
| 7 | |||
| 6 | class MainWidget | 8 | class MainWidget |
| 7 | : public QWidget | 9 | : public QWidget |
| 8 | { | 10 | { |
| @@ -14,6 +16,9 @@ public: | |||
| 14 | private: | 16 | private: |
| 15 | void loadDummyMap(); | 17 | void loadDummyMap(); |
| 16 | 18 | ||
| 19 | // data conversion | ||
| 20 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); | ||
| 21 | |||
| 17 | QGraphicsScene *scene; | 22 | QGraphicsScene *scene; |
| 18 | }; | 23 | }; |
| 19 | 24 | ||
diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index 1add92e..954ff77 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro | |||
| @@ -4,12 +4,14 @@ SOURCES += pixmapitem.cpp \ | |||
| 4 | animationmanager.cpp \ | 4 | animationmanager.cpp \ |
| 5 | block.cpp \ | 5 | block.cpp \ |
| 6 | client.cpp \ | 6 | client.cpp \ |
| 7 | bonuspoint.cpp \ | ||
| 7 | mainwidget.cpp | 8 | mainwidget.cpp |
| 8 | HEADERS += pixmapitem.h \ | 9 | HEADERS += pixmapitem.h \ |
| 9 | actor.h \ | 10 | actor.h \ |
| 10 | animationmanager.h \ | 11 | animationmanager.h \ |
| 11 | block.h \ | 12 | block.h \ |
| 12 | client.h \ | 13 | client.h \ |
| 14 | bonuspoint.h \ | ||
| 13 | mainwidget.h | 15 | mainwidget.h |
| 14 | RESOURCES += pacman.qrc | 16 | RESOURCES += pacman.qrc |
| 15 | 17 | ||
diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc index 6a7fefb..1d82831 100644 --- a/pacman-c++/pacman.qrc +++ b/pacman-c++/pacman.qrc | |||
| @@ -2,8 +2,12 @@ | |||
| 2 | <qresource prefix="/"> | 2 | <qresource prefix="/"> |
| 3 | <file alias="actor1">pics/actor1.png</file> | 3 | <file alias="actor1">pics/actor1.png</file> |
| 4 | <file alias="actor2">pics/actor2.png</file> | 4 | <file alias="actor2">pics/actor2.png</file> |
| 5 | <file alias="actor3">pics/actor3.png</file> | ||
| 6 | <file alias="actor4">pics/actor4.png</file> | 5 | <file alias="actor4">pics/actor4.png</file> |
| 6 | <file alias="actor8">pics/actor8.png</file> | ||
| 7 | <file alias="block0">pics/block0.png</file> | ||
| 7 | <file alias="block1">pics/block1.png</file> | 8 | <file alias="block1">pics/block1.png</file> |
| 9 | <file alias="block2">pics/block2.png</file> | ||
| 10 | <file alias="block4">pics/block4.png</file> | ||
| 11 | <file alias="cherry">pics/cherry.png</file> | ||
| 8 | </qresource> | 12 | </qresource> |
| 9 | </RCC> | 13 | </RCC> |
diff --git a/pacman-c++/pics/actor3.png b/pacman-c++/pics/actor3.png deleted file mode 100644 index 99e025c..0000000 --- a/pacman-c++/pics/actor3.png +++ /dev/null | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/actor4.png b/pacman-c++/pics/actor4.png index 9947f9b..99e025c 100644 --- a/pacman-c++/pics/actor4.png +++ b/pacman-c++/pics/actor4.png | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/actor8.png b/pacman-c++/pics/actor8.png new file mode 100644 index 0000000..9947f9b --- /dev/null +++ b/pacman-c++/pics/actor8.png | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/block0.png b/pacman-c++/pics/block0.png new file mode 100644 index 0000000..7f93087 --- /dev/null +++ b/pacman-c++/pics/block0.png | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/block2.png b/pacman-c++/pics/block2.png new file mode 100644 index 0000000..cf1a043 --- /dev/null +++ b/pacman-c++/pics/block2.png | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/block4.png b/pacman-c++/pics/block4.png new file mode 100644 index 0000000..13eb22d --- /dev/null +++ b/pacman-c++/pics/block4.png | |||
| Binary files differ | |||
diff --git a/pacman-c++/pics/cherry.png b/pacman-c++/pics/cherry.png new file mode 100644 index 0000000..6aff6de --- /dev/null +++ b/pacman-c++/pics/cherry.png | |||
| Binary files differ | |||
