Fixes for #9 #10 and #11

This commit is contained in:
Jeremiah Billmann
2013-07-03 17:03:52 -04:00
parent c3c2567c1b
commit b1e4e7a52e
7 changed files with 97 additions and 84 deletions
+22 -29
View File
@@ -1,26 +1,21 @@
$(function () {
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', {
var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState(),
requestAnimFrame = (function () {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };
})();
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
logging: true,
clientSidePrediction: true,
interpolation: true,
onUpdatePlayerPhysics: OnProcessGamePhysics,
onInterpolation: function (currentState, previousState, targetState, amount) {
onUpdatePlayerPhysics: onUpdatePlayerPhysics,
onInterpolation: 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;
}
});
var gameCanvas = document.getElementById('gameCanvas'),
keyboard = new THREEx.KeyboardState(),
ctxGameCanvas = gameCanvas.getContext('2d'),
requestAnimFrame = (function () {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000/60); };
})(),
processClientInput = function () {
},
onUpdate: function () {
if (keyboard.pressed('left')) {
GarageServerIO.addPlayerInput('left');
}
@@ -33,22 +28,20 @@ $(function () {
if (keyboard.pressed('up')) {
GarageServerIO.addPlayerInput('up');
}
},
}
});
draw = function () {
ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height);
GarageServerIO.start();
GarageServerIO.setPlayerState({ x: 0, y: 0 });
render();
GarageServerIO.getPlayerStates(function (state) {
ctxGameCanvas.fillRect(state.x, state.y, 15, 15);
});
},
function render () {
requestAnimFrame(render);
update = function () {
requestAnimFrame(update);
processClientInput();
draw();
$('#fps').html('FPS: ' + GarageServerIO.getFPS());
};
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
update();
GarageServerIO.getPlayerStates(function (state) {
ctxCanvas.fillRect(state.x, state.y, 15, 15);
});
}
});