From ea2880702a7df079f5e8eee0280584f186c2de73 Mon Sep 17 00:00:00 2001 From: totycro Date: Mon, 11 Apr 2011 13:03:40 +0200 Subject: Added code to play the cherry sound, but doesn't work here --- pacman-c++/bonuspoint.cpp | 7 +++++++ pacman-c++/bonuspoint.h | 1 + pacman-c++/gameentity.h | 6 ++++++ pacman-c++/point.cpp | 4 ++++ pacman-c++/point.h | 2 ++ pacman-c++/sceneholder.cpp | 11 +++++++++-- 6 files changed, 29 insertions(+), 2 deletions(-) (limited to 'pacman-c++') diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 2b5500b..a705c09 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp @@ -26,3 +26,10 @@ bool BonusPoint::enter(Actor* actor) m_eaten = true; return false; } + +void BonusPoint::onDie(Actor *actor) +{ + qDebug() << "here comes the cherry.. "; + actor->eatingCherry(); +} + diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h index dcf561e..222e046 100644 --- a/pacman-c++/bonuspoint.h +++ b/pacman-c++/bonuspoint.h @@ -12,6 +12,7 @@ public: {}; virtual bool enter(Actor *actor); + virtual void onDie(Actor *actor); }; #endif // BONUSPOINT_H diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h index 2a771ee..0c0ab9c 100644 --- a/pacman-c++/gameentity.h +++ b/pacman-c++/gameentity.h @@ -20,8 +20,14 @@ public: // returns whether this entity survives the entering virtual bool enter(Actor *actor) { Q_UNUSED(actor); return true; } // default to no action/survive + // check whether this entity is regarded as eaten + // (and can be removed in the next tick) virtual bool eaten() { return m_eaten; } + // called when an instance acctually dies for creating effects + virtual void onDie(Actor *actor) { Q_UNUSED(actor); }; + + protected: bool m_eaten; }; diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp index 05bd277..b4eae4e 100644 --- a/pacman-c++/point.cpp +++ b/pacman-c++/point.cpp @@ -23,3 +23,7 @@ bool Point::enter(Actor* actor) m_eaten = true; return false; } + +void Point::onDie(Actor* actor) +{ +} diff --git a/pacman-c++/point.h b/pacman-c++/point.h index 033ca56..944764b 100644 --- a/pacman-c++/point.h +++ b/pacman-c++/point.h @@ -12,6 +12,8 @@ public: {}; virtual bool enter(Actor *actor); + + virtual void onDie(Actor *actor); }; #endif // POINT_H diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index e4429f6..c819b95 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -40,8 +40,16 @@ void SceneHolder::updateMap(const Transmission::map_t& map) { m_scene->removeItem(oldItem); visualMap[x][y] = NULL; + Actor *actor = NULL; + foreach (Actor *i, m_actors) { + if (CoordToMapPosition(i->pos().x(), i->pos().y()) == QPoint(x, y)) { + actor = i; + break; + } + } + oldItem->onDie(actor); delete oldItem; - qDebug() << "deleting " << x << y; + //qDebug() << "deleting " << x << y; } } @@ -104,7 +112,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map) visualMap[x][y] = item; if (oldItem != NULL) { - oldItem->onDie(); m_scene->removeItem(item); delete oldItem; } -- cgit v1.2.3