mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Added onReady callback
This commit is contained in:
@@ -7,6 +7,7 @@ $(function () {
|
||||
|
||||
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
|
||||
logging: true,
|
||||
onReady: startGame,
|
||||
onUpdatePlayerPhysics: GamePhysics.getNewPlayerState,
|
||||
onInterpolation: GamePhysics.getInterpolatedState,
|
||||
onWorldState: function (state) {
|
||||
@@ -17,37 +18,39 @@ $(function () {
|
||||
}
|
||||
});
|
||||
|
||||
GameLoop.start(
|
||||
//Render Loop
|
||||
function () {
|
||||
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
|
||||
GarageServerIO.getStates(function (playerStates, entityStates) {
|
||||
playerStates.forEach(function (player) {
|
||||
ctxCanvas.fillRect(player.state.x, player.state.y, playerSize, playerSize);
|
||||
});
|
||||
function startGame() {
|
||||
GameLoop.start(
|
||||
//Render Loop
|
||||
function () {
|
||||
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
|
||||
GarageServerIO.getStates(function (playerStates, entityStates) {
|
||||
playerStates.forEach(function (player) {
|
||||
ctxCanvas.fillRect(player.state.x, player.state.y, playerSize, playerSize);
|
||||
});
|
||||
|
||||
entityStates.forEach(function (entity) {
|
||||
ctxCanvas.fillRect(entity.state.x, entity.state.y, entitySize, entitySize);
|
||||
entityStates.forEach(function (entity) {
|
||||
ctxCanvas.fillRect(entity.state.x, entity.state.y, entitySize, entitySize);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
//Update Loop
|
||||
function () {
|
||||
if (keyboard.pressed('left')) {
|
||||
GarageServerIO.addInput('left');
|
||||
},
|
||||
//Update Loop
|
||||
function () {
|
||||
if (keyboard.pressed('left')) {
|
||||
GarageServerIO.addInput('left');
|
||||
}
|
||||
if (keyboard.pressed('right')) {
|
||||
GarageServerIO.addInput('right');
|
||||
}
|
||||
if (keyboard.pressed('down')) {
|
||||
GarageServerIO.addInput('down');
|
||||
}
|
||||
if (keyboard.pressed('up')) {
|
||||
GarageServerIO.addInput('up');
|
||||
}
|
||||
if (keyboard.pressed('space')) {
|
||||
GarageServerIO.addInput('space');
|
||||
}
|
||||
}
|
||||
if (keyboard.pressed('right')) {
|
||||
GarageServerIO.addInput('right');
|
||||
}
|
||||
if (keyboard.pressed('down')) {
|
||||
GarageServerIO.addInput('down');
|
||||
}
|
||||
if (keyboard.pressed('up')) {
|
||||
GarageServerIO.addInput('up');
|
||||
}
|
||||
if (keyboard.pressed('space')) {
|
||||
GarageServerIO.addInput('space');
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user