summaryrefslogtreecommitdiff
path: root/src/player.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2010-11-30 15:35:03 +0200
committerPerttu Ahola <celeron55@gmail.com>2010-11-30 15:35:03 +0200
commit38353751c9f4e03fb6a0b855e6d8b5691af71dc0 (patch)
treefb3b6b96b37704382560ed735d26099338853bae /src/player.cpp
parent4a8973aeac1d44b78e44efde113e5c47bb3a803b (diff)
downloadminetest-38353751c9f4e03fb6a0b855e6d8b5691af71dc0.tar.gz
minetest-38353751c9f4e03fb6a0b855e6d8b5691af71dc0.tar.bz2
minetest-38353751c9f4e03fb6a0b855e6d8b5691af71dc0.zip
better water
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/player.cpp b/src/player.cpp
index c3e14fc90..5e838bf7a 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Player::Player():
touching_ground(false),
+ in_water(false),
inventory(PLAYER_INVENTORY_SIZE),
peer_id(PEER_ID_NEW),
m_speed(0,0,0),
@@ -64,6 +65,26 @@ void Player::move(f32 dtime, Map &map)
v3s16 pos_i = floatToInt(position);
+ /*
+ Check if player is in water
+ */
+ try{
+ if(in_water)
+ {
+ v3s16 pp = floatToInt(position + v3f(0,0,0));
+ in_water = material_liquid(map.getNode(pp).d);
+ }
+ else
+ {
+ v3s16 pp = floatToInt(position + v3f(0,BS/2,0));
+ in_water = material_liquid(map.getNode(pp).d);
+ }
+ }
+ catch(InvalidPositionException &e)
+ {
+ in_water = false;
+ }
+
// The frame length is limited to the player going 0.1*BS per call
f32 d = (float)BS * 0.15;
@@ -100,10 +121,8 @@ void Player::move(f32 dtime, Map &map)
for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++){
for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++){
for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++){
- //std::cout<<"with ("<<x<<","<<y<<","<<z<<"): ";
try{
- if(map.getNode(v3s16(x,y,z)).d == MATERIAL_AIR){
- //std::cout<<"air."<<std::endl;
+ if(material_walkable(map.getNode(v3s16(x,y,z)).d) == false){
continue;
}
}
@@ -355,11 +374,18 @@ void LocalPlayer::applyControl(float dtime)
}
if(control.jump)
{
- if(touching_ground){
+ if(touching_ground)
+ {
v3f speed = getSpeed();
speed.Y = 6.5*BS;
setSpeed(speed);
}
+ else if(in_water)
+ {
+ v3f speed = getSpeed();
+ speed.Y = 2.0*BS;
+ setSpeed(speed);
+ }
}
// The speed of the player (Y is ignored)