replaced all tabs with 4 spaces

This commit is contained in:
logsol 2012-07-28 13:26:05 +02:00
parent 5d11540c55
commit 26f3d22db7
30 changed files with 1017 additions and 1011 deletions

View file

@ -1,24 +1,24 @@
define([
"Lib/Vendor/Box2D",
"Game/Core/Collision/Detector"
"Lib/Vendor/Box2D",
"Game/Core/Collision/Detector"
],
function(Box2D, Parent) {
function Detector(me) {
Parent.call(this);
this.me = me;
}
function Detector(me) {
Parent.call(this);
this.me = me;
}
Detector.prototype = Object.create(Parent.prototype);
Detector.prototype = Object.create(Parent.prototype);
Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR
|| point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) {
Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR
|| point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) {
this.me.onFootSensorDetection(isColliding);
}
}
this.me.onFootSensorDetection(isColliding);
}
}
return Detector;
return Detector;
});

View file

@ -8,7 +8,7 @@ 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);

View file

@ -1,76 +1,76 @@
define([
"Game/Core/GameController",
"Game/Client/Physics/Engine",
"Game/Client/View/ViewController",
"Game/Client/Control/KeyboardController",
"Game/Core/NotificationCenter",
"Lib/Utilities/RequestAnimFrame"
"Game/Core/GameController",
"Game/Client/Physics/Engine",
"Game/Client/View/ViewController",
"Game/Client/Control/KeyboardController",
"Game/Core/NotificationCenter",
"Lib/Utilities/RequestAnimFrame"
],
function(Parent, PhysicsEngine, ViewController, KeyboardController, NotificationCenter, requestAnimFrame) {
function GameController () {
this.viewController = new ViewController();
function GameController () {
this.viewController = new ViewController();
Parent.call(this, new PhysicsEngine());
Parent.call(this, new PhysicsEngine());
this.me = null;
this.keyboardController = null;
this.me = null;
this.keyboardController = null;
//NotificationCenter.on('me/joined', this.meJoined, this)
//NotificationCenter.on('me/joined', this.meJoined, this)
//this.update();
}
//this.update();
}
GameController.prototype = Object.create(Parent.prototype);
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.getMe = function() {
return this.me;
}
GameController.prototype.getMe = function() {
return this.me;
}
GameController.prototype.update = function() {
GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
this.viewController.update();
this.physicsEngine.update();
this.viewController.update();
if(this.me) {
this.keyboardController.update();
this.me.update();
}
}
if(this.me) {
this.keyboardController.update();
this.me.update();
}
}
GameController.prototype.meJoined = function(user) {
this.me = this.userJoined(user);
GameController.prototype.meJoined = function(user) {
this.me = this.userJoined(user);
this.keyboardController = new KeyboardController(this.me, this);
}
this.keyboardController = new KeyboardController(this.me, this);
}
GameController.prototype.processGameCommand = function(command, options) {
if (command == "worldUpdate") {
GameController.prototype.processGameCommand = function(command, options) {
if (command == "worldUpdate") {
var body = this.physicsEngine.world.GetBodyList();
do {
var userData = body.GetUserData();
if(userData && options[userData]) {
var update = options[userData];
//console.log('position difference:', (body.GetPosition().y - update.p.y) * 30, body.GetLinearVelocity().y);
body.SetAwake(true);
body.SetPosition(update.p);
body.SetAngle(update.a);
body.SetLinearVelocity(update.lv);
body.SetAngularVelocity(update.av);
}
} while (body = body.GetNext());
var body = this.physicsEngine.world.GetBodyList();
do {
var userData = body.GetUserData();
if(userData && options[userData]) {
var update = options[userData];
//console.log('position difference:', (body.GetPosition().y - update.p.y) * 30, body.GetLinearVelocity().y);
body.SetAwake(true);
body.SetPosition(update.p);
body.SetAngle(update.a);
body.SetLinearVelocity(update.lv);
body.SetAngularVelocity(update.av);
}
} while (body = body.GetNext());
}
}
}
}
*/
return GameController;
return GameController;
});

