This commit is contained in:
Jeremiah Billmann
2013-07-14 14:52:59 -04:00
parent 0883042510
commit 9d364265e9
5 changed files with 37 additions and 15 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ $(function () {
});
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, 15, 15);
ctxCanvas.fillRect(entity.state.x, entity.state.y, 5, 5);
});
});
},
+19 -2
View File
@@ -6,19 +6,26 @@
if (!state.x && !state.y) {
state.x = 0;
state.y = 0;
state.direction = 'right';
}
for (i = 0; i < inputs.length; i ++) {
if (inputs[i].input === 'left') {
state.x -= (50 * deltaTime);
state.direction = 'left';
} else if (inputs[i].input === 'right') {
state.x += (50 * deltaTime);
state.direction = 'right';
} else if (inputs[i].input === 'down') {
state.y += (50 * deltaTime);
state.direction = 'down';
} else if (inputs[i].input === 'up') {
state.y -= (50 * deltaTime);
state.direction = 'up';
} else if (inputs[i].input === 'space') {
if (garageServer) {
garageServer.addEntity(new guid(), { x: state.x, y: state.y, direction: '' });
var newId = guid();
garageServer.addEntity(newId);
garageServer.updateEntityState(newId, { x: state.x, y: state.y, direction: state.direction } );
}
}
}
@@ -26,7 +33,17 @@
};
exports.getNewEntityState = function (state, deltaTime) {
if (state.direction === 'left') {
state.x -= (75 * deltaTime);
} else if (state.direction === 'right') {
state.x += (75 * deltaTime);
} else if (state.direction === 'down') {
state.y += (75 * deltaTime);
} else if (state.direction === 'up') {
state.y -= (75 * deltaTime);
}
return state;
};
exports.getInterpolatedState = function (previousState, targetState, amount) {