mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-05 17:30:44 +08:00
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user