summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-06 17:25:11 +0200
committermanuel <manuel@mausz.at>2011-04-06 17:25:11 +0200
commitf1a2d179062dfaf53f805395407a2c666eedf36e (patch)
tree353cacb1b63907e2ee1b72ce544c73f72560b597 /pacman-c++
parent7ca893e9357e9153ba35a248564c1134af0f1f54 (diff)
downloadfoop-f1a2d179062dfaf53f805395407a2c666eedf36e.tar.gz
foop-f1a2d179062dfaf53f805395407a2c666eedf36e.tar.bz2
foop-f1a2d179062dfaf53f805395407a2c666eedf36e.zip
make pictures color index based
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp2
-rw-r--r--pacman-c++/block.cpp5
-rw-r--r--pacman-c++/constants.h1
-rw-r--r--pacman-c++/main.cpp60
-rw-r--r--pacman-c++/mainwidget.cpp50
-rw-r--r--pacman-c++/pacman.qrc4
-rw-r--r--pacman-c++/pacman_old.pro15
-rw-r--r--pacman-c++/pics/actor3.pngbin0 -> 703 bytes
-rw-r--r--pacman-c++/pics/actor4.pngbin703 -> 706 bytes
-rw-r--r--pacman-c++/pics/actor8.pngbin706 -> 0 bytes
-rw-r--r--pacman-c++/pics/block3.pngbin0 -> 452 bytes
-rw-r--r--pacman-c++/pics/block4.pngbin452 -> 471 bytes
-rw-r--r--pacman-c++/pics/block8.pngbin471 -> 0 bytes
13 files changed, 34 insertions, 103 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index 9d35d47..cde20cd 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -14,7 +14,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal
14Actor::Actor(Color::Color color, QGraphicsItem *parent) 14Actor::Actor(Color::Color color, QGraphicsItem *parent)
15 : PixmapItem(parent), m_color(color), m_direction(Actor::None) 15 : PixmapItem(parent), m_color(color), m_direction(Actor::None)
16{ 16{
17 m_pix = ":/" + QString("actor%1").arg(m_color); 17 m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1);
18 // DON'T set any pixmap here. we've a pixmap in the animation 18 // DON'T set any pixmap here. we've a pixmap in the animation
19 //setPixmap(m_pix); 19 //setPixmap(m_pix);
20 // higher player "over" lower player 20 // higher player "over" lower player
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index 7cb77cc..c168c00 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -9,12 +9,13 @@ Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent)
9{ 9{
10 if (m_pixmaps.find(color) == m_pixmaps.end()) 10 if (m_pixmaps.find(color) == m_pixmaps.end())
11 { 11 {
12 QString pixmapName = ":/" + QString("block%1").arg(color); 12 unsigned int colid = (color == Color::none) ? 0 : (color >> 1) + 1;
13 QString pixmapName = ":/" + QString("block%1").arg(colid);
13 m_pixmaps[color] = QPixmap(pixmapName); 14 m_pixmaps[color] = QPixmap(pixmapName);
14 } 15 }
15 setPixmap(m_pixmaps.find(color).value()); 16 setPixmap(m_pixmaps.find(color).value());
16 setNeighbours(neighbours); 17 setNeighbours(neighbours);
17 qDebug() << "loading block w color: " << color; 18 //qDebug() << "loading block w color: " << color;
18} 19}
19 20
20void Block::setNeighbours(unsigned int neighbours) 21void Block::setNeighbours(unsigned int neighbours)
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h
index e009d40..019ac14 100644
--- a/pacman-c++/constants.h
+++ b/pacman-c++/constants.h
@@ -21,6 +21,7 @@ namespace Color
21 red = (1 << 0), 21 red = (1 << 0),
22 blue = (1 << 1), 22 blue = (1 << 1),
23 green = (1 << 2), 23 green = (1 << 2),
24 max = (1 << 2),
24 }; 25 };
25} 26}
26 27
diff --git a/pacman-c++/main.cpp b/pacman-c++/main.cpp
deleted file mode 100644
index 8c9232a..0000000
--- a/pacman-c++/main.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
1#include "actor.h"
2#include "block.h"
3
4#include <QtCore>
5#include <QtGui>
6#include <phonon/MediaObject>
7#include <phonon/AudioOutput>
8#include <phonon/BackendCapabilities>
9
10int main(int argc, char **argv)
11{
12 QApplication app(argc, argv);
13 app.setApplicationName("pacman");
14
15 QGraphicsScene scene(0, 0, 500, 500);
16 scene.setBackgroundBrush(Qt::black);
17
18 Actor *actor1 = new Actor(red);
19 scene.addItem(actor1);
20 actor1->setPos(100, 100);
21
22 Actor *actor2 = new Actor(blue);
23 scene.addItem(actor2);
24 actor2->setPos(120, 100);
25
26 Actor *actor3 = new Actor(green);
27 scene.addItem(actor3);
28 actor3->setPos(140, 100);
29
30 /*
31 Block *block1 = new Block(Actor::Player1);
32 scene.addItem(block1);
33 block1->setPos(200, 200);
34 */
35
36 for (unsigned int i=0; i<20; ++i) {
37 Block *b = new Block(red);
38 scene.addItem(b);
39 b->setPos( 100 + i*16, 200);
40 }
41
42 QGraphicsView *window = new QGraphicsView(&scene);
43 window->setFrameStyle(0);
44 window->setAlignment(Qt::AlignLeft | Qt::AlignTop);
45 window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
46 window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
47
48 QMainWindow mainWin;
49 mainWin.setCentralWidget(window);
50 mainWin.resize(500, 500);
51 mainWin.show();
52
53 Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
54 Phonon::MediaSource("/home/manuel/uni/foop/pacman-c++/sound/eating_cherry.ogg"));
55 music->play();
56
57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
58
59 return app.exec();
60}
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index ad11bf2..819088c 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -172,25 +172,23 @@ Transmission::map_t createDummyMap()
172 map[x + 3][y + 2] |= Color::none | Transmission::block; 172 map[x + 3][y + 2] |= Color::none | Transmission::block;
173 x += 5; 173 x += 5;
174 174
175 /* 175 map[15][16] |= Color::red | Transmission::block;
176 map[4][3] |= Color::green ^ Transmission::block; 176 map[15][17] |= Color::blue | Transmission::block;
177 177 map[15][18] |= Color::green | Transmission::block;
178 map[5][3] |= Color::none ^ Transmission::block; 178 map[15][19] |= Transmission::bonuspoint;
179 map[6][3] |= Color::none ^ Transmission::block;
180 map[7][3] |= Color::red ^ Transmission::block;
181
182 map[7][5] |= Transmission::bonuspoint;
183
184 map[5][5] |= Color::blue;
185 map[5][5] |= Transmission::pacman;
186 map[5][5] |= Transmission::direction_left;
187 179
188 map[7][5] |= Transmission::bonuspoint;*/ 180 map[15][15] |= Color::red;
189
190 map[15][15] |= Color::blue;
191 map[15][15] |= Transmission::pacman; 181 map[15][15] |= Transmission::pacman;
192 map[15][15] |= Transmission::direction_left; 182 map[15][15] |= Transmission::direction_left;
193 183
184 map[16][15] |= Color::blue;
185 map[16][15] |= Transmission::pacman;
186 map[16][15] |= Transmission::direction_left;
187
188 map[17][15] |= Color::green;
189 map[17][15] |= Transmission::pacman;
190 map[17][15] |= Transmission::direction_left;
191
194 return map; 192 return map;
195} 193}
196 194
@@ -250,11 +248,15 @@ void MainWidget::createGui()
250void MainWidget::updateScore() 248void MainWidget::updateScore()
251{ 249{
252 QMapIterator<Color::Color, Actor*> i(m_actors); 250 QMapIterator<Color::Color, Actor*> i(m_actors);
253 while (i.hasNext()) { 251 while (i.hasNext())
252 {
254 i.next(); 253 i.next();
255 int id = i.key() - 1; 254 int id = (i.key() >> 1);
256 if (id == 4) { 255 if (id > (Color::max >> 1))
257 id = 3; 256 {
257 /* player #4 isn't supported in score */
258 Q_ASSERT(false);
259 continue;
258 } 260 }
259 QLabel *turnPointsLbl = 261 QLabel *turnPointsLbl =
260 dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); 262 dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget());
@@ -274,10 +276,10 @@ void MainWidget::updateMap(const Transmission::map_t& map)
274 const Transmission::field_t &cur = map[x][y]; 276 const Transmission::field_t &cur = map[x][y];
275 if (cur == 0) 277 if (cur == 0)
276 continue; 278 continue;
277 qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; 279 //qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur;
278 280
279 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); 281 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask);
280 qDebug() << "col=" << color; 282 //qDebug() << "col=" << color;
281 283
282 PixmapItem* item = NULL; 284 PixmapItem* item = NULL;
283 if (cur & Transmission::block) 285 if (cur & Transmission::block)
@@ -303,7 +305,7 @@ void MainWidget::updateMap(const Transmission::map_t& map)
303 { 305 {
304 Actor *actor = m_actors.value(color, 0); 306 Actor *actor = m_actors.value(color, 0);
305 if (actor == 0) { // 0 entspricht NULL ;) 307 if (actor == 0) { // 0 entspricht NULL ;)
306 qDebug() << "new actor of col" << color; 308 //qDebug() << "new actor of col" << color;
307 actor = new Actor(color); 309 actor = new Actor(color);
308 m_actors[color] = actor; 310 m_actors[color] = actor;
309 m_scene->addItem(actor); 311 m_scene->addItem(actor);
@@ -342,13 +344,15 @@ void MainWidget::updateMap(const Transmission::map_t& map)
342 item->setPos(mapPositionToCoord(x, y)); 344 item->setPos(mapPositionToCoord(x, y));
343 PixmapItem* oldItem = visualMap[x][y]; 345 PixmapItem* oldItem = visualMap[x][y];
344 visualMap[x][y] = item; 346 visualMap[x][y] = item;
345 if (oldItem != NULL) { 347 if (oldItem != NULL)
348 {
346 m_scene->removeItem(item); 349 m_scene->removeItem(item);
347 delete oldItem; 350 delete oldItem;
348 } 351 }
349 } 352 }
350 } 353 }
351 } 354 }
355
352 updateScore(); 356 updateScore();
353} 357}
354 358
diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc
index e3aab92..6de5cc0 100644
--- a/pacman-c++/pacman.qrc
+++ b/pacman-c++/pacman.qrc
@@ -2,14 +2,14 @@
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>
5 <file alias="actor4">pics/actor4.png</file> 6 <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="block0">pics/block0.png</file>
8 <file alias="block1">pics/block1.png</file> 8 <file alias="block1">pics/block1.png</file>
9 <file alias="block2">pics/block2.png</file> 9 <file alias="block2">pics/block2.png</file>
10 <file alias="block3">pics/block3.png</file>
10 <file alias="block4">pics/block4.png</file> 11 <file alias="block4">pics/block4.png</file>
11 <file alias="bonuspoints">pics/bonuspoints.png</file> 12 <file alias="bonuspoints">pics/bonuspoints.png</file>
12 <file alias="points">pics/points.png</file> 13 <file alias="points">pics/points.png</file>
13 <file alias="block8">pics/block8.png</file>
14 </qresource> 14 </qresource>
15</RCC> 15</RCC>
diff --git a/pacman-c++/pacman_old.pro b/pacman-c++/pacman_old.pro
deleted file mode 100644
index c44e2c6..0000000
--- a/pacman-c++/pacman_old.pro
+++ /dev/null
@@ -1,15 +0,0 @@
1QT += phonon
2SOURCES += pixmapitem.cpp \
3 actor.cpp \
4 animationmanager.cpp \
5 block.cpp \
6 main.cpp
7HEADERS += pixmapitem.h \
8 actor.h \
9 animationmanager.h \
10 block.h \
11 constants.h
12RESOURCES += pacman.qrc
13
14OBJECTS_DIR = .obj
15MOC_DIR = .moc
diff --git a/pacman-c++/pics/actor3.png b/pacman-c++/pics/actor3.png
new file mode 100644
index 0000000..99e025c
--- /dev/null
+++ b/pacman-c++/pics/actor3.png
Binary files differ
diff --git a/pacman-c++/pics/actor4.png b/pacman-c++/pics/actor4.png
index 99e025c..9947f9b 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
deleted file mode 100644
index 9947f9b..0000000
--- a/pacman-c++/pics/actor8.png
+++ /dev/null
Binary files differ
diff --git a/pacman-c++/pics/block3.png b/pacman-c++/pics/block3.png
new file mode 100644
index 0000000..6662de4
--- /dev/null
+++ b/pacman-c++/pics/block3.png
Binary files differ
diff --git a/pacman-c++/pics/block4.png b/pacman-c++/pics/block4.png
index 6662de4..00fbd74 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
deleted file mode 100644
index 00fbd74..0000000
--- a/pacman-c++/pics/block8.png
+++ /dev/null
Binary files differ