diff options
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/block.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/block.h | 2 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.h | 2 | ||||
| -rw-r--r-- | pacman-c++/constants.h | 13 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 56 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 9 |
7 files changed, 62 insertions, 26 deletions
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp index 4240dd4..9d57578 100644 --- a/pacman-c++/block.cpp +++ b/pacman-c++/block.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | std::map<Color, QPixmap> Block::m_pixmaps; | 7 | std::map<Color, QPixmap> Block::m_pixmaps; |
| 8 | 8 | ||
| 9 | Block::Block(Color color) | 9 | Block::Block(Color color, QGraphicsItem *parent) |
| 10 | : PixmapItem(parent) | ||
| 10 | { | 11 | { |
| 11 | if (m_pixmaps.find(color) == m_pixmaps.end()) { | 12 | if (m_pixmaps.find(color) == m_pixmaps.end()) { |
| 12 | QString pixmapName = ":/" + QString("block%1").arg(color); | 13 | QString pixmapName = ":/" + QString("block%1").arg(color); |
diff --git a/pacman-c++/block.h b/pacman-c++/block.h index f19b590..25f4f08 100644 --- a/pacman-c++/block.h +++ b/pacman-c++/block.h | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | class Block | 12 | class Block |
| 13 | : public PixmapItem { | 13 | : public PixmapItem { |
| 14 | public: | 14 | public: |
| 15 | Block(Color color); | 15 | Block(Color color, QGraphicsItem *parent=0); |
| 16 | 16 | ||
| 17 | private: | 17 | private: |
| 18 | // map for saving QPixmaps for reuse | 18 | // map for saving QPixmaps for reuse |
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 67c8250..efff263 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp | |||
| @@ -4,7 +4,8 @@ namespace { | |||
| 4 | QPixmap *pixmap = 0; | 4 | QPixmap *pixmap = 0; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | BonusPoint::BonusPoint() | 7 | BonusPoint::BonusPoint(QGraphicsItem *parent) |
| 8 | : PixmapItem(parent) | ||
| 8 | { | 9 | { |
| 9 | if (pixmap == 0) { | 10 | if (pixmap == 0) { |
| 10 | pixmap = new QPixmap(":/cherry"); | 11 | pixmap = new QPixmap(":/cherry"); |
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h index cfae4b4..ebd1615 100644 --- a/pacman-c++/bonuspoint.h +++ b/pacman-c++/bonuspoint.h | |||
| @@ -7,7 +7,7 @@ class BonusPoint | |||
| 7 | : public PixmapItem | 7 | : public PixmapItem |
| 8 | { | 8 | { |
| 9 | public: | 9 | public: |
| 10 | BonusPoint(); | 10 | BonusPoint(QGraphicsItem *parent=0); |
| 11 | private: | 11 | private: |
| 12 | 12 | ||
| 13 | }; | 13 | }; |
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index a8907b1..088fcb8 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h | |||
| @@ -17,13 +17,20 @@ namespace transmission { | |||
| 17 | typedef unsigned int field_t; | 17 | typedef unsigned int field_t; |
| 18 | typedef unsigned int mask_t; | 18 | typedef unsigned int mask_t; |
| 19 | 19 | ||
| 20 | const field_t block = (1 << 3); | 20 | const field_t block = (1 << 3); |
| 21 | const field_t bonuspoint = (1 << 4); | 21 | const field_t bonuspoint = (1 << 4); |
| 22 | const field_t pacman = (1 << 5); | ||
| 23 | |||
| 24 | const field_t direction_left = (1 << 6); | ||
| 25 | const field_t direction_right = (1 << 7); | ||
| 26 | const field_t direction_up = (1 << 8); | ||
| 27 | const field_t direction_down = (1 << 9); | ||
| 22 | 28 | ||
| 23 | const mask_t color_mask = noColor | red | blue | green; | 29 | const mask_t color_mask = noColor | red | blue | green; |
| 24 | const mask_t type_mask = block | bonuspoint; | 30 | const mask_t type_mask = block | bonuspoint; |
| 31 | const mask_t direction_mask = direction_left | direction_right | direction_up | direction_down; | ||
| 25 | 32 | ||
| 26 | typedef field_t** map_t; | 33 | typedef field_t** map_t; |
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | #endif // CONSTANTS_H \ No newline at end of file | 36 | #endif // CONSTANTS_H |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 72d9c8a..8dd1875 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -12,10 +12,10 @@ MainWidget::MainWidget() { | |||
| 12 | QLabel *lbl = new QLabel("da kommt da spielstand hin", this); | 12 | QLabel *lbl = new QLabel("da kommt da spielstand hin", this); |
| 13 | layout->addWidget(lbl); | 13 | layout->addWidget(lbl); |
| 14 | 14 | ||
| 15 | scene = new QGraphicsScene(0, 0, 500, 500, this); | 15 | m_scene = new QGraphicsScene(0, 0, 500, 500, this); |
| 16 | scene->setBackgroundBrush(Qt::black); | 16 | m_scene->setBackgroundBrush(Qt::black); |
| 17 | 17 | ||
| 18 | QGraphicsView *window = new QGraphicsView(scene, this); | 18 | QGraphicsView *window = new QGraphicsView(m_scene, this); |
| 19 | window->setFrameStyle(0); | 19 | window->setFrameStyle(0); |
| 20 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); | 20 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 21 | window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 21 | window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| @@ -54,6 +54,9 @@ transmission::map_t createDummyMap() { | |||
| 54 | 54 | ||
| 55 | map[7][5] |= transmission::bonuspoint; | 55 | map[7][5] |= transmission::bonuspoint; |
| 56 | 56 | ||
| 57 | map[5][5] |= blue; | ||
| 58 | map[5][5] |= transmission::pacman; | ||
| 59 | |||
| 57 | return map; | 60 | return map; |
| 58 | } | 61 | } |
| 59 | void MainWidget::loadDummyMap() | 62 | void MainWidget::loadDummyMap() |
| @@ -76,27 +79,44 @@ void MainWidget::loadDummyMap() | |||
| 76 | item = new Block(color); | 79 | item = new Block(color); |
| 77 | } else if (cur & transmission::bonuspoint) { | 80 | } else if (cur & transmission::bonuspoint) { |
| 78 | item = new BonusPoint(); | 81 | item = new BonusPoint(); |
| 82 | } else if (cur & transmission::pacman) { | ||
| 83 | Actor *actor = 0; | ||
| 84 | ActorMap::iterator it = m_actors.find(color); | ||
| 85 | if (it != m_actors.end()) { | ||
| 86 | actor = it->second; | ||
| 87 | } else { | ||
| 88 | qDebug() << "new actor of col" << color; | ||
| 89 | actor = new Actor(color); | ||
| 90 | m_actors[color] = actor; | ||
| 91 | m_scene->addItem(actor); | ||
| 92 | actor->setPos( mapPositionToCoord(x, y) ); | ||
| 93 | } | ||
| 94 | Actor::Movement direction; | ||
| 95 | switch (cur & transmission::direction_mask) { | ||
| 96 | case transmission::direction_left: direction = Actor::Left; break; | ||
| 97 | case transmission::direction_right: direction = Actor::Right; break; | ||
| 98 | case transmission::direction_up: direction = Actor::Up; break; | ||
| 99 | case transmission::direction_down: direction = Actor::Down; break; | ||
| 100 | default: Q_ASSERT(false); | ||
| 101 | } | ||
| 102 | //actor->move(direction, mapPositionToCoord(x, y); | ||
| 103 | } else { Q_ASSERT(false); } | ||
| 104 | |||
| 105 | if(item != 0) { | ||
| 106 | m_scene->addItem(item); | ||
| 107 | item->setPos( mapPositionToCoord(x, y) ); | ||
| 79 | } | 108 | } |
| 80 | Q_ASSERT(item != 0); | ||
| 81 | scene->addItem(item); | ||
| 82 | item->setPos( mapPositionToCoord(x, y) ); | ||
| 83 | } | 109 | } |
| 84 | } | 110 | } |
| 85 | |||
| 86 | /* | ||
| 87 | Actor *actor3 = new Actor(Actor::Player3); | ||
| 88 | scene->addItem(actor3); | ||
| 89 | actor3->setPos(140, 100); | ||
| 90 | |||
| 91 | for (unsigned int i=0; i<20; ++i) { | ||
| 92 | Block *b = new Block(Actor::Player1); | ||
| 93 | scene->addItem(b); | ||
| 94 | b->setPos( 100 + i*16, 200); | ||
| 95 | } | ||
| 96 | */ | ||
| 97 | } | 111 | } |
| 98 | 112 | ||
| 99 | QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) | 113 | QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) |
| 100 | { | 114 | { |
| 101 | return QPoint(x * field_size[0], y * field_size[1]); | 115 | return QPoint(x * field_size[0], y * field_size[1]); |
| 102 | } | 116 | } |
| 117 | |||
| 118 | Actor* MainWidget::getActor(Color color) | ||
| 119 | { | ||
| 120 | |||
| 121 | } | ||
| 122 | |||
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index 4cdb3b8..93af229 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -2,9 +2,12 @@ | |||
| 2 | #define MAINWIDGET_H | 2 | #define MAINWIDGET_H |
| 3 | 3 | ||
| 4 | #include <QtGui> | 4 | #include <QtGui> |
| 5 | #include <map> | ||
| 5 | 6 | ||
| 6 | #include "constants.h" | 7 | #include "constants.h" |
| 7 | 8 | ||
| 9 | class Actor; | ||
| 10 | |||
| 8 | class MainWidget | 11 | class MainWidget |
| 9 | : public QWidget | 12 | : public QWidget |
| 10 | { | 13 | { |
| @@ -19,7 +22,11 @@ private: | |||
| 19 | // data conversion | 22 | // data conversion |
| 20 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); | 23 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); |
| 21 | 24 | ||
| 22 | QGraphicsScene *scene; | 25 | QGraphicsScene *m_scene; |
| 26 | |||
| 27 | Actor *getActor(Color); | ||
| 28 | typedef std::map<Color, Actor*> ActorMap; | ||
| 29 | ActorMap m_actors; | ||
| 23 | }; | 30 | }; |
| 24 | 31 | ||
| 25 | #endif // MAINWIDGET_H \ No newline at end of file | 32 | #endif // MAINWIDGET_H \ No newline at end of file |
