diff options
Diffstat (limited to 'pacman-c++/actor.cpp')
| -rw-r--r-- | pacman-c++/actor.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
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 | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | 12 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) |
| 13 | : GameEntity(color, parent), m_direction(Actor::None), m_local(local), | 13 | : GameEntity(color, parent), m_direction(Actor::None), m_local(local), m_reset(true), |
| 14 | m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0) | 14 | m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0) |
| 15 | { | 15 | { |
| 16 | m_type = Type; | 16 | m_type = Type; |
| @@ -62,6 +62,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 62 | for (int i = 0; i < 11; i++) | 62 | for (int i = 0; i < 11; i++) |
| 63 | { | 63 | { |
| 64 | PixmapItem *img = new PixmapItem(m_pix, this); | 64 | PixmapItem *img = new PixmapItem(m_pix, this); |
| 65 | img->setZValue(zValue() * 10); | ||
| 65 | m_images.append(img); | 66 | m_images.append(img); |
| 66 | int x = i * Constants::sprite_offset + Constants::sprite_margin; | 67 | int x = i * Constants::sprite_offset + Constants::sprite_margin; |
| 67 | int y = 5 * Constants::sprite_offset + Constants::sprite_margin; | 68 | int y = 5 * Constants::sprite_offset + Constants::sprite_margin; |
| @@ -130,13 +131,28 @@ Actor::Movement Actor::direction() | |||
| 130 | return m_direction; | 131 | return m_direction; |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 134 | |||
| 135 | void Actor::setDirection(Movement direction) | ||
| 136 | { | ||
| 137 | m_direction = direction; | ||
| 138 | } | ||
| 139 | |||
| 133 | bool Actor::isLocal() | 140 | bool Actor::isLocal() |
| 134 | { | 141 | { |
| 135 | return m_local; | 142 | return m_local; |
| 136 | } | 143 | } |
| 137 | 144 | ||
| 138 | void Actor::resetAnimation() | 145 | bool Actor::hadReset() |
| 139 | { | 146 | { |
| 147 | if (!m_reset) | ||
| 148 | return false; | ||
| 149 | m_reset = false; | ||
| 150 | return true; | ||
| 151 | } | ||
| 152 | |||
| 153 | void Actor::reset() | ||
| 154 | { | ||
| 155 | m_reset = true; | ||
| 140 | if (Constants::server) | 156 | if (Constants::server) |
| 141 | return; | 157 | return; |
| 142 | 158 | ||
| @@ -154,6 +170,21 @@ void Actor::resetAnimation() | |||
| 154 | m_images[m_direction]->setVisible(true); | 170 | m_images[m_direction]->setVisible(true); |
| 155 | } | 171 | } |
| 156 | 172 | ||
| 173 | void Actor::move(QPoint newpos) | ||
| 174 | { | ||
| 175 | QPoint oldpos = pos().toPoint(); | ||
| 176 | Actor::Movement direction = Actor::None; | ||
| 177 | if (oldpos.x() - newpos.x() < 0) | ||
| 178 | direction = Actor::Right; | ||
| 179 | else if (oldpos.x() - newpos.x() > 0) | ||
| 180 | direction = Actor::Left; | ||
| 181 | else if (oldpos.y() - newpos.y() < 0) | ||
| 182 | direction = Actor::Down; | ||
| 183 | else if (oldpos.y() - newpos.y() > 0) | ||
| 184 | direction = Actor::Up; | ||
| 185 | move(direction); | ||
| 186 | } | ||
| 187 | |||
| 157 | void Actor::move(Actor::Movement direction) | 188 | void Actor::move(Actor::Movement direction) |
| 158 | { | 189 | { |
| 159 | if (Constants::server) | 190 | if (Constants::server) |
| @@ -244,12 +275,18 @@ bool Actor::canEat(Actor *other, const QList<Color::Color> &order) | |||
| 244 | return (order.at(idx + 1) == other->color()); | 275 | return (order.at(idx + 1) == other->color()); |
| 245 | } | 276 | } |
| 246 | 277 | ||
| 278 | void Actor::onDie(Actor *other) | ||
| 279 | { | ||
| 280 | other->eatingPacman(); | ||
| 281 | die(); | ||
| 282 | } | ||
| 283 | |||
| 247 | void Actor::die() | 284 | void Actor::die() |
| 248 | { | 285 | { |
| 249 | if (Constants::server) | 286 | if (Constants::server) |
| 250 | return; | 287 | return; |
| 251 | 288 | ||
| 252 | resetAnimation(); | 289 | reset(); |
| 253 | m_images[m_direction]->setVisible(false); | 290 | m_images[m_direction]->setVisible(false); |
| 254 | m_dieing->start(); | 291 | m_dieing->start(); |
| 255 | if (m_local) | 292 | if (m_local) |