View file

@ -1,112 +1,118 @@
define([
"Game/Core/Protocol/Helper",
"Game/Client/GameController"
"Game/Core/Protocol/Helper",
"Game/Client/GameController"
],
function(ProtocolHelper, GameController) {
function Networker(socketLink) {
this.socketLink = socketLink;
this.gameController = null;
function Networker(socketLink) {
this.socketLink = socketLink;
this.gameController = null;
this.init();
}
this.init();
}
Networker.prototype.init = function() {
var self = this;
Networker.prototype.init = function() {
var self = this;
this.socketLink.on('connect', function() {
self.onConnect();
});
this.socketLink.on('connect', function() {
self.onConnect();
});
/*
this.socketLink.on('message', function(message) {
self.onMessage(message);
});
this.socketLink.on('message', function(message) {
self.onMessage(message);
});
*/
this.socketLink.on('disconnect', function() {
self.onDisconnect();
});
this.socketLink.on('disconnect', function() {
self.onDisconnect();
});
}
}
Networker.prototype.onConnect = function() {
console.log('connected.')
this.join('dungeon');
}
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){
this.sendCommand('join', channelName);
}
Networker.prototype.onJoinSuccess = function(options) {
this.gameController = new GameController(options.id);
this.gameController.loadLevel("default.json");
/*
console.log("Joined " + options.channelName);
if (options.userIds && options.userIds.length > 0) {
for(var i = 0; i < options.userIds.length; i++) {
this.gameController.userJoined(options.userIds[i])
}
}
*/
}
Networker.prototype.sendCommand = function(command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
Networker.prototype.onConnect = function() {
console.log('connected.')
this.join('dungeon');
}
/*
Networker.prototype.onMessage = function(message) {
var self = this;
ProtocolHelper.runCommands(message, function(command, options) {
self.processControlCommand(command, options);
});
}
Networker.prototype.onMessage = function(message) {
var self = this;
ProtocolHelper.runCommands(message, function(command, options) {
self.processControlCommand(command, options);
});
}
Networker.prototype.onUserJoined = function(userId) {
this.gameController.userJoined(userId);
console.log("User " + userId + " joined");
}
Networker.prototype.sendGameCommand = function(command, options) {
this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options));
}
Networker.prototype.onUserLeft = function(userId) {
this.gameController.userLeft(userId);
}
Networker.prototype.processControlCommand = function(command, options) {
switch(command) {
case 'joinSuccess':
this.onJoinSuccess(options);
break;
case 'gameCommand':
for(var gameCommand in options) {
this.gameController.processGameCommand(gameCommand, options[gameCommand]);
}
break;
case 'userJoined':
this.onUserJoined(options);
break;
case 'userLeft':
this.onUserLeft(options);
break;
default:
break;
}
}
*/
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){
this.sendCommand('join', channelName);
}
Networker.prototype.sendCommand = function(command, options) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
/*
Networker.prototype.onJoinSuccess = function(options) {
this.gameController = new GameController(options.id);
this.gameController.loadLevel("default.json")
console.log("Joined " + options.channelName);
if (options.userIds && options.userIds.length > 0) {
for(var i = 0; i < options.userIds.length; i++) {
this.gameController.userJoined(options.userIds[i])
}
}
}
Networker.prototype.onUserJoined = function(userId) {
this.gameController.userJoined(userId);
console.log("User " + userId + " joined");
}
Networker.prototype.sendGameCommand = function(command, options) {
this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options));
}
Networker.prototype.onUserLeft = function(userId) {
this.gameController.userLeft(userId);
}
Networker.prototype.processControlCommand = function(command, options) {
switch(command) {
case 'joinSuccess':
this.onJoinSuccess(options);
break;
case 'gameCommand':
for(var gameCommand in options) {
this.gameController.processGameCommand(gameCommand, options[gameCommand]);
}
break;
case 'userJoined':
this.onUserJoined(options);
break;
case 'userLeft':
this.onUserLeft(options);
break;
default:
break;
}
}
*/
return Networker;
return Networker;
});

