mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-28 11:15:16 +08:00
Code cleanup
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
var garageServer = require('../lib/server/garageserver.io'),
|
||||
gamePhysics = require('./shared/core');
|
||||
|
||||
|
||||
exports = module.exports = Game;
|
||||
|
||||
function Game (sockets) {
|
||||
@@ -30,7 +30,7 @@ Game.prototype.update = function () {
|
||||
self = this;
|
||||
|
||||
players.forEach(function (player) {
|
||||
var newState = gamePhysics.getNewPlayerState(player.state, player.inputs, self.physicsDelta);
|
||||
var newState = gamePhysics.getNewState(player.state, player.inputs, self.physicsDelta);
|
||||
self.server.updatePlayerState(player.id, newState);
|
||||
});
|
||||
};
|
||||
@@ -3,13 +3,8 @@ $(function () {
|
||||
|
||||
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
|
||||
logging: true,
|
||||
onUpdatePlayerPhysics: getNewPlayerState,
|
||||
onInterpolation: function (id, 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;
|
||||
}
|
||||
onUpdatePlayerPhysics: GamePhysics.getNewState,
|
||||
onInterpolation: GamePhysics.getInterpolatedState
|
||||
});
|
||||
GarageServerIO.setPlayerState({ x: 0, y: 0 });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function(exports){
|
||||
|
||||
exports.getNewPlayerState = function (state, inputs, deltaTime) {
|
||||
exports.getNewState = function (state, inputs, deltaTime) {
|
||||
var i = 0;
|
||||
|
||||
if (!state.x && !state.y) {
|
||||
@@ -21,12 +21,11 @@
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.onUpdateEntityPhysics = function (id, state, deltaTime) {
|
||||
if (!state.x && !state.y) {
|
||||
state.x = 0;
|
||||
state.y = 0;
|
||||
}
|
||||
state.x += (10 * 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;
|
||||
};
|
||||
|
||||
})(typeof exports === 'undefined' ? window : exports);
|
||||
})(typeof exports === 'undefined' ? window.GamePhysics = {} : exports);
|
||||
Reference in New Issue
Block a user