summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-05-02 15:50:23 +0200
committermanuel <manuel@mausz.at>2011-05-02 15:50:23 +0200
commitce20694e0db010b5d65bdd2ee81a410efbf99e3d (patch)
tree6063fb3b023d156374936cc6d405abf3e57532cd /pacman-c++/actor.cpp
parent41a31420cf091aeb4e986503387855d41e550106 (diff)
downloadfoop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.tar.gz
foop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.tar.bz2
foop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.zip
w000h00
Diffstat (limited to 'pacman-c++/actor.cpp')
-rw-r--r--pacman-c++/actor.cpp43
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
12Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) 12Actor::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
135void Actor::setDirection(Movement direction)
136{
137 m_direction = direction;
138}
139
133bool Actor::isLocal() 140bool Actor::isLocal()
134{ 141{
135 return m_local; 142 return m_local;
136} 143}
137 144
138void Actor::resetAnimation() 145bool Actor::hadReset()
139{ 146{
147 if (!m_reset)
148 return false;
149 m_reset = false;
150 return true;
151}
152
153void 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
173void 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
157void Actor::move(Actor::Movement direction) 188void 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
278void Actor::onDie(Actor *other)
279{
280 other->eatingPacman();
281 die();
282}
283
247void Actor::die() 284void 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)