--- a/src/Player.cc Mon Dec 08 17:39:01 2008 +0000
+++ b/src/Player.cc Mon Dec 08 18:12:43 2008 +0000
@@ -26,7 +26,8 @@
weapons(buildWeaponsList()),
selectedWeapon(0),
rope(*this),
- health(100),
+ health(PLAYER_HEALTH),
+ respawn_timer(PLAYER_RESPAWN_DELAY),
animation_step(0)
{
// XXX: populate weapons from somewhere else
@@ -44,11 +45,46 @@
// add to GameState players list
state.addPlayer(this);
+
+ // connect respawn timer
+ respawn_slot = respawn_timer.sig_tick().connect(this, &Player::respawn);
+
+ // spawn
+ spawn(position);
}
Player::~Player (void) {
state.removePlayer(this);
}
+
+void Player::spawn (Vector position) {
+ // dig hole
+ world.removeGround(position, PLAYER_DIG_RADIUS);
+
+ // update position
+ setPosition(position);
+
+ // enable
+ enable();
+}
+
+void Player::die (void) {
+ // disable our PhysicsObject
+ disable();
+
+ // start respawn timer
+ respawn_timer.fire_once();
+}
+
+void Player::respawn (TimeMS dt) {
+ (void) dt;
+
+ // reset health
+ health = PLAYER_HEALTH;
+
+ // XXX: ...
+ spawn(Vector(PLAYER_INITIAL_X, PLAYER_INITIAL_Y));
+}
void Player::handleDig (Vector pos, float radius) {
// calculate new position and velocity
@@ -85,7 +121,7 @@
void Player::tick (TimeMS dt) {
// let PhysicsObject execute
PhysicsObject::tick(dt);
-
+
// tick current weapon reload
if (getCurrentWeapon())
getCurrentWeapon()->tickReload(dt);
@@ -99,6 +135,9 @@
(void) length;
}
+/*
+ * LocalPlayer
+ */
void LocalPlayer::fireWeapon (Weapon *weapon) {
// calculate new position and velocity
Vector shotPosition = position + getDirection() * PROJECTILE_START_DISTANCE;
@@ -164,7 +203,7 @@
// outsource digging to Player::handleDig, since this modifies the Terrain and Network needs to know
if (input & INPUT_DIG)
- handleDig(position, 15);
+ handleDig(position, PLAYER_DIG_RADIUS);
// change weapon back/forth
if (input & INPUT_CHANGE_PREV)
@@ -201,6 +240,10 @@
// apply force
if (!move_force.zero())
applyForce(move_force, dt);
+
+ // suicide?
+ if (input & INPUT_SUICIDE)
+ die();
}
Weapon* Player::getCurrentWeapon() {
@@ -237,7 +280,7 @@
health -= damage;
if (health <= 0)
- disable();
+ die();
Engine::log(DEBUG, "player.take_damage") << this << ": damage=" << damage << ", health=" << health;
}