Broke play, adding input processing from server

This commit is contained in:
Jeremiah Billmann
2013-06-08 14:16:57 -04:00
parent b6981f21fa
commit dbbbc5bcc4
3 changed files with 46 additions and 17 deletions
+20 -1
View File
@@ -43,4 +43,23 @@ var sockets = io.listen(server);
sockets.set('log level', 0);
garageServer.createGarageServer(sockets, { logging: true });
garageServer.createGarageServer(sockets, {
logging: true,
onUpdatePhysics: function (state, inputs) {
var i = 0;
for (i = 0; i < inputs.length; i ++) {
if (inputs[i] === 'left') {
state.x -= 1;
}
else if (inputs[i] === 'right') {
state.x += 1;
}
else if (inputs[i] === 'down') {
state.y += 1;
}
else if (inputs[i] === 'up') {
state.y -= 1;
}
}
}
});
+2 -5
View File
@@ -15,19 +15,15 @@ $(function () {
handleInput = function () {
if (keyboard.pressed('left')) {
x -= 1;
GarageServerIO.addPlayerInput('left');
}
if (keyboard.pressed('right')) {
x += 1;
GarageServerIO.addPlayerInput('right');
}
if (keyboard.pressed('down')) {
y += 1;
GarageServerIO.addPlayerInput('down');
}
if (keyboard.pressed('up')) {
y -= 1;
GarageServerIO.addPlayerInput('up');
}
},
@@ -35,12 +31,13 @@ $(function () {
processInputs = function () {
//GarageServerIO.processPlayerInput
//GarageServerIO.processClientInput
},
update = function () {
requestAnimFrame(update);
handleInput();
processInputs();
ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height);
ctxGameCanvas.fillRect(x, y, 10, 10);