diff options
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/block.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/block.h | 7 | ||||
| -rw-r--r-- | pacman-c++/main.cpp | 10 |
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 | ||
| 5 | Block::Block(Actor::Type type) | 5 | Block::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 | |||
| 7 | class Block | 10 | class Block |
| 8 | : public PixmapItem { | 11 | : public PixmapItem { |
| 9 | public: | 12 | public: |
| 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())); |
