summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/actor.cpp')
-rw-r--r--pacman-c++/actor.cpp53
1 files changed, 33 insertions, 20 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index fb4b38a..9ff51f3 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -128,25 +128,19 @@ void Actor::move(Actor::Movement direction)
128 m_eating[m_direction]->stop(); 128 m_eating[m_direction]->stop();
129 } 129 }
130 130
131 QPointF endpos(0, 0); 131 QPointF endpos = movementToPoint(direction);
132 switch(direction) 132 switch(direction)
133 { 133 {
134 case Actor::None:
135 break;
136 case Actor::Left: 134 case Actor::Left:
137 endpos.setX(static_cast<qreal>(Constants::field_size.width) * -1);
138 break;
139 case Actor::Right: 135 case Actor::Right:
140 endpos.setX(Constants::field_size.width); 136 endpos *= Constants::field_size.width;
141 break; 137 break;
142 case Actor::Up: 138 case Actor::Up:
143 endpos.setY(static_cast<qreal>(Constants::field_size.height) * -1);
144 break;
145 case Actor::Down: 139 case Actor::Down:
146 endpos.setY(Constants::field_size.height); 140 endpos *= Constants::field_size.height;
147 break; 141 break;
142 case Actor::None:
148 default: 143 default:
149 Q_ASSERT(false);
150 break; 144 break;
151 } 145 }
152 146
@@ -175,25 +169,19 @@ void Actor::move(Actor::Movement direction)
175 169
176void Actor::moveByServer(Actor::Movement direction) 170void Actor::moveByServer(Actor::Movement direction)
177{ 171{
178 QPointF endpos(0, 0); 172 QPointF endpos = movementToPoint(direction);
179 switch(direction) 173 switch(direction)
180 { 174 {
181 case Actor::None:
182 break;
183 case Actor::Left: 175 case Actor::Left:
184 endpos.setX(static_cast<qreal>(Constants::field_size.width) * -1);
185 break;
186 case Actor::Right: 176 case Actor::Right:
187 endpos.setX(Constants::field_size.width); 177 endpos *= Constants::field_size.width;
188 break; 178 break;
189 case Actor::Up: 179 case Actor::Up:
190 endpos.setY(static_cast<qreal>(Constants::field_size.height) * -1);
191 break;
192 case Actor::Down: 180 case Actor::Down:
193 endpos.setY(Constants::field_size.height); 181 endpos *= Constants::field_size.height;
194 break; 182 break;
183 case Actor::None:
195 default: 184 default:
196 Q_ASSERT(false);
197 break; 185 break;
198 } 186 }
199 setPos(pos() + endpos); 187 setPos(pos() + endpos);
@@ -260,3 +248,28 @@ void Actor::finishRound()
260 m_gamePoints += m_roundPoints; 248 m_gamePoints += m_roundPoints;
261 m_roundPoints = 0; 249 m_roundPoints = 0;
262} 250}
251
252QPoint Actor::movementToPoint(const Actor::Movement direction)
253{
254 QPoint endpos(0,0);
255 switch (direction)
256 {
257 case Actor::Up:
258 endpos = QPoint(0, -1);
259 break;
260 case Actor::Down:
261 endpos = QPoint(0, 1);
262 break;
263 case Actor::Left:
264 endpos = QPoint(-1, 0);
265 break;
266 case Actor::Right:
267 endpos = QPoint(1, 0);
268 break;
269 case Actor::None:
270 break;
271 default:
272 Q_ASSERT(false);
273 }
274 return endpos;
275}