From ce20694e0db010b5d65bdd2ee81a410efbf99e3d Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 2 May 2011 15:50:23 +0200 Subject: w000h00 --- pacman-c++/actor.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'pacman-c++/actor.cpp') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 2dced34..9c2d2fa 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -10,7 +10,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal } Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) - : GameEntity(color, parent), m_direction(Actor::None), m_local(local), + : GameEntity(color, parent), m_direction(Actor::None), m_local(local), m_reset(true), m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0) { m_type = Type; @@ -62,6 +62,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) for (int i = 0; i < 11; i++) { PixmapItem *img = new PixmapItem(m_pix, this); + img->setZValue(zValue() * 10); m_images.append(img); int x = i * Constants::sprite_offset + Constants::sprite_margin; int y = 5 * Constants::sprite_offset + Constants::sprite_margin; @@ -130,13 +131,28 @@ Actor::Movement Actor::direction() return m_direction; } + +void Actor::setDirection(Movement direction) +{ + m_direction = direction; +} + bool Actor::isLocal() { return m_local; } -void Actor::resetAnimation() +bool Actor::hadReset() { + if (!m_reset) + return false; + m_reset = false; + return true; +} + +void Actor::reset() +{ + m_reset = true; if (Constants::server) return; @@ -154,6 +170,21 @@ void Actor::resetAnimation() m_images[m_direction]->setVisible(true); } +void Actor::move(QPoint newpos) +{ + QPoint oldpos = pos().toPoint(); + Actor::Movement direction = Actor::None; + if (oldpos.x() - newpos.x() < 0) + direction = Actor::Right; + else if (oldpos.x() - newpos.x() > 0) + direction = Actor::Left; + else if (oldpos.y() - newpos.y() < 0) + direction = Actor::Down; + else if (oldpos.y() - newpos.y() > 0) + direction = Actor::Up; + move(direction); +} + void Actor::move(Actor::Movement direction) { if (Constants::server) @@ -244,12 +275,18 @@ bool Actor::canEat(Actor *other, const QList &order) return (order.at(idx + 1) == other->color()); } +void Actor::onDie(Actor *other) +{ + other->eatingPacman(); + die(); +} + void Actor::die() { if (Constants::server) return; - resetAnimation(); + reset(); m_images[m_direction]->setVisible(false); m_dieing->start(); if (m_local) -- cgit v1.2.3