Skip to content

Commit 3a74b84

Browse files
committedFeb 14, 2016
Player::accelerateHorizontal/Vertical should be member of LocalPlayer
1 parent cfc8e44 commit 3a74b84

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed
 

‎src/localplayer.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,36 @@ v3s16 LocalPlayer::getStandingNodePos()
622622
return floatToInt(getPosition() - v3f(0, BS, 0), BS);
623623
}
624624

625+
// Horizontal acceleration (X and Z), Y direction is ignored
626+
void LocalPlayer::accelerateHorizontal(const v3f &target_speed, const f32 max_increase)
627+
{
628+
if (max_increase == 0)
629+
return;
630+
631+
v3f d_wanted = target_speed - m_speed;
632+
d_wanted.Y = 0;
633+
f32 dl = d_wanted.getLength();
634+
if (dl > max_increase)
635+
dl = max_increase;
636+
637+
v3f d = d_wanted.normalize() * dl;
638+
639+
m_speed.X += d.X;
640+
m_speed.Z += d.Z;
641+
}
642+
643+
// Vertical acceleration (Y), X and Z directions are ignored
644+
void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase)
645+
{
646+
if (max_increase == 0)
647+
return;
648+
649+
f32 d_wanted = target_speed.Y - m_speed.Y;
650+
if (d_wanted > max_increase)
651+
d_wanted = max_increase;
652+
else if (d_wanted < -max_increase)
653+
d_wanted = -max_increase;
654+
655+
m_speed.Y += d_wanted;
656+
}
657+

‎src/localplayer.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LocalPlayer : public Player
4545
bool isAttached;
4646

4747
v3f overridePosition;
48-
48+
4949
void move(f32 dtime, Environment *env, f32 pos_max_d);
5050
void move(f32 dtime, Environment *env, f32 pos_max_d,
5151
std::vector<CollisionInfo> *collision_info);
@@ -81,6 +81,9 @@ class LocalPlayer : public Player
8181
}
8282

8383
private:
84+
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
85+
void accelerateVertical(const v3f &target_speed, const f32 max_increase);
86+
8487
// This is used for determining the sneaking range
8588
v3s16 m_sneak_node;
8689
// Whether the player is allowed to sneak

‎src/player.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -111,41 +111,6 @@ Player::~Player()
111111
clearHud();
112112
}
113113

114-
// Horizontal acceleration (X and Z), Y direction is ignored
115-
void Player::accelerateHorizontal(v3f target_speed, f32 max_increase)
116-
{
117-
if(max_increase == 0)
118-
return;
119-
120-
v3f d_wanted = target_speed - m_speed;
121-
d_wanted.Y = 0;
122-
f32 dl = d_wanted.getLength();
123-
if(dl > max_increase)
124-
dl = max_increase;
125-
126-
v3f d = d_wanted.normalize() * dl;
127-
128-
m_speed.X += d.X;
129-
m_speed.Z += d.Z;
130-
131-
}
132-
133-
// Vertical acceleration (Y), X and Z directions are ignored
134-
void Player::accelerateVertical(v3f target_speed, f32 max_increase)
135-
{
136-
if(max_increase == 0)
137-
return;
138-
139-
f32 d_wanted = target_speed.Y - m_speed.Y;
140-
if(d_wanted > max_increase)
141-
d_wanted = max_increase;
142-
else if(d_wanted < -max_increase)
143-
d_wanted = -max_increase;
144-
145-
m_speed.Y += d_wanted;
146-
147-
}
148-
149114
v3s16 Player::getLightPosition() const
150115
{
151116
return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);

‎src/player.h

-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ class Player
119119
m_speed = speed;
120120
}
121121

122-
void accelerateHorizontal(v3f target_speed, f32 max_increase);
123-
void accelerateVertical(v3f target_speed, f32 max_increase);
124-
125122
v3f getPosition()
126123
{
127124
return m_position;

0 commit comments

Comments
 (0)
Please sign in to comment.