diff --git a/example/app.js b/example/app.js index 59870dc..3c810f2 100644 --- a/example/app.js +++ b/example/app.js @@ -9,7 +9,8 @@ var express = require('express'), http = require('http'), path = require('path'), io = require('socket.io'), - garageServer = require('../lib/server/garageserver.io'); + garageServer = require('../lib/server/garageserver.io'), + gamePhysics = require('./shared/core'); var app = express(); @@ -24,6 +25,7 @@ app.configure(function () { app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, '..', 'client'))); + app.use(express.static(path.join(__dirname, 'shared'))); }); app.configure('development', function () { @@ -45,23 +47,5 @@ sockets.set('log level', 0); garageServer.createGarageServer(sockets,{ logging: true, - onUpdatePlayerPhysics: function (state, inputs) { - var i = 0; - if (!state.x && !state.y) { - state.x = 0; - state.y = 0; - } - for (i = 0; i < inputs.length; i ++) { - if (inputs[i].input === 'left') { - state.x -= 1; - } else if (inputs[i].input === 'right') { - state.x += 1; - } else if (inputs[i].input === 'down') { - state.y += 1; - } else if (inputs[i].input === 'up') { - state.y -= 1; - } - } - return state; - } + onUpdatePlayerPhysics: gamePhysics.OnProcessGamePhysics }); diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index b4db930..74820ca 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -3,25 +3,7 @@ $(function () { logging: true, clientSidePrediction: true, interpolation: true, - onUpdatePlayerPhysics: function (state, inputs) { - var i = 0; - if (!state.x && !state.y) { - state.x = 0; - state.y = 0; - } - for (i = 0; i < inputs.length; i ++) { - if (inputs[i].input === 'left') { - state.x -= 1; - } else if (inputs[i].input === 'right') { - state.x += 1; - } else if (inputs[i].input === 'down') { - state.y += 1; - } else if (inputs[i].input === 'up') { - state.y -= 1; - } - } - return state; - }, + onUpdatePlayerPhysics: OnProcessGamePhysics, onInterpolation: function (currentState, previousState, targetState, amount) { var interpolationState = {}; diff --git a/example/shared/core.js b/example/shared/core.js new file mode 100644 index 0000000..badf04c --- /dev/null +++ b/example/shared/core.js @@ -0,0 +1,23 @@ +(function(exports){ + + exports.OnProcessGamePhysics = function (state, inputs) { + var i = 0; + if (!state.x && !state.y) { + state.x = 0; + state.y = 0; + } + for (i = 0; i < inputs.length; i ++) { + if (inputs[i].input === 'left') { + state.x -= 1; + } else if (inputs[i].input === 'right') { + state.x += 1; + } else if (inputs[i].input === 'down') { + state.y += 1; + } else if (inputs[i].input === 'up') { + state.y -= 1; + } + } + return state; + }; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/example/shared/game.js b/example/shared/game.js deleted file mode 100644 index e69de29..0000000 diff --git a/example/views/layout.jade b/example/views/layout.jade index ad35b8e..1c149a9 100644 --- a/example/views/layout.jade +++ b/example/views/layout.jade @@ -7,6 +7,7 @@ html script(src='/garageserver.io.js') script(src='/javascripts/jquery-2.0.0.min.js') script(src='/javascripts/keyboard.min.js') + script(src='core.js') script(src='/javascripts/game.js') body block content \ No newline at end of file