mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-24 12:50:31 +08:00
Progress: #3
This commit is contained in:
+7
-1
@@ -26,10 +26,16 @@ Game.prototype.start = function () {
|
||||
|
||||
Game.prototype.update = function () {
|
||||
var players = this.server.getPlayers(),
|
||||
entities = this.server.getEntities(),
|
||||
self = this;
|
||||
|
||||
players.forEach(function (player) {
|
||||
var newState = gamePhysics.getNewState(player.state, player.inputs, self.physicsDelta);
|
||||
var newState = gamePhysics.getNewPlayerState(player.state, player.inputs, self.physicsDelta);
|
||||
self.server.updatePlayerState(player.id, newState);
|
||||
});
|
||||
|
||||
entities.forEach(function (entity) {
|
||||
var newState = gamePhysics.getNewPlayerState(entity.state, self.physicsDelta);
|
||||
self.server.updateEntityState(entity.id, newState);
|
||||
});
|
||||
};
|
||||
@@ -6,7 +6,7 @@ $(function () {
|
||||
|
||||
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
|
||||
logging: true,
|
||||
onUpdatePlayerPhysics: GamePhysics.getNewState,
|
||||
onUpdatePlayerPhysics: GamePhysics.getNewPlayerState,
|
||||
onInterpolation: GamePhysics.getInterpolatedState,
|
||||
onWorldState: function (state) {
|
||||
document.getElementById('gameCanvas').style.width = state.width;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function(exports){
|
||||
|
||||
exports.getNewState = function (state, inputs, deltaTime) {
|
||||
exports.getNewPlayerState = function (state, inputs, deltaTime) {
|
||||
var i = 0;
|
||||
|
||||
if (!state.x && !state.y) {
|
||||
@@ -16,11 +16,17 @@
|
||||
state.y += (50 * deltaTime);
|
||||
} else if (inputs[i].input === 'up') {
|
||||
state.y -= (50 * deltaTime);
|
||||
} else if (inputs[i].input === 'space') {
|
||||
|
||||
}
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.getNewEntityState = function (state, deltaTime) {
|
||||
|
||||
};
|
||||
|
||||
exports.getInterpolatedState = function (previousState, targetState, amount) {
|
||||
var interpolationState = {};
|
||||
interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x));
|
||||
|
||||
Reference in New Issue
Block a user