Browse Source

fall down with greater gravity

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
702ad886af

+ 2
- 1
core.mod/src/WGDefault.cc View File

@@ -34,6 +34,7 @@ void WGDefault::genChunk(Swan::WorldPlane &plane, Swan::Chunk &chunk) {
}

Swan::BodyTrait::HasBody *WGDefault::spawnPlayer(Swan::WorldPlane &plane) {
int x = 0;
return dynamic_cast<Swan::BodyTrait::HasBody *>(
plane.spawnEntity("core::player", Swan::SRFFloatArray{ 0, (float)getHeightAt(perlin_, 0) - 4 }));
plane.spawnEntity("core::player", Swan::SRFFloatArray{ (float)x, (float)getHeightAt(perlin_, x) - 4 }));
}

+ 7
- 1
core.mod/src/entities/EntPlayer.cc View File

@@ -42,11 +42,17 @@ void EntPlayer::update(const Swan::Context &ctx, float dt) {
state_ = State::RUNNING_R;
}

bool jump_pressed = ctx.game.isKeyPressed(SDL_SCANCODE_SPACE);

// Jump
if (body_.on_ground_ && ctx.game.isKeyPressed(SDL_SCANCODE_SPACE) && jump_timer_.periodic(0.5)) {
if (body_.on_ground_ && jump_pressed && jump_timer_.periodic(0.5)) {
body_.vel_.y = -JUMP_FORCE;
}

// Fall down faster than we went up
if (!body_.on_ground_ && (!jump_pressed || body_.vel_.y > 0))
body_.force_ += Swan::Vec2(0, DOWN_FORCE);

if (state_ != oldState)
anims_[(int)state_].reset();
anims_[(int)state_].tick(dt);

+ 1
- 0
core.mod/src/entities/EntPlayer.h View File

@@ -22,6 +22,7 @@ public:
private:
static constexpr float FORCE = 3000;
static constexpr float JUMP_FORCE = 11;
static constexpr float DOWN_FORCE = 1500;
static constexpr float MASS = 80;
static constexpr Swan::Vec2 SIZE = Swan::Vec2(0.6, 1.9);


Loading…
Cancel
Save