diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index cc85416..90d31b2 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -5,8 +5,8 @@ | |||
| 5 | #include "bonuspoint.h" | 5 | #include "bonuspoint.h" |
| 6 | #include "constants.h" | 6 | #include "constants.h" |
| 7 | 7 | ||
| 8 | MainWidget::MainWidget() { | 8 | MainWidget::MainWidget() |
| 9 | 9 | { | |
| 10 | QVBoxLayout *layout = new QVBoxLayout(this); | 10 | QVBoxLayout *layout = new QVBoxLayout(this); |
| 11 | 11 | ||
| 12 | QLabel *lbl = new QLabel("da kommt da spielstand hin", this); | 12 | QLabel *lbl = new QLabel("da kommt da spielstand hin", this); |
| @@ -29,14 +29,17 @@ MainWidget::MainWidget() { | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | // temporary | 31 | // temporary |
| 32 | transmission::map_t createDummyMap() { | 32 | transmission::map_t createDummyMap() |
| 33 | { | ||
| 33 | transmission::map_t map; | 34 | transmission::map_t map; |
| 34 | map = new transmission::field_t*[map_size[0]]; | 35 | map = new transmission::field_t*[map_size[0]]; |
| 35 | for (unsigned int i=0; i<map_size[0]; ++i) { | 36 | for (unsigned int i = 0; i < map_size[0]; ++i) |
| 36 | map[i] = new transmission::field_t[map_size[1]]; | 37 | map[i] = new transmission::field_t[map_size[1]]; |
| 37 | } | 38 | |
| 38 | for (unsigned int x=0; x<map_size[0]; ++x) { | 39 | for (unsigned int x = 0; x < map_size[0]; ++x) |
| 39 | for (unsigned int y=0; y<map_size[1]; ++y) { | 40 | { |
| 41 | for (unsigned int y = 0; y < map_size[1]; ++y) | ||
| 42 | { | ||
| 40 | transmission::field_t &cur = map[x][y]; | 43 | transmission::field_t &cur = map[x][y]; |
| 41 | cur = 0; | 44 | cur = 0; |
| 42 | } | 45 | } |
| @@ -60,52 +63,72 @@ transmission::map_t createDummyMap() { | |||
| 60 | 63 | ||
| 61 | return map; | 64 | return map; |
| 62 | } | 65 | } |
| 66 | |||
| 63 | void MainWidget::loadDummyMap() | 67 | void MainWidget::loadDummyMap() |
| 64 | { | 68 | { |
| 65 | transmission::map_t map = createDummyMap(); | 69 | transmission::map_t map = createDummyMap(); |
| 66 | 70 | ||
| 67 | for (unsigned int x=0; x<map_size[0]; ++x) { | 71 | for (unsigned int x = 0; x < map_size[0]; ++x) |
| 68 | for (unsigned int y=0; y<map_size[1]; ++y) { | 72 | { |
| 73 | for (unsigned int y = 0; y < map_size[1]; ++y) | ||
| 74 | { | ||
| 69 | const transmission::field_t &cur = map[x][y]; | 75 | const transmission::field_t &cur = map[x][y]; |
| 70 | if (cur == 0) { | 76 | if (cur == 0) |
| 71 | continue; | 77 | continue; |
| 72 | } | 78 | qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; |
| 73 | qDebug() << "not 0 at " << x << "," << y << ":" << cur; | ||
| 74 | 79 | ||
| 75 | Color color = static_cast<Color>(cur & transmission::color_mask); | 80 | Color color = static_cast<Color>(cur & transmission::color_mask); |
| 76 | qDebug() << "col " << color; | 81 | qDebug() << "col=" << color; |
| 77 | 82 | ||
| 78 | PixmapItem *item = 0; | 83 | PixmapItem *item = 0; |
| 79 | if (cur & transmission::block) { | 84 | if (cur & transmission::block) |
| 80 | item = new Block(color); | 85 | item = new Block(color); |
| 81 | } else if (cur & transmission::bonuspoint) { | 86 | else if (cur & transmission::bonuspoint) |
| 82 | item = new BonusPoint(); | 87 | item = new BonusPoint(); |
| 83 | } else if (cur & transmission::pacman) { | 88 | else if (cur & transmission::pacman) |
| 89 | { | ||
| 84 | Actor *actor = 0; | 90 | Actor *actor = 0; |
| 85 | ActorMap::iterator it = m_actors.find(color); | 91 | ActorMap::iterator it = m_actors.find(color); |
| 86 | if (it != m_actors.end()) { | 92 | if (it != m_actors.end()) |
| 87 | actor = it->second; | 93 | actor = it->second; |
| 88 | } else { | 94 | else |
| 95 | { | ||
| 89 | qDebug() << "new actor of col" << color; | 96 | qDebug() << "new actor of col" << color; |
| 90 | actor = new Actor(color); | 97 | actor = new Actor(color); |
| 91 | m_actors[color] = actor; | 98 | m_actors[color] = actor; |
| 92 | m_scene->addItem(actor); | 99 | m_scene->addItem(actor); |
| 93 | actor->setPos( mapPositionToCoord(x, y) ); | 100 | actor->setPos(mapPositionToCoord(x, y)); |
| 94 | } | 101 | } |
| 102 | |||
| 95 | Actor::Movement direction; | 103 | Actor::Movement direction; |
| 96 | switch (cur & transmission::direction_mask) { | 104 | switch (cur & transmission::direction_mask) |
| 97 | case transmission::direction_left: direction = Actor::Left; break; | 105 | { |
| 98 | case transmission::direction_right: direction = Actor::Right; break; | 106 | case 0: |
| 99 | case transmission::direction_up: direction = Actor::Up; break; | 107 | break; |
| 100 | case transmission::direction_down: direction = Actor::Down; break; | 108 | case transmission::direction_left: |
| 101 | default: Q_ASSERT(false); | 109 | direction = Actor::Left; |
| 110 | break; | ||
| 111 | case transmission::direction_right: | ||
| 112 | direction = Actor::Right; | ||
| 113 | break; | ||
| 114 | case transmission::direction_up: | ||
| 115 | direction = Actor::Up; | ||
| 116 | break; | ||
| 117 | case transmission::direction_down: | ||
| 118 | direction = Actor::Down; | ||
| 119 | break; | ||
| 120 | default: | ||
| 121 | Q_ASSERT(false); | ||
| 102 | } | 122 | } |
| 103 | //actor->move(direction, mapPositionToCoord(x, y); | 123 | //actor->move(direction, mapPositionToCoord(x, y); |
| 104 | } else { Q_ASSERT(false); } | 124 | } |
| 105 | 125 | else | |
| 106 | if(item != 0) { | 126 | Q_ASSERT(false); |
| 127 | |||
| 128 | if(item != 0) | ||
| 129 | { | ||
| 107 | m_scene->addItem(item); | 130 | m_scene->addItem(item); |
| 108 | item->setPos( mapPositionToCoord(x, y) ); | 131 | item->setPos(mapPositionToCoord(x, y)); |
| 109 | } | 132 | } |
| 110 | } | 133 | } |
| 111 | } | 134 | } |
