mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Broke play, adding input processing from server
This commit is contained in:
+20
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user