From 712509c047195d01edf4dbbc846b0525b7e4da0f Mon Sep 17 00:00:00 2001 From: XProger Date: Tue, 28 May 2019 04:54:04 +0300 Subject: [PATCH] #183 fix "Boulder traps doesn't work" --- src/controller.h | 4 +-- src/lara.h | 4 +-- src/objects.h | 91 +++++++++++++++++++++++++++--------------------- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/controller.h b/src/controller.h index 199e0be..9478aa0 100644 --- a/src/controller.h +++ b/src/controller.h @@ -6,7 +6,7 @@ #include "mesh.h" #include "animation.h" -#define GRAVITY (6.0f * 30.0f) +#define GRAVITY 6.0f #define SPRITE_FPS 10.0f #define MAX_LAYERS 4 @@ -777,7 +777,7 @@ struct Controller { } static inline void applyGravity(float &speed) { - speed += (speed < 128.0f ? GRAVITY : 30.0f) * Core::deltaTime; + speed += (speed < 128.0f ? GRAVITY : 1.0f) * (30.0f * Core::deltaTime); } bool alignToWall(float offset = 0.0f, int quadrant = -1, int maxDist = 0, int maxWidth = 0) { diff --git a/src/lara.h b/src/lara.h index 69967d8..40a677c 100644 --- a/src/lara.h +++ b/src/lara.h @@ -383,7 +383,7 @@ struct Lara : Character { void integrate() { float TIMESTEP = Core::deltaTime; - float ACCEL = 16.0f * GRAVITY * TIMESTEP * TIMESTEP; + float ACCEL = 16.0f * GRAVITY * 30.0f * TIMESTEP * TIMESTEP; float DAMPING = 1.5f; if (lara->stand == STAND_UNDERWATER) { @@ -1529,7 +1529,7 @@ struct Lara : Character { virtual void cmdJump(const vec3 &vel) { vec3 v = vel; if (state == STATE_HANG_UP) - v.y = (3.0f - sqrtf(-2.0f * GRAVITY / 30.0f * (collision.info[Collision::FRONT].floor - pos.y + 800.0f - 128.0f))); + v.y = (3.0f - sqrtf(-2.0f * GRAVITY * (collision.info[Collision::FRONT].floor - pos.y + 800.0f - 128.0f))); Character::cmdJump(v); } diff --git a/src/objects.h b/src/objects.h index f08c63e..c5b25d3 100644 --- a/src/objects.h +++ b/src/objects.h @@ -417,58 +417,71 @@ struct TrapBoulder : Controller { vec3 velocity; - TrapBoulder(IGame *game, int entity) : Controller(game, entity), velocity(0) {} + TrapBoulder(IGame *game, int entity) : Controller(game, entity), velocity(0) { + flags.unused = false; + } virtual void update() { if (flags.active == 0) { - const TR::Entity &e = getEntity(); - pos = vec3(e.x, e.y, e.z); + if (state != STATE_FALL) { + const TR::Entity &e = getEntity(); + roomIndex = e.room; + pos = vec3(float(e.x), float(e.y), float(e.z)); + velocity = vec3(0.0f); + animation.setAnim(0); + flags.unused = false; + } + return; } - TR::Level::FloorInfo info; - getFloorInfo(getRoomIndex(), pos, info); - - vec3 dir = getDir(); - - bool onGround = false; - - if (pos.y >= info.floor - 256) { - onGround = true; - pos.y = info.floor; - velocity = dir * animation.getSpeed(); - if (state != STATE_ROLL) - animation.setState(STATE_ROLL); - } else { - if (velocity.y == 0.0f) - velocity.y = 10.0f; - applyGravity(velocity.y); - animation.setState(STATE_FALL); + if (flags.unused) { + Character *lara = (Character*)game->getLara(pos); + if (lara->collide(this, true)) { + vec3 delta = lara->pos - pos; + Box box(delta + vec3(-125, 0, -125), delta + vec3(125, 762, 125)); + lara->pos += getBoundingBoxLocal().pushOut2D(box); + } + return; } vec3 p = pos; + + if (velocity.y != 0.0f) { + applyGravity(velocity.y); + } pos += velocity * (30.0f * Core::deltaTime); - if (info.roomNext != TR::NO_ROOM) - roomIndex = info.roomNext; + TR::Room::Sector *sector = level->getSector(roomIndex, pos); + p.y = level->getFloor(sector, pos); - if (onGround) { - game->checkTrigger(this, true); - } - - vec3 v = pos + getDir() * 512.0f; - getFloorInfo(getRoomIndex(), v, info); - if (pos.y > info.floor) { - if (onGround) { - pos = p; - game->checkTrigger(this, true); - return; - } else { - pos.x = p.x; - pos.z = p.z; - velocity.x = velocity.z = 0.0f; + if (pos.y < p.y) { + if (velocity.y == 0.0f) { + velocity.y = -10.0f; + } + } else { + if (state != STATE_ROLL) { + animation.setState(STATE_ROLL); + velocity = getDir() * animation.getSpeed(); } } + if (pos.y >= p.y - 256.0f) { + velocity.y = 0.0f; + pos.y = p.y; + } + + int16 roomIdx = this->roomIndex; + vec3 v = pos + getDir() * 512.0f; + sector = level->getSector(roomIdx, v); + if (pos.y > level->getFloor(sector, v)) { + velocity.y = 0.0f; + pos = p; + flags.unused = true; + } + + game->checkTrigger(this, true); + updateAnimation(true); + Character *lara = (Character*)game->getLara(pos); if (lara->health > 0.0f && collide(lara)) { if (lara->stand == Character::STAND_GROUND) @@ -476,8 +489,6 @@ struct TrapBoulder : Controller { if (lara->stand == Character::STAND_AIR) lara->hit(BOULDER_DAMAGE_AIR * 30.0f * Core::deltaTime, this); } - - updateAnimation(true); } };