diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 56 |
1 files changed, 38 insertions, 18 deletions
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 | |||
