209 else |
209 else |
210 return NULL; |
210 return NULL; |
211 } |
211 } |
212 |
212 |
213 void Player::onCollision (Vector collisionPoint, PhysicsObject *other) { |
213 void Player::onCollision (Vector collisionPoint, PhysicsObject *other) { |
|
214 (void) collisionPoint; |
214 |
215 |
215 if (other == NULL) |
216 if (other == NULL) |
216 return; |
217 return; |
217 |
218 |
218 // Currently we handle only player-player collision here. |
219 // Currently we handle only player-player collision here. |
219 // Player-projectile collision is handled in projectile's onCollision. |
220 // Player-projectile collision is handled in projectile's onCollision. |
|
221 // XXX: not network-safe |
220 if (other->getType() == PLAYER) { |
222 if (other->getType() == PLAYER) { |
221 Vector normal = this->getPosition() - other->getPosition(); |
223 Vector normal = this->getPosition() - other->getPosition(); |
222 this->bounce(normal); |
224 this->bounce(normal); |
223 // Move the player back to its previous position so that players won't |
225 // Move the player back to its previous position so that players won't |
224 // stuff inside each others when having a collision walk, e.g. |
226 // stuff inside each others when having a collision walk, e.g. |
225 this->setPosition(this->getPreviousPosition()); |
227 this->setPosition(this->getPreviousPosition()); |
226 } |
228 } |
227 } |
229 } |
228 |
230 |
229 void Player::takeDamage(int damage) { |
231 void Player::takeDamage (Health damage) { |
230 this->health -= damage; |
232 this->health -= damage; |
231 Engine::log(DEBUG, "Player.takeDamage") << "Your health is now: " << health; |
233 |
232 if (this->health <= 0) { |
234 if (this->health <= 0) |
233 this->disable(); |
235 this->disable(); |
234 } |
236 |
|
237 Engine::log(DEBUG, "player.take_damage") << this << ": damage=" << damage << ", health=" << health; |
235 } |
238 } |
236 |
239 |
237 void Player::draw (Graphics *g, PixelCoordinate camera) { |
240 void Player::draw (Graphics *g, PixelCoordinate camera) { |
238 CL_GraphicContext *gc = g->get_gc(); |
241 CL_GraphicContext *gc = g->get_gc(); |
239 |
242 |