Skip to content

Commit

Permalink
Gloom: Jump control for the user
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent f50addb commit f66027d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions doomsday/tests/test_gloom/gloom/gloomwidget.cpp
Expand Up @@ -196,6 +196,7 @@ bool GloomWidget::handleEvent(Event const &event)
case DDKEY_DOWNARROW: bit = User::Backward; break;
case 'a': bit = User::StepLeft; break;
case 'd': bit = User::StepRight; break;
case ' ': bit = User::Jump; break;
case DDKEY_LSHIFT: bit = User::Shift; break;
default: break;
}
Expand Down
35 changes: 26 additions & 9 deletions doomsday/tests/test_gloom/gloom/world/user.cpp
Expand Up @@ -34,17 +34,18 @@ DENG2_PIMPL(User)
World const *world = nullptr;

InputState input;
Vector3f pos; // Current position of the user (feet).
float height = 1.8f; // Height from feet to top of the head.
float viewHeight = 1.66f; // Eye height.
float yaw = 0;
float pitch = 0;
Vector3f pos; // Current position of the user (feet).
float height = 1.8f; // Height from feet to top of the head.
float viewHeight = 1.66f; // Eye height.
float yaw = 0;
float pitch = 0;
Vector3f momentum;
float angularMomentum = 0;
bool onGround = false;
bool firstUpdate = true;
float crouch = 0;
float crouchMomentum = 0;
bool jumpPending = false;

// For notification:
Vector3f prevPosition;
Expand Down Expand Up @@ -132,7 +133,7 @@ DENG2_PIMPL(User)

if (onGround)
{
float moveFriction = 5;
float moveFriction = 2; //5;

// Apply friction.
Vector2f planar = momentum.xz();
Expand All @@ -148,6 +149,22 @@ DENG2_PIMPL(User)
momentum.x += fric.x;
momentum.z += fric.y;
}

// Jump.
if (input & Jump)
{
jumpPending = true;
}
else if (jumpPending)
{
jumpPending = false;
momentum.y += 9;
}
}
else
{
// Can't jump in air.
jumpPending = false;
}

if (world)
Expand Down Expand Up @@ -182,14 +199,14 @@ DENG2_PIMPL(User)
}
}

if (pos.y <= surface - FLOAT_EPSILON)
if (pos.y <= surface + FLOAT_EPSILON)
{
if (!onGround)
{
playFallDownSound();
if (!firstUpdate)
{
crouchMomentum = min(crouchMomentum, momentum.y - 14);
crouchMomentum = min(crouchMomentum, momentum.y + 8);
}
momentum.y = 0;
}
Expand Down Expand Up @@ -225,7 +242,7 @@ DENG2_PIMPL(User)

// Move in crouch.
crouch += crouchMomentum * elapsed;
crouchMomentum += 2 * elapsed;
crouchMomentum += 3 * elapsed;
if (crouch > 0)
{
crouch = 0;
Expand Down
15 changes: 8 additions & 7 deletions doomsday/tests/test_gloom/gloom/world/user.h
Expand Up @@ -33,13 +33,14 @@ class User
public:
enum InputBit {
Inert = 0,
TurnLeft = 0x1,
TurnRight = 0x2,
Forward = 0x4,
Backward = 0x8,
StepLeft = 0x10,
StepRight = 0x20,
Shift = 0x40
Shift = 0x1,
TurnLeft = 0x2,
TurnRight = 0x4,
Forward = 0x8,
Backward = 0x10,
StepLeft = 0x20,
StepRight = 0x40,
Jump = 0x80,
};
Q_DECLARE_FLAGS(InputState, InputBit)

Expand Down

0 comments on commit f66027d

Please sign in to comment.