1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-16 18:14:05 +02:00

#22 add Damocles Sword trap

This commit is contained in:
XProger
2017-10-08 03:22:04 +03:00
parent 1fc7072f94
commit 59b6bb3488
4 changed files with 43 additions and 4 deletions

View File

@@ -312,6 +312,10 @@ struct Controller {
return vec3(angle.x, angle.y);
}
static inline void applyGravity(float &speed) {
speed += (speed < 128.0f ? GRAVITY : 30.0f) * Core::deltaTime;
}
bool alignToWall(float offset = 0.0f, int quadrant = -1, int maxDist = 0, int maxWidth = 0) {
int q = angleQuadrant(angle.y);
int ix = int(pos.x);

View File

@@ -279,6 +279,7 @@ namespace TR {
SND_LIGHTNING = 98,
SND_ROCK = 99,
SND_SWORD = 103,
SND_EXPLOSION = 104,
SND_INV_SPIN = 108,
@@ -334,6 +335,7 @@ namespace TR {
HIT_BLADE,
HIT_BOULDER,
HIT_SPIKES,
HIT_SWORD,
HIT_LAVA,
HIT_SLAM,
HIT_REX,
@@ -692,7 +694,7 @@ namespace TR {
}
bool castShadow() const {
return isLara() || isEnemy() || isActor() || type == TRAP_DART;
return isLara() || isEnemy() || isActor() || type == TRAP_DART || type == TRAP_SWORD;
}
void getAxis(int &dx, int &dz) {

View File

@@ -1347,6 +1347,7 @@ struct Lara : Character {
switch (hitType) {
case TR::HIT_BLADE : addBloodBlade(); break;
case TR::HIT_SPIKES : addBloodSpikes(); break;
case TR::HIT_SWORD : addBloodBlade(); break;
case TR::HIT_SLAM : addBloodSlam(enemy); break;
case TR::HIT_LIGHTNING : lightning = (Lightning*)enemy; break;
default : ;
@@ -2483,7 +2484,7 @@ struct Lara : Character {
switch (stand) {
case STAND_AIR :
velocity.y += (velocity.y >= 128.0f ? 30.0f : GRAVITY) * Core::deltaTime;
applyGravity(velocity.y);
if (velocity.y >= 154.0f && state == STATE_FALL)
game->playSound(TR::SND_SCREAM, pos, Sound::PAN);
/*

View File

@@ -775,12 +775,44 @@ struct TrapSlam : Controller {
}
};
#define SWORD_DAMAGE 100.0f
#define SWORD_RANGE 1536.0f
struct TrapSword : Controller {
TrapSword(IGame *game, int entity) : Controller(game, entity) {}
vec3 dir;
float rot;
TrapSword(IGame *game, int entity) : Controller(game, entity), dir(0) {
rot = (randf() * 2.0f - 1.0f) * PI;
}
virtual void update() {
updateAnimation(true);
TR::Level::FloorInfo info;
level->getFloorInfo(getRoomIndex(), int(pos.x), int(pos.y), int(pos.z), info);
Controller *lara = game->getLara();
if (dir.y == 0.0f) {
dir = lara->pos - pos;
if (dir.y > 0 && dir.y < 3072.0f && fabsf(dir.x) < SWORD_RANGE && fabsf(dir.z) < SWORD_RANGE) {
dir /= 32.0f;
dir.y = 50.0f;
} else
dir.y = 0.0f;
} else {
angle.y += rot * Core::deltaTime;
applyGravity(dir.y);
pos += dir * (30.0f * Core::deltaTime);
if (pos.y > info.floor) {
pos.y = info.floor;
game->playSound(TR::SND_SWORD, pos, Sound::PAN);
deactivate(true);
}
updateEntity();
if (collide(lara))
lara->hit(SWORD_DAMAGE * 30.0f * Core::deltaTime, this, TR::HIT_SWORD); // TODO: push lara
}
}
};