Skip to content

Commit

Permalink
#8 fix loosing camera room; #10 temporary turn off underwater sound; #9
Browse files Browse the repository at this point in the history
… add rewind mode for samples; #14 add basic AI logic for bears and bats; #3 health, death and basic inventory logic; #15 add fast & slow-motion while holding R & T keys
  • Loading branch information
XProger committed Nov 22, 2016
1 parent 251f993 commit ddf9ae2
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 124 deletions.
1 change: 1 addition & 0 deletions src/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct Animation {
prev = index;
index = animIndex;
next = anims[index].nextAnimation - model->animation;
dir = 1.0f;
time = (animFrame <= 0 ? -animFrame : (animFrame - anim->frameStart)) / 30.0f;
timeMax = (anim->frameEnd - anim->frameStart + lerpToNext) / 30.0f;
framesCount = anim->frameEnd - anim->frameStart + 1;
Expand Down
5 changes: 3 additions & 2 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct Camera : Controller {
vec3 eye = lastDest + dir.cross(vec3(0, 1, 0)).normal() * 2048.0f - vec3(0.0f, 512.0f, 0.0f);
destPos = trace(owner->getRoomIndex(), target, eye, destRoom, true);
}
room = destRoom;
}

pos = pos.lerp(destPos, Core::deltaTime * lerpFactor);
Expand Down Expand Up @@ -153,8 +154,8 @@ struct Camera : Controller {
}

// play underwater sound when camera goes under water
if (lastRoom != room && !level->rooms[lastRoom].flags.water && level->rooms[room].flags.water)
playSound(TR::SND_UNDERWATER, vec3(0.0f), 0);
// if (lastRoom != room && !level->rooms[lastRoom].flags.water && level->rooms[room].flags.water)
// playSound(TR::SND_UNDERWATER, vec3(0.0f), Sound::REPLAY); // TODO: loop sound
}

mViewInv = mat4(pos, target, vec3(0, -1, 0));
Expand Down
36 changes: 22 additions & 14 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ struct Character : Controller {
enum Stand {
STAND_AIR, STAND_GROUND, STAND_SLIDE, STAND_HANG, STAND_UNDERWATER, STAND_ONWATER
} stand;
int input;

enum { LEFT = 1 << 1,
RIGHT = 1 << 2,
FORTH = 1 << 3,
BACK = 1 << 4,
JUMP = 1 << 5,
WALK = 1 << 6,
ACTION = 1 << 7,
WEAPON = 1 << 8,
DEATH = 1 << 9 };
int input, lastInput;

enum Key {
LEFT = 1 << 1,
RIGHT = 1 << 2,
FORTH = 1 << 3,
BACK = 1 << 4,
JUMP = 1 << 5,
WALK = 1 << 6,
ACTION = 1 << 7,
WEAPON = 1 << 8,
DEATH = 1 << 9
};

vec3 velocity;
float angleExt;

Character(TR::Level *level, int entity, int health) : Controller(level, entity), target(-1), health(100), tilt(0.0f), stand(STAND_GROUND), velocity(0.0f) {
Character(TR::Level *level, int entity, int health) : Controller(level, entity), target(-1), health(health), tilt(0.0f), stand(STAND_GROUND), lastInput(0), velocity(0.0f) {
animation.initOverrides();
rotHead = rotChest = quat(0, 0, 0, 1);
}

virtual void hit(int damage) {
virtual void hit(int damage, Controller *enemy = NULL) {
health -= damage;
};

Expand Down Expand Up @@ -63,6 +65,7 @@ struct Character : Controller {
health = 0;
}

virtual void updateVelocity() {}
virtual void updatePosition() {}
virtual Stand getStand() { return stand; }
virtual int getHeight() { return 0; }
Expand All @@ -74,7 +77,7 @@ struct Character : Controller {
virtual int getStateOnwater() { return state; }
virtual int getStateDeath() { return state; }
virtual int getStateDefault() { return state; }
virtual int getInput() { return 0; }
virtual int getInput() { return health <= 0 ? DEATH : 0; }

virtual void updateState() {
int state = animation.state;
Expand Down Expand Up @@ -117,7 +120,12 @@ struct Character : Controller {
angle.z = tilt;
}

bool isPressed(Key key) {
return (input & key) && !(lastInput & key);
}

virtual void update() {
lastInput = input;
input = getInput();
stand = getStand();
updateState();
Expand Down
9 changes: 5 additions & 4 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "mesh.h"
#include "animation.h"

#define GRAVITY 6.0f
#define GRAVITY (6.0f * 30.0f)
#define NO_OVERLAP 0x7FFFFFFF
#define SPRITE_FPS 10.0f

Expand Down Expand Up @@ -165,11 +165,13 @@ struct Controller {

int16 a = level->soundsMap[id];
if (a == -1) return;

TR::SoundInfo &b = level->soundsInfo[a];
if (b.chance == 0 || (rand() & 0x7fff) <= b.chance) {
uint32 c = level->soundOffsets[b.offset + rand() % ((b.flags & 0xFF) >> 2)];
int index = b.offset + rand() % b.flags.count;
uint32 c = level->soundOffsets[index];
void *p = &level->soundData[c];
Sound::play(new Stream(p, 1024 * 1024), pos, (float)b.volume / 0xFFFF, 0.0f, flags);
Sound::play(new Stream(p, 1024 * 1024), pos, (float)b.volume / 0xFFFF, 0.0f, flags | ((b.flags.replay == 1) ? Sound::REPLAY : 0), entity * 1000 + index);
}
}

Expand Down Expand Up @@ -360,7 +362,6 @@ struct Controller {

virtual bool activate(ActionCommand *cmd) { actionCommand = cmd; return true; }
virtual void doCustomCommand (int curFrame, int prevFrame) {}
virtual void updateVelocity() {}
virtual void checkRoom() {}

virtual void cmdOffset(const vec3 &offset) {
Expand Down
3 changes: 2 additions & 1 deletion src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ namespace Debug {
char buf[255];
sprintf(buf, "DIP = %d, TRI = %d, SND = %d", Core::stats.dips, Core::stats.tris, Sound::channelsCount);
Debug::Draw::text(vec2(16, 16), vec4(1.0f), buf);
sprintf(buf, "pos = (%d, %d, %d), room = %d", entity.x, entity.y, entity.z, entity.room);
vec3 angle = ((Controller*)entity.controller)->angle * RAD2DEG;
sprintf(buf, "pos = (%d, %d, %d), angle = (%d, %d), room = %d", entity.x, entity.y, entity.z, (int)angle.x, (int)angle.y, entity.room);
Debug::Draw::text(vec2(16, 32), vec4(1.0f), buf);
int rate = anim.anims[anim.index].frameRate;
sprintf(buf, "state = %d, anim = %d, next = %d, rate = %d, frame = %.2f / %d (%f)", anim.state, anim.index, anim.next, rate, anim.time * 30.0f, anim.framesCount, anim.delta);
Expand Down
Loading

0 comments on commit ddf9ae2

Please sign in to comment.