src/Player.cc
changeset 295 4d3adfbec077
parent 293 d40fbf8ba13b
child 296 4d3ebaa29430
--- a/src/Player.cc	Mon Dec 08 16:44:38 2008 +0000
+++ b/src/Player.cc	Mon Dec 08 16:46:48 2008 +0000
@@ -26,6 +26,7 @@
     weapons(buildWeaponsList()), 
     selectedWeapon(0), 
     rope(*this),
+    health(100),
     animation_step(0)
 {
     // XXX: populate weapons from somewhere else
@@ -209,8 +210,28 @@
         return NULL;
 }
 
+void Player::onCollision (Vector collisionPoint, PhysicsObject *other) {
+
+    if (other == NULL)
+        return;
+
+    // Currently we handle only player-player collision here.
+    // Player-projectile collision is handled in projectile's onCollision.
+    if (other->getType() == PLAYER) {
+        Vector normal = this->getPosition() - other->getPosition();
+        this->bounce(normal);
+        // Move the player back to its previous position so that players won't
+        // stuff inside each others when having a collision walk, e.g.
+        this->setPosition(this->getPreviousPosition());
+    }
+}
+
 void Player::takeDamage(int damage) {
-
+    this->health -= damage;
+    Engine::log(DEBUG, "Player.takeDamage") << "Your health is now: " << health;
+    if (this->health <= 0) {
+        this->disable();
+    }
 }
 
 void Player::draw (Graphics *g, PixelCoordinate camera) {