diff options
| author | manuel <manuel@mausz.at> | 2011-04-09 12:34:06 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-09 12:34:06 +0200 |
| commit | 7e4bc8ece49543533c4e27f5d6bc867c1bada601 (patch) | |
| tree | 261881edeed4c703c9f1fce5111705a013df8bdc /pacman-c++ | |
| parent | a4fc700dfe22c252824ac81711da4bd0bf94def5 (diff) | |
| download | foop-7e4bc8ece49543533c4e27f5d6bc867c1bada601.tar.gz foop-7e4bc8ece49543533c4e27f5d6bc867c1bada601.tar.bz2 foop-7e4bc8ece49543533c4e27f5d6bc867c1bada601.zip | |
collision detection fix
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/actor.cpp | 9 | ||||
| -rw-r--r-- | pacman-c++/audioplayer.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/audioplayer.h | 1 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 13 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.cpp | 7 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.h | 1 |
6 files changed, 31 insertions, 6 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 5ccc339..445d63d 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -14,7 +14,10 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local) | 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local) |
| 15 | { | 15 | { |
| 16 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); | 16 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); |
| 17 | /* DON'T set any pixmap here. we've a pixmap in the animation */ | 17 | /* DON'T set any pixmap here. we've a pixmap in the animation |
| 18 | * but we need a sprite for the collision detection | ||
| 19 | */ | ||
| 20 | setSprite(Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); | ||
| 18 | /* higher player "over" lower player */ | 21 | /* higher player "over" lower player */ |
| 19 | setZValue(m_color * 10); | 22 | setZValue(m_color * 10); |
| 20 | 23 | ||
| @@ -165,7 +168,7 @@ void Actor::move(Actor::Movement direction) | |||
| 165 | { | 168 | { |
| 166 | if (m_local && AudioPlayer::self()->state() != Phonon::PlayingState) | 169 | if (m_local && AudioPlayer::self()->state() != Phonon::PlayingState) |
| 167 | { | 170 | { |
| 168 | AudioPlayer::self()->clearQueue(); | 171 | AudioPlayer::self()->clear(); |
| 169 | AudioPlayer::self()->play(AudioPlayer::WakaWaka); | 172 | AudioPlayer::self()->play(AudioPlayer::WakaWaka); |
| 170 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); | 173 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); |
| 171 | } | 174 | } |
| @@ -183,7 +186,7 @@ bool Actor::isMoving() | |||
| 183 | } | 186 | } |
| 184 | 187 | ||
| 185 | void Actor::enqueue() | 188 | void Actor::enqueue() |
| 186 | { | 189 | { |
| 187 | if (isMoving()) | 190 | if (isMoving()) |
| 188 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); | 191 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); |
| 189 | } | 192 | } |
diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp index d3d2ff6..424d3cf 100644 --- a/pacman-c++/audioplayer.cpp +++ b/pacman-c++/audioplayer.cpp | |||
| @@ -72,6 +72,12 @@ void AudioPlayer::play(AudioPlayer::Sound sound) | |||
| 72 | m_player->play(); | 72 | m_player->play(); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | void AudioPlayer::clear() | ||
| 76 | { | ||
| 77 | if (!m_working) | ||
| 78 | return; | ||
| 79 | m_player->clear(); | ||
| 80 | } | ||
| 75 | 81 | ||
| 76 | void AudioPlayer::enqueue(AudioPlayer::Sound sound) | 82 | void AudioPlayer::enqueue(AudioPlayer::Sound sound) |
| 77 | { | 83 | { |
diff --git a/pacman-c++/audioplayer.h b/pacman-c++/audioplayer.h index e5344e7..dd0c25a 100644 --- a/pacman-c++/audioplayer.h +++ b/pacman-c++/audioplayer.h | |||
| @@ -32,6 +32,7 @@ public: | |||
| 32 | void stop(); | 32 | void stop(); |
| 33 | void setMuted(bool mute = true); | 33 | void setMuted(bool mute = true); |
| 34 | void play(Sound sound); | 34 | void play(Sound sound); |
| 35 | void clear(); | ||
| 35 | void enqueue(Sound sound); | 36 | void enqueue(Sound sound); |
| 36 | void clearQueue(); | 37 | void clearQueue(); |
| 37 | Phonon::State state(); | 38 | Phonon::State state(); |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 072d417..63280f2 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -62,8 +62,8 @@ Transmission::map_t createDummyMap() | |||
| 62 | 62 | ||
| 63 | map[0][0] |= Transmission::bonuspoint; | 63 | map[0][0] |= Transmission::bonuspoint; |
| 64 | map[1][0] |= Color::red | Transmission::pacman | Transmission::direction_right; | 64 | map[1][0] |= Color::red | Transmission::pacman | Transmission::direction_right; |
| 65 | map[2][0] |= Color::blue | Transmission::pacman | Transmission::direction_up; | 65 | //map[2][0] |= Color::blue | Transmission::pacman | Transmission::direction_up; |
| 66 | map[3][0] |= Color::green | Transmission::pacman | Transmission::direction_down; | 66 | //map[3][0] |= Color::green | Transmission::pacman | Transmission::direction_down; |
| 67 | 67 | ||
| 68 | /* auto place normal points*/ | 68 | /* auto place normal points*/ |
| 69 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) | 69 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
| @@ -97,7 +97,7 @@ MainWidget::MainWidget() | |||
| 97 | 97 | ||
| 98 | QTimer *timer = new QTimer(this); | 98 | QTimer *timer = new QTimer(this); |
| 99 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); | 99 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); |
| 100 | timer->start(100); | 100 | timer->start(Constants::tick); |
| 101 | 101 | ||
| 102 | startGame(); | 102 | startGame(); |
| 103 | } | 103 | } |
| @@ -318,6 +318,13 @@ void MainWidget::tick() | |||
| 318 | { | 318 | { |
| 319 | i.next(); | 319 | i.next(); |
| 320 | i.value()->move(mov); | 320 | i.value()->move(mov); |
| 321 | QList<QGraphicsItem *> list(i.value()->collidingItems()); | ||
| 322 | for(int j = 0; j < list.count(); ++j) | ||
| 323 | { | ||
| 324 | if (list.at(j)->parentItem() == i.value()) | ||
| 325 | continue; | ||
| 326 | list.at(j)->setOpacity(0.6); | ||
| 327 | } | ||
| 321 | } | 328 | } |
| 322 | } | 329 | } |
| 323 | 330 | ||
diff --git a/pacman-c++/pixmapitem.cpp b/pacman-c++/pixmapitem.cpp index 84517c2..1ceeec1 100644 --- a/pacman-c++/pixmapitem.cpp +++ b/pacman-c++/pixmapitem.cpp | |||
| @@ -63,6 +63,13 @@ QRectF PixmapItem::boundingRect() const | |||
| 63 | return QRectF(QPointF(0, 0), size()); | 63 | return QRectF(QPointF(0, 0), size()); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | QPainterPath PixmapItem::shape() const | ||
| 67 | { | ||
| 68 | QPainterPath path; | ||
| 69 | path.addRect(boundingRect()); | ||
| 70 | return path; | ||
| 71 | } | ||
| 72 | |||
| 66 | void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) | 73 | void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
| 67 | { | 74 | { |
| 68 | painter->drawPixmap(QPoint(0, 0), m_pix, QRect(m_x, m_y, m_width, m_height)); | 75 | painter->drawPixmap(QPoint(0, 0), m_pix, QRect(m_x, m_y, m_width, m_height)); |
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h index e576d77..cff976f 100644 --- a/pacman-c++/pixmapitem.h +++ b/pacman-c++/pixmapitem.h | |||
| @@ -18,6 +18,7 @@ public: | |||
| 18 | void setSprite(int x, int y, int width, int height); | 18 | void setSprite(int x, int y, int width, int height); |
| 19 | QSizeF size() const; | 19 | QSizeF size() const; |
| 20 | QRectF boundingRect() const; | 20 | QRectF boundingRect() const; |
| 21 | QPainterPath shape() const; | ||
| 21 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | 22 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
| 22 | 23 | ||
| 23 | private: | 24 | private: |
