aboutsummaryrefslogtreecommitdiff
path: root/src/player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 8f594eee6..31415b6b2 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -33,6 +33,7 @@ Player::Player():
in_water_stable(false),
swimming_up(false),
craftresult_is_preview(true),
+ hp(20),
peer_id(PEER_ID_INEXISTENT),
m_pitch(0),
m_yaw(0),
@@ -102,6 +103,7 @@ void Player::serialize(std::ostream &os)
args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position);
args.setBool("craftresult_is_preview", craftresult_is_preview);
+ args.setS32("hp", hp);
args.writeLines(os);
@@ -138,6 +140,11 @@ void Player::deSerialize(std::istream &is)
}catch(SettingNotFoundException &e){
craftresult_is_preview = true;
}
+ try{
+ hp = args.getS32("hp");
+ }catch(SettingNotFoundException &e){
+ hp = 20;
+ }
inventory.deSerialize(is);
}
@@ -276,7 +283,8 @@ LocalPlayer::~LocalPlayer()
{
}
-void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
+void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
+ core::list<CollisionInfo> *collision_info)
{
v3f position = getPosition();
v3f oldpos = position;
@@ -530,9 +538,23 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
*/
if(other_axes_overlap && main_axis_collides)
{
+ v3f old_speed = m_speed;
+
m_speed -= m_speed.dotProduct(dirs[i]) * dirs[i];
position -= position.dotProduct(dirs[i]) * dirs[i];
position += oldpos.dotProduct(dirs[i]) * dirs[i];
+
+ if(collision_info)
+ {
+ // Report fall collision
+ if(old_speed.Y < m_speed.Y - 0.1)
+ {
+ CollisionInfo info;
+ info.t = COLLISION_FALL;
+ info.speed = m_speed.Y - old_speed.Y;
+ collision_info->push_back(info);
+ }
+ }
}
}
@@ -617,6 +639,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
setPosition(position);
}
+void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
+{
+ move(dtime, map, pos_max_d, NULL);
+}
+
void LocalPlayer::applyControl(float dtime)
{
// Clear stuff