View file

@ -1,50 +1,50 @@
define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) {
function CameraController(isOrthographic) {
function CameraController(isOrthographic) {
isOrthographic = typeof isOrthographic == 'undefined'
? true
: isOrthographic;
isOrthographic = typeof isOrthographic == 'undefined'
? true
: isOrthographic;
if(isOrthographic) {
this.camera = new Three.OrthographicCamera(
-Settings.STAGE_WIDTH/2,
Settings.STAGE_WIDTH/2,
Settings.STAGE_HEIGHT/2,
-Settings.STAGE_HEIGHT/2,
-2000,
1000
);
if(isOrthographic) {
this.camera = new Three.OrthographicCamera(
-Settings.STAGE_WIDTH/2,
Settings.STAGE_WIDTH/2,
Settings.STAGE_HEIGHT/2,
-Settings.STAGE_HEIGHT/2,
-2000,
1000
);
} else {
} else {
this.camera = new Three.PerspectiveCamera(
45,
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
-2000,
1000
);
}
this.camera = new Three.PerspectiveCamera(
45,
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
-2000,
1000
);
}
this.camera.position.z = 481;
}
this.camera.position.z = 481;
}
CameraController.prototype.getCamera = function(){
return this.camera;
}
CameraController.prototype.getCamera = function(){
return this.camera;
}
CameraController.prototype.setPosition = function(x, y){
this.camera.position.x = x;
this.camera.position.y = y;
}
CameraController.prototype.setPosition = function(x, y){
this.camera.position.x = x;
this.camera.position.y = y;
}
CameraController.prototype.setZoom = function(z){
this.camera.position.z = z;
}
CameraController.prototype.setZoom = function(z){
this.camera.position.z = z;
}
return CameraController;
return CameraController;
});

View file

@ -1,53 +1,53 @@
define(['Game/Config/Settings'], function(Settings) {
var DomController = {
canvas: null,
debugCanvas: null
};
var DomController = {
canvas: null,
debugCanvas: null
};
DomController.getCanvasContainer = function(){
var container = document.getElementById(Settings.CANVAS_DOM_ID);
DomController.getCanvasContainer = function(){
var container = document.getElementById(Settings.CANVAS_DOM_ID);
if(container) {
return container;
} else {
throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID;
}
}
if(container) {
return container;
} else {
throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID;
}
}
DomController.getCanvas = function(){
return DomController.canvas;
}
DomController.getCanvas = function(){
return DomController.canvas;
}
DomController.setCanvas = function(canvas){
var container = DomController.getCanvasContainer();
if(DomController.canvas){
container.removeChild(DomController.canvas);
}
DomController.setCanvas = function(canvas){
var container = DomController.getCanvasContainer();
if(DomController.canvas){
container.removeChild(DomController.canvas);
}
DomController.canvas = canvas;
container.appendChild(canvas);
}
DomController.canvas = canvas;
container.appendChild(canvas);
}
DomController.getDebugCanvas = function(){
return DomController.debugCanvas;
}
DomController.getDebugCanvas = function(){
return DomController.debugCanvas;
}
DomController.createDebugCanvas = function(){
var container = DomController.getCanvasContainer();
if(DomController.debugCanvas){
container.removeChild(DomController.debugCanvas);
}
DomController.createDebugCanvas = function(){
var container = DomController.getCanvasContainer();
if(DomController.debugCanvas){
container.removeChild(DomController.debugCanvas);
}
var canvas = document.createElement('canvas');
canvas.width = Settings.STAGE_WIDTH;
canvas.height = Settings.STAGE_HEIGHT;
DomController.debugCanvas = canvas;
container.appendChild(canvas);
}
var canvas = document.createElement('canvas');
canvas.width = Settings.STAGE_WIDTH;
canvas.height = Settings.STAGE_HEIGHT;
DomController.debugCanvas = canvas;
container.appendChild(canvas);
}
return DomController;
return DomController;
});

View file

