changed function( to function (

This commit is contained in:
logsol 2012-07-28 13:38:31 +02:00
parent 26f3d22db7
commit 7e5eeb0a27
36 changed files with 209 additions and 209 deletions

View file

@ -3,14 +3,14 @@ define([
"Game/Server/CoordinatorLink"
],
function(Channel, CoordinatorLink) {
function (Channel, CoordinatorLink) {
function ChannelBootstrap(process) {
var coordinatorLink = new CoordinatorLink(process);
var channel = null;
process.on('message', function(message) {
process.on('message', function (message) {
switch(message){
case 'CREATE':

View file

@ -3,7 +3,7 @@ define([
"Lib/Vendor/SocketIO"
],
function(Networker, SocketIO) {
function (Networker, SocketIO) {
function Client(location, options) {
this.socket = SocketIO.connect(location, options);

View file

@ -3,7 +3,7 @@ define([
'node-static'
],
function(http, nodeStatic) {
function (http, nodeStatic) {
function HttpServer(options) {
options.port = options.port || 1234;
@ -15,13 +15,13 @@ function(http, nodeStatic) {
this.init(options);
}
HttpServer.prototype.init = function(options) {
HttpServer.prototype.init = function (options) {
var self = this;
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching });
this.server = http.createServer(
function(req, res){
function (req, res){
req.addListener('end', function () {
switch(true) {
case req.url == '/':
@ -37,13 +37,13 @@ function(http, nodeStatic) {
break;
case new RegExp(/^\/app/).test(req.url):
fileServer.serve(req, res, function(){
fileServer.serve(req, res, function (){
self.handleFileError(res)
});
break;
case new RegExp(/^\/static/).test(req.url):
fileServer.serve(req, res, function(){
fileServer.serve(req, res, function (){
self.handleFileError(res)
});
break;
@ -58,7 +58,7 @@ function(http, nodeStatic) {
this.server.listen(options.port);
}
HttpServer.prototype.getServer = function(){
HttpServer.prototype.getServer = function (){
return this.server;
}

View file

@ -4,7 +4,7 @@ define([
"Lobby/Coordinator"
],
function(HttpServer, Socket, Coordinator) {
function (HttpServer, Socket, Coordinator) {
function Server(options) {
coordinator = new Coordinator();

View file

@ -2,7 +2,7 @@ define([
'socket.io'
],
function(io) {
function (io) {
function Socket(server, options, coordinator) {
options.logLevel = typeof options.logLevel != 'undefined'
@ -15,19 +15,19 @@ function(io) {
this.init(options);
}
Socket.prototype.init = function(options){
Socket.prototype.init = function (options){
var self = this;
this.socket.configure('development', function(){
this.socket.configure('development', function (){
this.set('log level', options.logLevel);
});
this.socket.on('connection', function(user){
this.socket.on('connection', function (user){
self.onConnection(user);
});
}
Socket.prototype.onConnection = function(socketLink){
Socket.prototype.onConnection = function (socketLink){
this.coordinator.createUser(socketLink);
}

View file

@ -3,7 +3,7 @@ define([
"Game/Core/Collision/Detector"
],
function(Box2D, Parent) {
function (Box2D, Parent) {
function Detector(me) {
Parent.call(this);
@ -12,7 +12,7 @@ function(Box2D, Parent) {
Detector.prototype = Object.create(Parent.prototype);
Detector.prototype.handleStand = function(point, isColliding) {
Detector.prototype.handleStand = function (point, isColliding) {
if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR
|| point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) {

View file

@ -1,4 +1,4 @@
define(function(){
define(function (){
function Key () {
this._active = false;
@ -9,51 +9,51 @@ define(function(){
this._keyFrameFunction = null;
}
Key.prototype.setActivityUpdateStatus = function(active) {
Key.prototype.setActivityUpdateStatus = function (active) {
this._activityUpdateStatus = active;
}
Key.prototype.getActivityUpdateStatus = function() {
Key.prototype.getActivityUpdateStatus = function () {
return this._activityUpdateStatus;
}
Key.prototype.setActivityUpdateNeeded = function(need) {
Key.prototype.setActivityUpdateNeeded = function (need) {
this._activityUpdateNeeded = need;
}
Key.prototype.getActivityUpdateNeeded = function() {
Key.prototype.getActivityUpdateNeeded = function () {
return this._activityUpdateNeeded;
}
Key.prototype.setActive = function(active) {
Key.prototype.setActive = function (active) {
this._active = active;
}
Key.prototype.getActive = function() {
Key.prototype.getActive = function () {
return this._active;
}
Key.prototype.setKeyDownFunction = function(f) {
Key.prototype.setKeyDownFunction = function (f) {
this._keyDownFunction = f;
}
Key.prototype.getKeyDownFunction = function() {
Key.prototype.getKeyDownFunction = function () {
return this._keyDownFunction;
}
Key.prototype.setKeyUpFunction = function(f) {
Key.prototype.setKeyUpFunction = function (f) {
this._keyUpFunction = f;
}
Key.prototype.getKeyUpFunction = function() {
Key.prototype.getKeyUpFunction = function () {
return this._keyUpFunction;
}
Key.prototype.setKeyFrameFunction = function(f) {
Key.prototype.setKeyFrameFunction = function (f) {
this._keyFrameFunction = f;
}
Key.prototype.getKeyFrameFunction = function() {
Key.prototype.getKeyFrameFunction = function () {
return this._keyFrameFunction;
}

View file

@ -1,4 +1,4 @@
define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"], function(InputController, KeyboardInput){
define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"], function (InputController, KeyboardInput){
function KeyboardController(me, gameController) {
@ -22,7 +22,7 @@ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"
this.init(keys);
}
KeyboardController.prototype.init = function(keys) {
KeyboardController.prototype.init = function (keys) {
this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft');
this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft');
@ -40,53 +40,53 @@ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"
this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
}
KeyboardController.prototype.moveLeft = function() {
KeyboardController.prototype.moveLeft = function () {
this.inputController.moveLeft();
this.gameController.sendGameCommand('moveLeft');
}
KeyboardController.prototype.moveRight = function() {
KeyboardController.prototype.moveRight = function () {
this.inputController.moveRight();
this.gameController.sendGameCommand('moveRight');
}
KeyboardController.prototype.stop = function() {
KeyboardController.prototype.stop = function () {
this.inputController.stop();
this.gameController.sendGameCommand('stop');
}
KeyboardController.prototype.jump = function() {
KeyboardController.prototype.jump = function () {
this.inputController.jump();
this.gameController.sendGameCommand('jump');
}
KeyboardController.prototype.jumped = function() {
KeyboardController.prototype.jumped = function () {
this.inputController.jumped();
}
KeyboardController.prototype.jumping = function() {
KeyboardController.prototype.jumping = function () {
this.inputController.jumping();
}
KeyboardController.prototype.duck = function() {
KeyboardController.prototype.duck = function () {
this.inputController.duck();
this.gameController.sendGameCommand('duck');
}
KeyboardController.prototype.standUp = function() {
KeyboardController.prototype.standUp = function () {
this.inputController.standUp();
}
KeyboardController.prototype.activateShift = function() {
KeyboardController.prototype.activateShift = function () {
this.inputController.activateShift();
this.gameController.sendGameCommand('activateShift');
}
KeyboardController.prototype.deactivateShift = function() {
KeyboardController.prototype.deactivateShift = function () {
this.inputController.deactivateShift();
}
KeyboardController.prototype.update = function() {
KeyboardController.prototype.update = function () {
this.keyboardInput.update();
}

View file

@ -1,4 +1,4 @@
define(["Game/Client/Control/Key"], function(Key){
define(["Game/Client/Control/Key"], function (Key){
function KeyboardInput (keyboardController) {
@ -8,13 +8,13 @@ define(["Game/Client/Control/Key"], function(Key){
this.init();
}
KeyboardInput.prototype.init = function() {
KeyboardInput.prototype.init = function () {
// Using window is ok here because it only runs in the browser
window.onkeydown = this._onKeyDown.bind(this);
window.onkeyup = this._onKeyUp.bind(this);
}
KeyboardInput.prototype.registerKey = function(keyCode, onKeyDown, onKeyUp, onKeyFrame) {
KeyboardInput.prototype.registerKey = function (keyCode, onKeyDown, onKeyUp, onKeyFrame) {
var key = new Key();
key.setKeyDownFunction(onKeyDown);
key.setKeyUpFunction(onKeyUp);
@ -22,11 +22,11 @@ define(["Game/Client/Control/Key"], function(Key){
this._registry[keyCode] = key;
}
KeyboardInput.prototype._getKeyByKeyCode = function(keyCode) {
KeyboardInput.prototype._getKeyByKeyCode = function (keyCode) {
return this._registry[keyCode];
}
KeyboardInput.prototype._onKeyDown = function(e) {
KeyboardInput.prototype._onKeyDown = function (e) {
var key = this._getKeyByKeyCode(e.keyCode);
if (key && key.getActive() == false) {
key.setActivityUpdateStatus(true);
@ -34,7 +34,7 @@ define(["Game/Client/Control/Key"], function(Key){
}
}
KeyboardInput.prototype._onKeyUp = function(e) {
KeyboardInput.prototype._onKeyUp = function (e) {
var key = this._getKeyByKeyCode(e.keyCode);
if (key != null) {
key.setActivityUpdateStatus(false);
@ -42,7 +42,7 @@ define(["Game/Client/Control/Key"], function(Key){
}
}
KeyboardInput.prototype.update = function() {
KeyboardInput.prototype.update = function () {
var callback = null;
var self = this;

View file

@ -7,7 +7,7 @@ define([
"Lib/Utilities/RequestAnimFrame"
],
function(Parent, PhysicsEngine, ViewController, KeyboardController, NotificationCenter, requestAnimFrame) {
function (Parent, PhysicsEngine, ViewController, KeyboardController, NotificationCenter, requestAnimFrame) {
function GameController () {
this.viewController = new ViewController();
@ -25,11 +25,11 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, Notification
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.getMe = function() {
GameController.prototype.getMe = function () {
return this.me;
}
GameController.prototype.update = function() {
GameController.prototype.update = function () {
requestAnimFrame(this.update.bind(this));
@ -42,13 +42,13 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, Notification
}
}
GameController.prototype.meJoined = function(user) {
GameController.prototype.meJoined = function (user) {
this.me = this.userJoined(user);
this.keyboardController = new KeyboardController(this.me, this);
}
GameController.prototype.processGameCommand = function(command, options) {
GameController.prototype.processGameCommand = function (command, options) {
if (command == "worldUpdate") {

View file

@ -3,7 +3,7 @@ define([
"Game/Client/GameController"
],
function(ProtocolHelper, GameController) {
function (ProtocolHelper, GameController) {
function Networker(socketLink) {
this.socketLink = socketLink;
@ -12,41 +12,41 @@ function(ProtocolHelper, GameController) {
this.init();
}
Networker.prototype.init = function() {
Networker.prototype.init = function () {
var self = this;
this.socketLink.on('connect', function() {
this.socketLink.on('connect', function () {
self.onConnect();
});
/*
this.socketLink.on('message', function(message) {
this.socketLink.on('message', function (message) {
self.onMessage(message);
});
*/
this.socketLink.on('disconnect', function() {
this.socketLink.on('disconnect', function () {
self.onDisconnect();
});
}
Networker.prototype.onConnect = function() {
Networker.prototype.onConnect = function () {
console.log('connected.')
this.join('dungeon');
}
Networker.prototype.onDisconnect = function() {
Networker.prototype.onDisconnect = function () {
if(this.gameController) this.gameController.destruct();
this.gameController = null;
console.log('disconnected. game destroyed. no auto-reconnect');
}
Networker.prototype.join = function(channelName){
Networker.prototype.join = function (channelName){
this.sendCommand('join', channelName);
}
Networker.prototype.onJoinSuccess = function(options) {
Networker.prototype.onJoinSuccess = function (options) {
this.gameController = new GameController(options.id);
this.gameController.loadLevel("default.json");
/*
@ -60,35 +60,35 @@ function(ProtocolHelper, GameController) {
*/
}
Networker.prototype.sendCommand = function(command, options) {
Networker.prototype.sendCommand = function (command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
/*
Networker.prototype.onMessage = function(message) {
Networker.prototype.onMessage = function (message) {
var self = this;
ProtocolHelper.runCommands(message, function(command, options) {
ProtocolHelper.runCommands(message, function (command, options) {
self.processControlCommand(command, options);
});
}
Networker.prototype.onUserJoined = function(userId) {
Networker.prototype.onUserJoined = function (userId) {
this.gameController.userJoined(userId);
console.log("User " + userId + " joined");
}
Networker.prototype.sendGameCommand = function(command, options) {
Networker.prototype.sendGameCommand = function (command, options) {
this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options));
}
Networker.prototype.onUserLeft = function(userId) {
Networker.prototype.onUserLeft = function (userId) {
this.gameController.userLeft(userId);
}
Networker.prototype.processControlCommand = function(command, options) {
Networker.prototype.processControlCommand = function (command, options) {
switch(command) {
case 'joinSuccess':
this.onJoinSuccess(options);

View file

@ -5,7 +5,7 @@ define([
"Lib/Vendor/Box2D"
],
function(Parent, Settings, DomController, Box2D) {
function (Parent, Settings, DomController, Box2D) {
function Engine () {
Parent.call(this);
@ -15,7 +15,7 @@ function(Parent, Settings, DomController, Box2D) {
}
}
Engine.prototype.setupDebugDraw = function() {
Engine.prototype.setupDebugDraw = function () {
//var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
var debugSprite = DomController.getDebugCanvas().getContext("2d");
@ -42,7 +42,7 @@ function(Parent, Settings, DomController, Box2D) {
}
Engine.prototype.update = function() {
Engine.prototype.update = function () {
Parent.prototype.update.call(this);
this.world.DrawDebugData();

View file

@ -1,4 +1,4 @@
define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) {
define(['Lib/Vendor/Three', 'Game/Config/Settings'], function (Three, Settings) {
function CameraController(isOrthographic) {
@ -31,17 +31,17 @@ define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) {
this.camera.position.z = 481;
}
CameraController.prototype.getCamera = function(){
CameraController.prototype.getCamera = function (){
return this.camera;
}
CameraController.prototype.setPosition = function(x, y){
CameraController.prototype.setPosition = function (x, y){
this.camera.position.x = x;
this.camera.position.y = y;
}
CameraController.prototype.setZoom = function(z){
CameraController.prototype.setZoom = function (z){
this.camera.position.z = z;
}

View file

@ -1,11 +1,11 @@
define(['Game/Config/Settings'], function(Settings) {
define(['Game/Config/Settings'], function (Settings) {
var DomController = {
canvas: null,
debugCanvas: null
};
DomController.getCanvasContainer = function(){
DomController.getCanvasContainer = function (){
var container = document.getElementById(Settings.CANVAS_DOM_ID);
if(container) {
@ -15,11 +15,11 @@ define(['Game/Config/Settings'], function(Settings) {
}
}
DomController.getCanvas = function(){
DomController.getCanvas = function (){
return DomController.canvas;
}
DomController.setCanvas = function(canvas){
DomController.setCanvas = function (canvas){
var container = DomController.getCanvasContainer();
if(DomController.canvas){
@ -30,11 +30,11 @@ define(['Game/Config/Settings'], function(Settings) {
container.appendChild(canvas);
}
DomController.getDebugCanvas = function(){
DomController.getDebugCanvas = function (){
return DomController.debugCanvas;
}
DomController.createDebugCanvas = function(){
DomController.createDebugCanvas = function (){
var container = DomController.getCanvasContainer();
if(DomController.debugCanvas){

View file

@ -5,7 +5,7 @@ var requires = [
"Game/Client/View/CameraController"
];
define(requires, function(DomController, Three, Settings, CameraController){
define(requires, function (DomController, Three, Settings, CameraController){
function ViewController(){
@ -25,7 +25,7 @@ define(requires, function(DomController, Three, Settings, CameraController){
}
}
ViewController.prototype.init = function(){
ViewController.prototype.init = function (){
var self = this;
@ -61,12 +61,12 @@ define(requires, function(DomController, Three, Settings, CameraController){
this.scene.add(directionalLight);
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function(mesh){
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function (mesh){
self.mesh = mesh;
self.scene.add(mesh);
});
/*
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function (mesh){
self.scene.add(mesh);
});
*/
@ -74,7 +74,7 @@ define(requires, function(DomController, Three, Settings, CameraController){
//this.animate(this);
}
ViewController.prototype.update = function() {
ViewController.prototype.update = function () {
if(this.mesh) {
this.mesh.rotation.z += .01;
@ -86,14 +86,14 @@ define(requires, function(DomController, Three, Settings, CameraController){
this.render();
}
ViewController.prototype.render = function() {
ViewController.prototype.render = function () {
this.renderer.render(this.scene, this.cameraController.getCamera());
}
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
ViewController.prototype.createMesh = function (width, height, x, y, imgPath, callback) {
var textureImg = new Image();
textureImg.onload = function(){
textureImg.onload = function (){
var material = new Three.MeshLambertMaterial({
map: Three.ImageUtils.loadTexture(imgPath)
});

12
app/Game/Core/Collision/Detector.js Normal file → Executable file
View file

@ -3,7 +3,7 @@ define([
"Game/Core/Collision/Detector"
],
function(Box2D, Parent) {
function (Box2D, Parent) {
function Detector() {
this.listener = new Box2D.Dynamics.b2ContactListener();
@ -22,25 +22,25 @@ function(Box2D, Parent) {
PLAYER_FOOT_SENSOR: 'footsensor'
}
Detector.prototype.getListener = function() {
Detector.prototype.getListener = function () {
return this.listener;
}
Detector.prototype.handleStand = function(point, isColliding) {
Detector.prototype.handleStand = function (point, isColliding) {
throw "Overwrite this function";
}
/** Extension **/
Detector.prototype.BeginContact = function(point) {
Detector.prototype.BeginContact = function (point) {
this.chuckDetector.handleStand(point, true);
}
Detector.prototype.PostSolve = function(point, impulse) {
Detector.prototype.PostSolve = function (point, impulse) {
this.chuckDetector.handleStand(point, true);
}
Detector.prototype.EndContact = function(point) {
Detector.prototype.EndContact = function (point) {
this.chuckDetector.handleStand(point, false);
}

View file

@ -1,4 +1,4 @@
define(function(){
define(function (){
function InputController(player) {
@ -8,50 +8,50 @@ define(function(){
this._isJumping;
}
InputController.prototype.moveLeft = function() {
InputController.prototype.moveLeft = function () {
this.player.move(-1);
}
InputController.prototype.moveRight = function() {
InputController.prototype.moveRight = function () {
this.player.move(1);
}
InputController.prototype.stop = function() {
InputController.prototype.stop = function () {
this.player.stop();
}
InputController.prototype.jump = function() {
InputController.prototype.jump = function () {
this._isJumping = true;
this.player.jump();
}
InputController.prototype.jumped = function() {
InputController.prototype.jumped = function () {
this._isJumping = false;
}
InputController.prototype.jumping = function() {
InputController.prototype.jumping = function () {
if (this._isJumping) {
this.player.jumping();
}
}
InputController.prototype.duck = function() {
InputController.prototype.duck = function () {
this.player.duck();
}
InputController.prototype.standUp = function() {
InputController.prototype.standUp = function () {
this.player.standUp();
}
InputController.prototype.activateShift = function() {
InputController.prototype.activateShift = function () {
this._shift = true;
}
InputController.prototype.deactivateShift = function() {
InputController.prototype.deactivateShift = function () {
this._shift = false;
}
InputController.prototype.update = function() {
InputController.prototype.update = function () {
}

View file

@ -4,7 +4,7 @@ define([
"Game/Core/Player"
],
function(Engine, Level, Player) {
function (Engine, Level, Player) {
function GameController(physicsEngine) {
this.players = {};
@ -16,11 +16,11 @@ function(Engine, Level, Player) {
this.physicsEngine = physicsEngine;
}
GameController.prototype.getPhysicsEngine = function() {
GameController.prototype.getPhysicsEngine = function () {
return this.physicsEngine;
}
GameController.prototype.loadLevel = function(path) {
GameController.prototype.loadLevel = function (path) {
if (this.level) {
this.level.unload();
}
@ -31,7 +31,7 @@ function(Engine, Level, Player) {
/*
GameController.prototype.destroy = function() {
GameController.prototype.destroy = function () {
for(var player in this.players) {
this.players[player].destroy();
}
@ -39,13 +39,13 @@ function(Engine, Level, Player) {
GameController.prototype.userJoined = function(user) {
GameController.prototype.userJoined = function (user) {
var player = new Player(user.id, this.physicsEngine);
this.players[user.id] = player;
return player;
}
GameController.prototype.userLeft = function(user) {
GameController.prototype.userLeft = function (user) {
var player = this.players[user.id];
player.destroy();
delete this.players[user.id];

16
app/Game/Core/Loader/Level.js Normal file → Executable file
View file

@ -1,4 +1,4 @@
define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detector"], function(Settings, Box2D, CollisionDetector) {
define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detector"], function (Settings, Box2D, CollisionDetector) {
// Public
function Level(path, engine) {
@ -7,12 +7,12 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
this.levelObject = null;
}
Level.prototype.loadLevelInToEngine = function() {
Level.prototype.loadLevelInToEngine = function () {
this.loadLevelObjectFromPath(this.path);
this.createPhysicTiles();
}
Level.prototype.unload = function() {
Level.prototype.unload = function () {
// TODO unload level from engine if necessary
// Perhaps just remove all bodies?
}
@ -30,7 +30,7 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
}
}
Level.prototype.createPhysicTile = function(tile) {
Level.prototype.createPhysicTile = function (tile) {
tile.r = tile.r || 0;
var vertices = this.createVertices(tile);
@ -55,7 +55,7 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
}
Level.prototype.createVertices = function(tile) {
Level.prototype.createVertices = function (tile) {
var vs = [];
switch(tile.s) {
@ -119,15 +119,15 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
return vs;
}
Level.prototype.mkArg = function(multiplier) {
Level.prototype.mkArg = function (multiplier) {
return Settings.TILE_SIZE / 2 / Settings.RATIO * multiplier;
}
Level.prototype.addVec = function(vs, m1, m2) {
Level.prototype.addVec = function (vs, m1, m2) {
return vs.push(new Box2D.Common.Math.b2Vec2(this.mkArg(m1), this.mkArg(m2)));
}
Level.prototype.loadLevelObjectFromPath = function(path) {
Level.prototype.loadLevelObjectFromPath = function (path) {
// TODO: load JSON levelObject from path
// s: shape

View file

@ -1,14 +1,14 @@
define([
],
function() {
function () {
function NotificationCenter() {
this.topics = {};
this.subUid = -1;
}
NotificationCenter.prototype.trigger = function(topic) {
NotificationCenter.prototype.trigger = function (topic) {
if (!this.topics[topic]) {
throw "No such topic " + topic + ". Could not trigger.";
@ -24,7 +24,7 @@ function() {
}
}
NotificationCenter.prototype.on = function(topic, func, context) {
NotificationCenter.prototype.on = function (topic, func, context) {
if (!this.topics[topic]) {
this.topics[topic] = [];
@ -40,7 +40,7 @@ function() {
return token;
}
NotificationCenter.prototype.off = function(token) {
NotificationCenter.prototype.off = function (token) {
for(var m in this.topics) {
if (this.topics[m]) {

4
app/Game/Core/Physics/Doll.js Normal file → Executable file
View file

@ -1,4 +1,4 @@
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, CollisionDetector) {
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function (Box2D, Settings, CollisionDetector) {
function Doll (physicsEngine, id){
this.id = id;
@ -106,7 +106,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
this.body.ApplyImpulse(vector, this.body.GetPosition());
}
Doll.prototype.destroy = function() {
Doll.prototype.destroy = function () {
this.body.GetWorld().DestroyBody(this.body);
}

View file

@ -4,7 +4,7 @@ define([
"Game/Core/Collision/Detector"
],
function(Settings, Box2D, CollisionDetector) {
function (Settings, Box2D, CollisionDetector) {
function Engine () {
this.world = new Box2D.Dynamics.b2World(
@ -13,21 +13,21 @@ function(Settings, Box2D, CollisionDetector) {
);
}
Engine.prototype.getWorld = function() {
Engine.prototype.getWorld = function () {
return this.world;
}
Engine.prototype.setCollisionDetector = function(me) {
Engine.prototype.setCollisionDetector = function (me) {
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
this.world.SetContactListener(detector.getListener());
}
Engine.prototype.createBody = function(bodyDef) {
Engine.prototype.createBody = function (bodyDef) {
return this.world.CreateBody(bodyDef);
}
Engine.prototype.update = function() {
Engine.prototype.update = function () {
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
this.world.ClearForces();
}

View file

@ -3,7 +3,7 @@ define([
"Game/Config/Settings"
],
function(Doll, Settings) {
function (Doll, Settings) {
function Player (id, physicsEngine, repository) {
this.physicsEngine = physicsEngine;
@ -19,7 +19,7 @@ function(Doll, Settings) {
this.init(id);
}
Player.prototype.init = function(id) {
Player.prototype.init = function (id) {
this.doll = new Doll(this.physicsEngine, id);
//this.mc = EmbedHandler.load(EmbedHandler.CHUCK);
//this.mc.stop();
@ -27,20 +27,20 @@ function(Doll, Settings) {
//mclp.parse(this.mc);
}
Player.prototype.spawn = function(x, y) {
Player.prototype.spawn = function (x, y) {
//this.repository.createModel(this.mc, this.doll.getBody());
this.doll.spawn(x, y);
}
Player.prototype.getDoll = function() {
Player.prototype.getDoll = function () {
return this.doll;
}
Player.prototype.getBody = function() {
Player.prototype.getBody = function () {
return this.doll.getBody();
}
Player.prototype.setStanding = function(isStanding) {
Player.prototype.setStanding = function (isStanding) {
var resetStates = ['jump', 'jumploop'];
if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) {
this.animate('stand');
@ -48,11 +48,11 @@ function(Doll, Settings) {
this.standing = isStanding;
}
Player.prototype.isStanding = function() {
Player.prototype.isStanding = function () {
return this.standing;
}
Player.prototype.move = function(direction) {
Player.prototype.move = function (direction) {
this.moveDirection = direction;
switch(true) {
@ -74,7 +74,7 @@ function(Doll, Settings) {
}
}
Player.prototype.stop = function() {
Player.prototype.stop = function () {
this.moveDirection = 0;
this.doll.stop();
if (this.isWalking() || this.standing) {
@ -82,7 +82,7 @@ function(Doll, Settings) {
}
}
Player.prototype.jump = function() {
Player.prototype.jump = function () {
if (this.isStanding()) {
this.doll.jump();
this.animate('jump');
@ -90,25 +90,25 @@ function(Doll, Settings) {
}
}
Player.prototype.jumping = function() {
Player.prototype.jumping = function () {
if (!this.isStanding()) {
this.doll.jumping();
}
}
Player.prototype.duck = function() {
Player.prototype.duck = function () {
if (this.standing && !this.isWalking()) {
this.animate('duck');
}
}
Player.prototype.standUp = function() {
Player.prototype.standUp = function () {
if (this.standing) {
this.animate('standup');
}
}
Player.prototype.animate = function(type) {
Player.prototype.animate = function (type) {
if (type == this.currentAnimationState) {
return;
}
@ -118,14 +118,14 @@ function(Doll, Settings) {
this.currentAnimationState = type;
}
Player.prototype.calculateWalkAnimation = function() {
Player.prototype.calculateWalkAnimation = function () {
if (this.moveDirection == this.lookDirection) {
return 'run';
}
return 'walkback';
}
Player.prototype.look = function(x, y) {
Player.prototype.look = function (x, y) {
/*
var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
var lastLookDirection = this.lookDirection;
@ -147,7 +147,7 @@ function(Doll, Settings) {
}*/
}
Player.prototype.isWalking = function() {
Player.prototype.isWalking = function () {
var states = ['walk', 'walkback', 'run'];
if (states.indexOf(this.currentAnimationState) >= 0) {
@ -157,7 +157,7 @@ function(Doll, Settings) {
}
// called by CollisionDetection
Player.prototype.onFootSensorDetection = function(isColliding) {
Player.prototype.onFootSensorDetection = function (isColliding) {
if(isColliding) {
if(this.doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) {
return;
@ -173,7 +173,7 @@ function(Doll, Settings) {
}
}
Player.prototype.update = function() {
Player.prototype.update = function () {
//this.mc.head.y = this.mc.head_posmask.y;
if (this.doll.getBody().GetLinearVelocity().x == 0 && this.isWalking()) {
@ -185,7 +185,7 @@ function(Doll, Settings) {
}
}
Player.prototype.destroy = function() {
Player.prototype.destroy = function () {
this.doll.destroy();
}

View file

@ -2,21 +2,21 @@ define([
"Game/Core/Protocol/Parser"
],
function(Parser) {
function (Parser) {
var Helper = {}
Helper.encodeCommand = function(command, options){
Helper.encodeCommand = function (command, options){
return Parser.encode(Helper.assemble(command, options));
}
Helper.assemble = function(command, options){
Helper.assemble = function (command, options){
var commands = {};
commands[command] = options || null;
return commands;
}
Helper.runCommands = function(message, callback){
Helper.runCommands = function (message, callback){
var commands = Parser.decode(message);
for(var command in commands) {

View file

@ -1,15 +1,15 @@
define([
],
function() {
function () {
var Parser = {};
Parser.encode = function(message){
Parser.encode = function (message){
return JSON.stringify(message);
}
Parser.decode = function(message){
Parser.decode = function (message){
return JSON.parse(message);
}

View file

@ -1,4 +1,4 @@
define(function() {
define(function () {
function User(id) {
this.id = id;

View file

@ -3,13 +3,13 @@
"Game/Core/NotificationCenter"
],
function(GameController, NotificationCenter) {
function (GameController, NotificationCenter) {
function Channel(coordinatorLink) {
var self = this;
this.coordinatorLink = coordinatorLink;
this.coordinatorLink.receive = function(message) { self.onMessage(message) };
this.coordinatorLink.receive = function (message) { self.onMessage(message) };
this.users = {};
@ -17,20 +17,20 @@
this.gameController.loadLevel("default.json");
/*
var self = this;
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
NotificationCenter.on("processGameCommandFromUser", function (topic, args) {
self.processGameCommandFromUser.apply(self, args);
});
*/
}
Channel.validateName = function(name){
Channel.validateName = function (name){
return true;
}
// Messages look like:
// {channel: {setName: 'foo'}}
// {user: {jupm: null}, id: 12}
Channel.prototype.onMessage = function(message) {
Channel.prototype.onMessage = function (message) {
for(var recipient in message) {
@ -51,7 +51,7 @@
}
};
Channel.prototype.forward = function(target, message) {
Channel.prototype.forward = function (target, message) {
for(var command in message) {
if(typeof target[command] == 'function'){
target[command].call(target, message[command]);
@ -61,13 +61,13 @@
}
};
Channel.prototype.setName = function(name) {
Channel.prototype.setName = function (name) {
this.name = name;
console.log(' created channel ' + name);
}
/*
Channel.prototype.addUser = function(user){
Channel.prototype.addUser = function (user){
var userIds = Object.keys(this.users);
this.users[user.id] = user;
@ -78,20 +78,20 @@
NotificationCenter.trigger('user/joined', user);
}
Channel.prototype.releaseUser = function(user) {
Channel.prototype.releaseUser = function (user) {
this.gameController.userIdLeft(user.id);
this.sendCommandToAllUsersExcept("userLeft", user.id, user);
delete this.users[user.id];
}
Channel.prototype.sendCommandToAllUsers = function(command, options) {
Channel.prototype.sendCommandToAllUsers = function (command, options) {
for(var id in this.users) {
this.users[id].sendCommand(command, options);
}
}
Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) {
Channel.prototype.sendCommandToAllUsersExcept = function (command, options, except_user) {
for(var id in this.users) {
if (id != except_user.id) {
this.users[id].sendCommand(command, options);
@ -99,7 +99,7 @@
}
}
Channel.prototype.processGameCommandFromUser = function(command, options, user) {
Channel.prototype.processGameCommandFromUser = function (command, options, user) {
this.gameController.progressGameCommandFromUser(command, options, user);
}
*/

4
app/Game/Server/Collision/Detector.js Normal file → Executable file
View file

@ -3,7 +3,7 @@ define([
"Game/Core/Collision/Detector"
],
function(Box2D, Parent) {
function (Box2D, Parent) {
function Detector() {
Parent.call(this);
@ -11,7 +11,7 @@ function(Box2D, Parent) {
Detector.prototype = Object.create(Parent.prototype);
Detector.prototype.handleStand = function(point, isColliding) {
Detector.prototype.handleStand = function (point, isColliding) {
throw "Implement this function";
}

View file

@ -1,17 +1,17 @@
define([
],
function() {
function () {
function CoordinatorLink(process) {
this.process = process;
}
CoordinatorLink.prototype.send = function(message) {
CoordinatorLink.prototype.send = function (message) {
this.process.send(message);
};
CoordinatorLink.prototype.receive = function(message) {
CoordinatorLink.prototype.receive = function (message) {
throw 'This method is abstract and must be overwritten by Channel';
};

View file

@ -7,7 +7,7 @@ define([
"Game/Core/NotificationCenter"
],
function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) {
function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) {
function GameController () {
Parent.call(this, new PhysicsEngine());
@ -23,7 +23,7 @@ function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, Not
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.update = function() {
GameController.prototype.update = function () {
requestAnimFrame(this.update.bind(this));
@ -33,7 +33,7 @@ function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, Not
}
}
GameController.prototype.userJoined = function(user) {
GameController.prototype.userJoined = function (user) {
Parent.prototype.userJoined.call(this, user);
var id = user.id;
@ -41,19 +41,19 @@ function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, Not
this.inputControllers[id] = new InputController(player);
}
GameController.prototype.userLeft = function(user) {
GameController.prototype.userLeft = function (user) {
Parent.prototype.userLeft.call(this, user);
delete this.inputControllers[user.id];
}
GameController.prototype.progressGameCommandFromUser = function(command, options, user) {
GameController.prototype.progressGameCommandFromUser = function (command, options, user) {
var inputController = this.inputControllers[user.id];
if (typeof inputController[command] == 'function') {
inputController[command](options);
}
}
GameController.prototype.updateWorld = function() {
GameController.prototype.updateWorld = function () {
var update = {};
var isUpdateNeeded = false;

View file

@ -4,7 +4,7 @@ define([
"Game/Core/NotificationCenter"
],
function(Parent, ProtocolHelper, NotificationCenter) {
function (Parent, ProtocolHelper, NotificationCenter) {
function User(id, coordinator) {
Parent.call(this, id);
@ -18,17 +18,17 @@ function(Parent, ProtocolHelper, NotificationCenter) {
User.prototype = Object.create(Parent.prototype);
User.prototype.init = function(socketLink){
User.prototype.init = function (socketLink){
var self = this;
}
/*
User.prototype.setChannel = function(channel) {
User.prototype.setChannel = function (channel) {
this.channel = channel;
}
User.prototype.sendCommand = function(command, options) {
User.prototype.sendCommand = function (command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
@ -36,7 +36,7 @@ function(Parent, ProtocolHelper, NotificationCenter) {
User.prototype.toString = function() {
User.prototype.toString = function () {
return "[User " + this.id + "]";
};
*/

View file

@ -2,11 +2,11 @@ define([
'Game/Config/Settings'
],
function(Settings) {
function (Settings) {
var requestAnimFrame = (function(){
var requestAnimFrame = (function (){
var _setTimeout = function( callback ){
var _setTimeout = function ( callback ){
setTimeout(callback, Settings.BOX2D_TIME_STEP * 1000);
}

View file

@ -4,7 +4,7 @@ define([
"child_process"
],
function(User, Channel, childProcess) {
function (User, Channel, childProcess) {
var fork = childProcess.fork;
@ -13,19 +13,19 @@ function(User, Channel, childProcess) {
this.lobbyUsers = {};
}
Coordinator.prototype.createUser = function(socketLink){
Coordinator.prototype.createUser = function (socketLink){
var user = new User(socketLink, this);
this.assignUserToLobby(user);
}
Coordinator.prototype.assignUserToLobby = function(user){
Coordinator.prototype.assignUserToLobby = function (user){
if(user.channelProcess) {
//user.channel.releaseUser(user); -> generate message
}
this.lobbyUsers[user.id] = user;
}
Coordinator.prototype.assignUserToChannel = function(user, channelName){
Coordinator.prototype.assignUserToChannel = function (user, channelName){
if(user.channelProcess) {
//user.channel.releaseUser(user); -> generate message
@ -62,7 +62,7 @@ function(User, Channel, childProcess) {
delete this.lobbyUsers[user.id];
}
Coordinator.prototype.removeUser = function(user){
Coordinator.prototype.removeUser = function (user){
delete this.lobbyUsers[user.id];
if(user.channelProcess) {
//user.channel.releaseUser(user); -> generate message

View file

@ -3,7 +3,7 @@ define([
"Game/Core/Protocol/Helper"
],
function(Parent, ProtocolHelper) {
function (Parent, ProtocolHelper) {
function User(socketLink, coordinator) {
Parent.call(this, socketLink.id);
@ -13,32 +13,32 @@ function(Parent, ProtocolHelper) {
var self = this;
socketLink.on('message', function(message){
socketLink.on('message', function (message){
self.onMessage(message);
});
socketLink.on('disconnect', function(){
socketLink.on('disconnect', function (){
self.onDisconnect();
});
}
User.prototype = Object.create(Parent.prototype);
User.prototype.setChannelProcess = function(channelProcess) {
User.prototype.setChannelProcess = function (channelProcess) {
this.channelProcess = channelProcess;
}
User.prototype.onMessage = function(message){
User.prototype.onMessage = function (message){
var self = this;
ProtocolHelper.runCommands(message, function(command, options){
ProtocolHelper.runCommands(message, function (command, options){
self.processControlCommand(command, options);
});
}
User.prototype.onDisconnect = function(){
User.prototype.onDisconnect = function (){
this.coordinator.removeUser(this);
}
User.prototype.processControlCommand = function(command, options){
User.prototype.processControlCommand = function (command, options){
switch(command) {
case 'join':