--- 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) {
--- a/src/Player.hh Mon Dec 08 16:44:38 2008 +0000
+++ b/src/Player.hh Mon Dec 08 16:46:48 2008 +0000
@@ -36,6 +36,8 @@
// we have a rope
Rope rope;
+ int health;
+
// XXX: hmm... updated where?
int animation_step;
@@ -54,7 +56,7 @@
*/
~Player (void);
- /*
+ /**
* Used by the network code to execute various actions
*/
virtual void handleDig (Vector position, float radius);
@@ -85,16 +87,21 @@
*/
Weapon* getWeapon (WeaponID id);
- /*
+ /**
* Prints random things via Engine::log
*/
void printDebugInfo ();
- /*
+ /**
* Overrides PhysicsObject::tick to also advance game state
*/
virtual void tick (TimeMS dt);
+ /**
+ * This is called when the player collides with the terrain or with some other object.
+ */
+ void onCollision (Vector collisionPoint, PhysicsObject *other);
+
/*
* Drawing requires the skin texture, which is loaded on-demand when draw is called
*/
--- a/src/Projectile.cc Mon Dec 08 16:44:38 2008 +0000
+++ b/src/Projectile.cc Mon Dec 08 16:46:48 2008 +0000
@@ -44,7 +44,7 @@
if(other != NULL && other->getType() == PLAYER) {
Player* pl = dynamic_cast<Player*>(other);
- pl->takeDamage(12345);
+ pl->takeDamage(10);
}
if (collision_elasticity == 0)