Skip to content

Commit

Permalink
Player::accelerateHorizontal/Vertical should be member of LocalPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Feb 14, 2016
1 parent cfc8e44 commit 3a74b84
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
33 changes: 33 additions & 0 deletions src/localplayer.cpp
Expand Up @@ -622,3 +622,36 @@ v3s16 LocalPlayer::getStandingNodePos()
return floatToInt(getPosition() - v3f(0, BS, 0), BS);
}

// Horizontal acceleration (X and Z), Y direction is ignored
void LocalPlayer::accelerateHorizontal(const v3f &target_speed, const f32 max_increase)
{
if (max_increase == 0)
return;

v3f d_wanted = target_speed - m_speed;
d_wanted.Y = 0;
f32 dl = d_wanted.getLength();
if (dl > max_increase)
dl = max_increase;

v3f d = d_wanted.normalize() * dl;

m_speed.X += d.X;
m_speed.Z += d.Z;
}

// Vertical acceleration (Y), X and Z directions are ignored
void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase)
{
if (max_increase == 0)
return;

f32 d_wanted = target_speed.Y - m_speed.Y;
if (d_wanted > max_increase)
d_wanted = max_increase;
else if (d_wanted < -max_increase)
d_wanted = -max_increase;

m_speed.Y += d_wanted;
}

5 changes: 4 additions & 1 deletion src/localplayer.h
Expand Up @@ -45,7 +45,7 @@ class LocalPlayer : public Player
bool isAttached;

v3f overridePosition;

void move(f32 dtime, Environment *env, f32 pos_max_d);
void move(f32 dtime, Environment *env, f32 pos_max_d,
std::vector<CollisionInfo> *collision_info);
Expand Down Expand Up @@ -81,6 +81,9 @@ class LocalPlayer : public Player
}

private:
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
void accelerateVertical(const v3f &target_speed, const f32 max_increase);

// This is used for determining the sneaking range
v3s16 m_sneak_node;
// Whether the player is allowed to sneak
Expand Down
35 changes: 0 additions & 35 deletions src/player.cpp
Expand Up @@ -111,41 +111,6 @@ Player::~Player()
clearHud();
}

// Horizontal acceleration (X and Z), Y direction is ignored
void Player::accelerateHorizontal(v3f target_speed, f32 max_increase)
{
if(max_increase == 0)
return;

v3f d_wanted = target_speed - m_speed;
d_wanted.Y = 0;
f32 dl = d_wanted.getLength();
if(dl > max_increase)
dl = max_increase;

v3f d = d_wanted.normalize() * dl;

m_speed.X += d.X;
m_speed.Z += d.Z;

}

// Vertical acceleration (Y), X and Z directions are ignored
void Player::accelerateVertical(v3f target_speed, f32 max_increase)
{
if(max_increase == 0)
return;

f32 d_wanted = target_speed.Y - m_speed.Y;
if(d_wanted > max_increase)
d_wanted = max_increase;
else if(d_wanted < -max_increase)
d_wanted = -max_increase;

m_speed.Y += d_wanted;

}

v3s16 Player::getLightPosition() const
{
return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
Expand Down
3 changes: 0 additions & 3 deletions src/player.h
Expand Up @@ -119,9 +119,6 @@ class Player
m_speed = speed;
}

void accelerateHorizontal(v3f target_speed, f32 max_increase);
void accelerateVertical(v3f target_speed, f32 max_increase);

v3f getPosition()
{
return m_position;
Expand Down

0 comments on commit 3a74b84

Please sign in to comment.