@ -1,59 +1,59 @@
var requires = [
"Game/Client/View/DomController",
"Lib/Vendor/Three",
"Game/Config/Settings",
"Game/Client/View/CameraController"
"Game/Client/View/DomController",
"Lib/Vendor/Three",
"Game/Config/Settings",
"Game/Client/View/CameraController"
];
define(requires, function(DomController, Three, Settings, CameraController){
function ViewController(){
function ViewController(){
this.mesh = null;
this.scene = null;
this.renderer = null;
this.cameraController = new CameraController();
this.mesh = null;
this.scene = null;
this.renderer = null;
this.cameraController = new CameraController();
this.init();
}
this.init();
}
function isWebGlEnabled () {
try {
return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' );
} catch(e) {
return false;
}
}
function isWebGlEnabled () {
try {
return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' );
} catch(e) {
return false;
}
}
ViewController.prototype.init = function(){
ViewController.prototype.init = function(){
var self = this;
var self = this;
var rendererOptions = {
antialias: true,
preserveDrawingBuffer: true
};
var rendererOptions = {
antialias: true,
preserveDrawingBuffer: true
};
if(isWebGlEnabled()) {
this.renderer = new Three.WebGLRenderer(rendererOptions);
} else {
this.renderer = new Three.CanvasRenderer(rendererOptions);
}
this.renderer.setClearColorHex(0x333333, 1);
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
if(isWebGlEnabled()) {
this.renderer = new Three.WebGLRenderer(rendererOptions);
} else {
this.renderer = new Three.CanvasRenderer(rendererOptions);
}
this.renderer.setClearColorHex(0x333333, 1);
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
DomController.setCanvas(this.renderer.domElement);
DomController.setCanvas(this.renderer.domElement);
if(Settings.DEBUG_MODE){
DomController.createDebugCanvas();
}
if(Settings.DEBUG_MODE){
DomController.createDebugCanvas();
}
this.scene = new Three.Scene();
this.scene.add(this.cameraController.getCamera());
this.scene = new Three.Scene();
this.scene.add(this.cameraController.getCamera());
var ambientLight = new Three.AmbientLight(0xffffff);
var ambientLight = new Three.AmbientLight(0xffffff);
this.scene.add(ambientLight);
var directionalLight = new Three.DirectionalLight(0xffffff);
@ -62,52 +62,52 @@ define(requires, function(DomController, Three, Settings, CameraController){
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function(mesh){
self.mesh = mesh;
self.scene.add(mesh);
self.mesh = mesh;
self.scene.add(mesh);
});
/*
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
self.scene.add(mesh);
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
self.scene.add(mesh);
});
*/
//this.animate(this);
}
}
ViewController.prototype.update = function() {
ViewController.prototype.update = function() {
if(this.mesh) {
this.mesh.rotation.z += .01;
this.mesh.position.z += 1;
this.mesh.position.x += .4;
this.mesh.position.y += .4;
if(this.mesh) {
this.mesh.rotation.z += .01;
this.mesh.position.z += 1;
this.mesh.position.x += .4;
this.mesh.position.y += .4;
}
this.render();
}
this.render();
}
ViewController.prototype.render = function() {
ViewController.prototype.render = function() {
this.renderer.render(this.scene, this.cameraController.getCamera());
}
this.renderer.render(this.scene, this.cameraController.getCamera());
}
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
var textureImg = new Image();
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
var textureImg = new Image();
textureImg.onload = function(){
var material = new Three.MeshLambertMaterial({
map: Three.ImageUtils.loadTexture(imgPath)
});
var material = new Three.MeshLambertMaterial({
map: Three.ImageUtils.loadTexture(imgPath)
});
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
mesh.overdraw = true;/*
mesh.position.z = 0;
mesh.position.x = x;
mesh.position.y = y;
*/
callback(mesh);
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
mesh.overdraw = true;/*
mesh.position.z = 0;
mesh.position.x = x;
mesh.position.y = y;
*/
callback(mesh);
};
textureImg.src = imgPath;
}
}
return ViewController;
return ViewController;
});