summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
authortotycro <totycro@unknown-horizons.org>2011-04-04 19:20:32 +0200
committertotycro <totycro@unknown-horizons.org>2011-04-04 19:20:32 +0200
commit0693d00da48d795c7ccb658e8b69fe17f4427337 (patch)
treec750928f839ebf242fe9fdfefec904c921889931 /pacman-c++
parentf3f2cc63376019aaf9e8dd807ab674f92908123c (diff)
downloadfoop-0693d00da48d795c7ccb658e8b69fe17f4427337.tar.gz
foop-0693d00da48d795c7ccb658e8b69fe17f4427337.tar.bz2
foop-0693d00da48d795c7ccb658e8b69fe17f4427337.zip
Cache QPixmaps for Blocks
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/block.cpp6
-rw-r--r--pacman-c++/block.h7
-rw-r--r--pacman-c++/main.cpp10
3 files changed, 21 insertions, 2 deletions
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index 11c2a32..d5435f3 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -4,5 +4,9 @@
4 4
5Block::Block(Actor::Type type) 5Block::Block(Actor::Type type)
6{ 6{
7 setPixmap(QPixmap(":/" + QString("block%1").arg(type))); 7 if (m_pixmaps.find(type) == m_pixmaps.end()) {
8 QString pixmapName = ":/" + QString("block%1").arg(type);
9 m_pixmaps[type] = QPixmap( pixmapName );
10 }
11 setPixmap( m_pixmaps.find(type)->second );
8} 12}
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index 25a331c..1e76aa9 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -1,14 +1,21 @@
1#ifndef BLOCK_H 1#ifndef BLOCK_H
2#define BLOCK_H 2#define BLOCK_H
3 3
4#include <map>
5
4#include "pixmapitem.h" 6#include "pixmapitem.h"
5#include "actor.h" 7#include "actor.h"
6 8
9
7class Block 10class Block
8 : public PixmapItem { 11 : public PixmapItem {
9public: 12public:
10 Block(Actor::Type type); 13 Block(Actor::Type type);
11 14
15 private:
16 // map for saving QPixmaps for reuse
17 std::map<Actor::Type, QPixmap> m_pixmaps;
18
12}; 19};
13 20
14#endif // BLOCK_H 21#endif // BLOCK_H
diff --git a/pacman-c++/main.cpp b/pacman-c++/main.cpp
index ed347fe..a34ff97 100644
--- a/pacman-c++/main.cpp
+++ b/pacman-c++/main.cpp
@@ -29,9 +29,17 @@ int main(int argc, char **argv)
29 scene.addItem(actor4); 29 scene.addItem(actor4);
30 actor4->setPos(160, 100); 30 actor4->setPos(160, 100);
31 31
32 /*
32 Block *block1 = new Block(Actor::Player1); 33 Block *block1 = new Block(Actor::Player1);
33 scene.addItem(block1); 34 scene.addItem(block1);
34 block1->setPos(200, 200); 35 block1->setPos(200, 200);
36 */
37
38 for (unsigned int i=0; i<20; ++i) {
39 Block *b = new Block(Actor::Player1);
40 scene.addItem(b);
41 b->setPos( 100 + i*16, 200);
42 }
35 43
36 QGraphicsView *window = new QGraphicsView(&scene); 44 QGraphicsView *window = new QGraphicsView(&scene);
37 window->setFrameStyle(0); 45 window->setFrameStyle(0);
@@ -45,7 +53,7 @@ int main(int argc, char **argv)
45 mainWin.show(); 53 mainWin.show();
46 54
47 Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, 55 Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
48 Phonon::MediaSource("/home/manuel/uni/foop/pacman-c++/sound/intro.wav")); 56 Phonon::MediaSource("/home/totycro/stud/foop/repo/pacman-c++/sound/intro.wav"));
49 music->play(); 57 music->play();
50 58
51 qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); 59 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));