summaryrefslogtreecommitdiffstats
path: root/pacman-c++/mainwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
-rw-r--r--pacman-c++/mainwidget.cpp28
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
10Transmission::map_t createDummyMap() 12Transmission::map_t createDummyMap()
11{ 13{
@@ -204,7 +206,7 @@ Transmission::map_t createDummyMap()
204} 206}
205 207
206MainWidget::MainWidget() 208MainWidget::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
218void MainWidget::createGui() 229void 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
404void MainWidget::keyPressEvent(QKeyEvent* event) 415void 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
437void MainWidget::keyReleaseEvent(QKeyEvent* event) 451void 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
467void MainWidget::startGame()
468{
469 m_running = true;
470}