From fe11a3bf19040388671a141a7282f375073cf67d Mon Sep 17 00:00:00 2001 From: totycro Date: Sat, 9 Apr 2011 00:55:05 +0200 Subject: tried to make movement more smooth --- pacman-c++/mainwidget.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'pacman-c++/mainwidget.cpp') diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index b421c36..072d417 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -92,8 +92,14 @@ MainWidget::MainWidget() createGui(); updateMap(createDummyMap()); - connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); - AudioPlayer::self()->play(AudioPlayer::Intro); + //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); + //AudioPlayer::self()->play(AudioPlayer::Intro); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(tick())); + timer->start(100); + + startGame(); } void MainWidget::createGui() @@ -286,6 +292,36 @@ Transmission::field_t MainWidget::translateKey(int key) } } +void MainWidget::tick() +{ + Actor::Movement mov = Actor::None; + switch(m_currentKey) + { + case Transmission::direction_up: + mov = Actor::Up; + break; + case Transmission::direction_down: + mov = Actor::Down; + break; + case Transmission::direction_left: + mov = Actor::Left; + break; + case Transmission::direction_right: + mov = Actor::Right; + break; + default: + break; + } + + QMapIterator i(m_actors); + while (i.hasNext()) + { + i.next(); + i.value()->move(mov); + } +} + + void MainWidget::keyPressEvent(QKeyEvent* event) { if (!m_running) @@ -294,6 +330,8 @@ void MainWidget::keyPressEvent(QKeyEvent* event) QWidget::keyPressEvent(event); m_currentKey = translateKey(event->key()); + return; + // test stuff Actor::Movement mov = Actor::None; switch(m_currentKey) -- cgit v1.2.3