summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacman-c++/actor.cpp4
-rw-r--r--pacman-c++/block.cpp8
-rw-r--r--pacman-c++/block.h5
-rw-r--r--pacman-c++/constants.h8
-rw-r--r--pacman-c++/mainwidget.cpp31
-rw-r--r--pacman-c++/pacman.qrc1
-rw-r--r--pacman-c++/pics/block0.pngbin181 -> 479 bytes
-rw-r--r--pacman-c++/pics/block1.pngbin179 -> 453 bytes
-rw-r--r--pacman-c++/pics/block2.pngbin195 -> 476 bytes
-rw-r--r--pacman-c++/pics/block4.pngbin180 -> 452 bytes
-rw-r--r--pacman-c++/pics/block8.pngbin0 -> 471 bytes
11 files changed, 45 insertions, 12 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index cfd832c..9d35d47 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -35,8 +35,8 @@ Actor::Actor(Color::Color color, QGraphicsItem *parent)
35 for (int i = 0; i < 4; i++) 35 for (int i = 0; i < 4; i++)
36 { 36 {
37 PixmapItem *img = new PixmapItem(m_pix, this); 37 PixmapItem *img = new PixmapItem(m_pix, this);
38 int x = i * 20 + Constants::sprite_margin; 38 int x = i * Constants::sprite_offset + Constants::sprite_margin;
39 int y = m_direction * 20 + Constants::sprite_margin; 39 int y = m_direction * Constants::sprite_offset + Constants::sprite_margin;
40 img->setSprite(x, y, Constants::field_size.width, Constants::field_size.height); 40 img->setSprite(x, y, Constants::field_size.width, Constants::field_size.height);
41 img->setZValue(zValue()); 41 img->setZValue(zValue());
42 img->setVisible(false); 42 img->setVisible(false);
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index ccb7ade..7cb77cc 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -4,7 +4,7 @@
4 4
5QMap<Color::Color, QPixmap> Block::m_pixmaps; 5QMap<Color::Color, QPixmap> Block::m_pixmaps;
6 6
7Block::Block(Color::Color color, Neighbour neighbour, QGraphicsItem *parent) 7Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent)
8 : PixmapItem(parent) 8 : PixmapItem(parent)
9{ 9{
10 if (m_pixmaps.find(color) == m_pixmaps.end()) 10 if (m_pixmaps.find(color) == m_pixmaps.end())
@@ -13,5 +13,11 @@ Block::Block(Color::Color color, Neighbour neighbour, QGraphicsItem *parent)
13 m_pixmaps[color] = QPixmap(pixmapName); 13 m_pixmaps[color] = QPixmap(pixmapName);
14 } 14 }
15 setPixmap(m_pixmaps.find(color).value()); 15 setPixmap(m_pixmaps.find(color).value());
16 setNeighbours(neighbours);
16 qDebug() << "loading block w color: " << color; 17 qDebug() << "loading block w color: " << color;
17} 18}
19
20void Block::setNeighbours(unsigned int neighbours)
21{
22 setSprite(neighbours * Constants::sprite_offset, 0, Constants::field_size.width, Constants::field_size.height);
23}
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index 40bde51..29ddd23 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -8,6 +8,7 @@
8class Block 8class Block
9 : public PixmapItem 9 : public PixmapItem
10{ 10{
11public:
11 enum Neighbour { 12 enum Neighbour {
12 None = 0, 13 None = 0,
13 Left = (1 << 0), 14 Left = (1 << 0),
@@ -16,8 +17,8 @@ class Block
16 Down = (1 << 3) 17 Down = (1 << 3)
17 }; 18 };
18 19
19public: 20 Block(Color::Color color, unsigned int neighbours = None, QGraphicsItem *parent = 0);
20 Block(Color::Color color, Neighbour neighbour = None, QGraphicsItem *parent = 0); 21 void setNeighbours(unsigned int neighbours);
21 22
22private: 23private:
23 // map for saving QPixmaps for reuse 24 // map for saving QPixmaps for reuse
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h
index 34f29d0..46791be 100644
--- a/pacman-c++/constants.h
+++ b/pacman-c++/constants.h
@@ -2,15 +2,15 @@
2#define CONSTANTS_H 2#define CONSTANTS_H
3 3
4namespace Constants { 4namespace Constants {
5 5 const struct
6 const struct { 6 {
7 const unsigned int width, height; 7 const unsigned int width, height;
8 } field_size = { 16, 16 }, 8 } field_size = { 16, 16 },
9 map_size = { 20, 20 }, 9 map_size = { 20, 20 },
10 map_size_pixel = { field_size.width * map_size.width, 10 map_size_pixel = { field_size.width * map_size.width,
11 field_size.height * map_size.height}; 11 field_size.height * map_size.height};
12
13 const unsigned int sprite_margin = 2; 12 const unsigned int sprite_margin = 2;
13 const unsigned int sprite_offset = 20;
14} 14}
15 15
16namespace Color 16namespace Color
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index 809e786..fe1ba9c 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -25,8 +25,18 @@ Transmission::map_t createDummyMap()
25 map[0][0] |= Color::none ^ Transmission::block; 25 map[0][0] |= Color::none ^ Transmission::block;
26 map[0][1] |= Color::none ^ Transmission::block; 26 map[0][1] |= Color::none ^ Transmission::block;
27 map[0][2] |= Color::none ^ Transmission::block; 27 map[0][2] |= Color::none ^ Transmission::block;
28 map[0][3] |= Color::none ^ Transmission::block;
29 map[0][4] |= Color::none ^ Transmission::block;
30 map[0][5] |= Color::none ^ Transmission::block;
28 map[1][0] |= Color::none ^ Transmission::block; 31 map[1][0] |= Color::none ^ Transmission::block;
29 map[2][0] |= Color::none ^ Transmission::block; 32 map[2][0] |= Color::none ^ Transmission::block;
33 map[1][3] |= Color::none ^ Transmission::block;
34 map[2][3] |= Color::none ^ Transmission::block;
35 map[3][3] |= Color::none ^ Transmission::block;
36 map[2][4] |= Color::none ^ Transmission::block;
37 map[2][5] |= Color::none ^ Transmission::block;
38 map[2][2] |= Color::none ^ Transmission::block;
39 map[2][1] |= Color::none ^ Transmission::block;
30 40
31 map[4][3] |= Color::green ^ Transmission::block; 41 map[4][3] |= Color::green ^ Transmission::block;
32 42
@@ -124,9 +134,24 @@ void MainWidget::updateMap(const Transmission::map_t& map)
124 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); 134 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask);
125 qDebug() << "col=" << color; 135 qDebug() << "col=" << color;
126 136
127 PixmapItem *item = 0; 137 PixmapItem *item = NULL;
128 if (cur & Transmission::block) 138 if (cur & Transmission::block)
129 item = new Block(color); 139 {
140 unsigned int neighbours = Block::None;
141 // check left side
142 if (x > 0 && map[x - 1][y] & Transmission::block)
143 neighbours |= Block::Left;
144 // check right side
145 if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block)
146 neighbours |= Block::Right;
147 // check upside
148 if (y > 0 && map[x][y - 1] & Transmission::block)
149 neighbours |= Block::Up;
150 // check down side
151 if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block)
152 neighbours |= Block::Down;
153 item = new Block(color, neighbours);
154 }
130 else if (cur & Transmission::bonuspoint) 155 else if (cur & Transmission::bonuspoint)
131 item = new BonusPoint(); 156 item = new BonusPoint();
132 else if (cur & Transmission::pacman) 157 else if (cur & Transmission::pacman)
@@ -166,7 +191,7 @@ void MainWidget::updateMap(const Transmission::map_t& map)
166 else 191 else
167 Q_ASSERT(false); 192 Q_ASSERT(false);
168 193
169 if(item != 0) 194 if (item != NULL)
170 { 195 {
171 m_scene->addItem(item); 196 m_scene->addItem(item);
172 item->setPos(mapPositionToCoord(x, y)); 197 item->setPos(mapPositionToCoord(x, y));
diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc
index feb4276..e3aab92 100644
--- a/pacman-c++/pacman.qrc
+++ b/pacman-c++/pacman.qrc
@@ -10,5 +10,6 @@
10 <file alias="block4">pics/block4.png</file> 10 <file alias="block4">pics/block4.png</file>
11 <file alias="bonuspoints">pics/bonuspoints.png</file> 11 <file alias="bonuspoints">pics/bonuspoints.png</file>
12 <file alias="points">pics/points.png</file> 12 <file alias="points">pics/points.png</file>
13 <file alias="block8">pics/block8.png</file>
13 </qresource> 14 </qresource>
14</RCC> 15</RCC>
diff --git a/pacman-c++/pics/block0.png b/pacman-c++/pics/block0.png
index 7f93087..76bc4b7 100644
--- a/pacman-c++/pics/block0.png
+++ b/pacman-c++/pics/block0.png
Binary files differ
diff --git a/pacman-c++/pics/block1.png b/pacman-c++/pics/block1.png
index 4188bcf..99e8633 100644
--- a/pacman-c++/pics/block1.png
+++ b/pacman-c++/pics/block1.png
Binary files differ
diff --git a/pacman-c++/pics/block2.png b/pacman-c++/pics/block2.png
index cf1a043..963207e 100644
--- a/pacman-c++/pics/block2.png
+++ b/pacman-c++/pics/block2.png
Binary files differ
diff --git a/pacman-c++/pics/block4.png b/pacman-c++/pics/block4.png
index 13eb22d..6662de4 100644
--- a/pacman-c++/pics/block4.png
+++ b/pacman-c++/pics/block4.png
Binary files differ
diff --git a/pacman-c++/pics/block8.png b/pacman-c++/pics/block8.png
new file mode 100644
index 0000000..00fbd74
--- /dev/null
+++ b/pacman-c++/pics/block8.png
Binary files differ