diff options
| author | manuel <manuel@mausz.at> | 2011-04-07 04:02:55 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-07 04:02:55 +0200 |
| commit | 11a1b82636ab75cb9d002712a3e0f353ad6b2579 (patch) | |
| tree | 59c6c678ab20fa5bb373b85f8fe7775615e7f1d6 /pacman-c++/mainwidget.cpp | |
| parent | 52fb2da3c61a1942ebb26a64a4b9513b24d10087 (diff) | |
| download | foop-11a1b82636ab75cb9d002712a3e0f353ad6b2579.tar.gz foop-11a1b82636ab75cb9d002712a3e0f353ad6b2579.tar.bz2 foop-11a1b82636ab75cb9d002712a3e0f353ad6b2579.zip | |
add some sounds
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index d0b2ad7..73612af 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -1,11 +1,13 @@ | |||
| 1 | #include "mainwidget.h" | 1 | #include "mainwidget.h" |
| 2 | |||
| 3 | #include "actor.h" | 2 | #include "actor.h" |
| 4 | #include "block.h" | 3 | #include "block.h" |
| 5 | #include "bonuspoint.h" | 4 | #include "bonuspoint.h" |
| 6 | #include "point.h" | 5 | #include "point.h" |
| 7 | #include "constants.h" | 6 | #include "constants.h" |
| 8 | 7 | ||
| 8 | #include <phonon/MediaObject> | ||
| 9 | #include <QFile> | ||
| 10 | |||
| 9 | // temporary | 11 | // temporary |
| 10 | Transmission::map_t createDummyMap() | 12 | Transmission::map_t createDummyMap() |
| 11 | { | 13 | { |
| @@ -204,7 +206,7 @@ Transmission::map_t createDummyMap() | |||
| 204 | } | 206 | } |
| 205 | 207 | ||
| 206 | MainWidget::MainWidget() | 208 | MainWidget::MainWidget() |
| 207 | : m_currentKey(0) | 209 | : m_currentKey(0), m_running(false) |
| 208 | { | 210 | { |
| 209 | visualMap.resize(Constants::map_size.width); | 211 | visualMap.resize(Constants::map_size.width); |
| 210 | for (int i=0; i<visualMap.size(); ++i) { | 212 | for (int i=0; i<visualMap.size(); ++i) { |
| @@ -213,6 +215,15 @@ MainWidget::MainWidget() | |||
| 213 | 215 | ||
| 214 | createGui(); | 216 | createGui(); |
| 215 | updateMap(createDummyMap()); | 217 | updateMap(createDummyMap()); |
| 218 | |||
| 219 | #if 0 | ||
| 220 | emit startGame(); | ||
| 221 | #else | ||
| 222 | Phonon::MediaObject *player = Phonon::createPlayer(Phonon::MusicCategory, | ||
| 223 | Phonon::MediaSource(new QFile(":/sound/intro"))); | ||
| 224 | connect(player, SIGNAL(finished()), this, SLOT(startGame())); | ||
| 225 | player->play(); | ||
| 226 | #endif | ||
| 216 | } | 227 | } |
| 217 | 228 | ||
| 218 | void MainWidget::createGui() | 229 | void MainWidget::createGui() |
| @@ -321,7 +332,7 @@ void MainWidget::updateMap(const Transmission::map_t& map) | |||
| 321 | if (actor == NULL) | 332 | if (actor == NULL) |
| 322 | { | 333 | { |
| 323 | //qDebug() << "new actor of col" << color; | 334 | //qDebug() << "new actor of col" << color; |
| 324 | actor = new Actor(color); | 335 | actor = new Actor(color, (color == Color::red)); //TODO: red = local for testing |
| 325 | m_actors[color] = actor; | 336 | m_actors[color] = actor; |
| 326 | m_scene->addItem(actor); | 337 | m_scene->addItem(actor); |
| 327 | actor->setPos(mapPositionToCoord(x, y)); | 338 | actor->setPos(mapPositionToCoord(x, y)); |
| @@ -403,6 +414,9 @@ Transmission::field_t MainWidget::translateKey(int key) | |||
| 403 | 414 | ||
| 404 | void MainWidget::keyPressEvent(QKeyEvent* event) | 415 | void MainWidget::keyPressEvent(QKeyEvent* event) |
| 405 | { | 416 | { |
| 417 | if (!m_running) | ||
| 418 | return; | ||
| 419 | |||
| 406 | QWidget::keyPressEvent(event); | 420 | QWidget::keyPressEvent(event); |
| 407 | m_currentKey = translateKey(event->key()); | 421 | m_currentKey = translateKey(event->key()); |
| 408 | 422 | ||
| @@ -436,6 +450,9 @@ void MainWidget::keyPressEvent(QKeyEvent* event) | |||
| 436 | 450 | ||
| 437 | void MainWidget::keyReleaseEvent(QKeyEvent* event) | 451 | void MainWidget::keyReleaseEvent(QKeyEvent* event) |
| 438 | { | 452 | { |
| 453 | if (!m_running) | ||
| 454 | return; | ||
| 455 | |||
| 439 | QWidget::keyReleaseEvent(event); | 456 | QWidget::keyReleaseEvent(event); |
| 440 | Transmission::field_t releasedKey = translateKey(event->key()); | 457 | Transmission::field_t releasedKey = translateKey(event->key()); |
| 441 | if (releasedKey == m_currentKey) | 458 | if (releasedKey == m_currentKey) |
| @@ -446,3 +463,8 @@ void MainWidget::keyReleaseEvent(QKeyEvent* event) | |||
| 446 | m_currentKey = Transmission::direction_none; | 463 | m_currentKey = Transmission::direction_none; |
| 447 | } | 464 | } |
| 448 | } | 465 | } |
| 466 | |||
| 467 | void MainWidget::startGame() | ||
| 468 | { | ||
| 469 | m_running = true; | ||
| 470 | } | ||
