mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
(function(exports){
|
|
|
|
exports.getNewPlayerState = function (state, inputs, deltaTime, garageServer) {
|
|
var i = 0;
|
|
|
|
if (!state.x && !state.y) {
|
|
state.x = 0;
|
|
state.y = 0;
|
|
}
|
|
for (i = 0; i < inputs.length; i ++) {
|
|
if (inputs[i].input === 'left') {
|
|
state.x -= (50 * deltaTime);
|
|
} else if (inputs[i].input === 'right') {
|
|
state.x += (50 * deltaTime);
|
|
} else if (inputs[i].input === 'down') {
|
|
state.y += (50 * deltaTime);
|
|
} else if (inputs[i].input === 'up') {
|
|
state.y -= (50 * deltaTime);
|
|
} else if (inputs[i].input === 'space') {
|
|
if (garageServer) {
|
|
garageServer.addEntity(new guid(), { x: state.x, y: state.y, direction: '' });
|
|
}
|
|
}
|
|
}
|
|
return state;
|
|
};
|
|
|
|
exports.getNewEntityState = function (state, deltaTime) {
|
|
|
|
};
|
|
|
|
exports.getInterpolatedState = function (previousState, targetState, amount) {
|
|
var interpolationState = {};
|
|
interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x));
|
|
interpolationState.y = (previousState.y + amount * (targetState.y - previousState.y));
|
|
return interpolationState;
|
|
};
|
|
|
|
function s4() {
|
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
}
|
|
|
|
function guid() {
|
|
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
}
|
|
|
|
})(typeof exports === 'undefined' ? window.GamePhysics = {} : exports); |