From de30375828cb9f65f0f7c7e1f8807a9a7d6d3445 Mon Sep 17 00:00:00 2001 From: Eric Fredricksen Date: Wed, 28 Nov 2012 10:01:48 -0800 Subject: [PATCH] Keep track of distance travelled by entities for later head bob usage --- main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 151d3a6..868eb63 100644 --- a/main.js +++ b/main.js @@ -1008,6 +1008,8 @@ function togglePointerLock() { function ballistics(e, elapsed) { // Apply the laws of pseudo-physics + var origin = {x: e.x, y: e.y, z: e.z}; + e.swimming = e.falling && block(e).type.liquid; if (e.ddx || e.ddz) { @@ -1167,6 +1169,8 @@ function ballistics(e, elapsed) { e.dy = 0; } + e.travelled += distance(e, origin); + if (blocke.type.onstep) blocke.type.onstep.call(blocke, e); @@ -2143,6 +2147,7 @@ function Entity(init1, init2) { init('pitch', 0); init('dyaw', 0); init('dpitch', 0); + init('travelled', 0); //init('falling', false); init('birthday', GAME.clock); init('id', function () { return GAME.nextEntityID++} ); @@ -2162,7 +2167,7 @@ function Entity(init1, init2) { Entity.prototype.data = function () { var result = {}; - var keeps = 'x y z dx dy dz yaw pitch dyaw dpitch birthday id'.split(' '); + var keeps = 'x y z dx dy dz yaw pitch dyaw dpitch travelled birthday id'.split(' '); for (var i = 0; i < keeps.length; ++i) { var k = keeps[i]; result[k] = this[k]; -- 2.1.1