Added debug canvas and webgl render canvas, added viewcontroller

This commit is contained in:
logsol 2012-07-13 03:11:29 +02:00
parent 486cb4f312
commit dd71bf79a9
9 changed files with 224 additions and 109 deletions

114
lib/Chuck/Processor.js Normal file → Executable file
View file

@ -1,4 +1,5 @@
var requires = [
"Chuck/View/ViewController",
"Chuck/Physics/Engine",
"Chuck/Player",
"Chuck/Control/InputControlUnit",
@ -8,47 +9,32 @@ var requires = [
"RequestAnimationFrame"
];
define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
define(requires, function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
function Processor () {
this._me;
this._physicsEngine;
this._camera;
this._repository;
this._inputControlUnit;
this._keyboardInput;
this._bodyDef;
this.level;
this.init();
if(Settings.IS_BROWSER_ENVIRONMENT) {
this.initClient();
} else {
this.initServer();
}
};
Processor.prototype.init = function() {
Processor.prototype.initClient = function() {
this.viewController = new ViewController();
this.physicsEngine = new PhysicsEngine();
this.me = new Player(this.physicsEngine, null);
this.me.spawn(100, 0);
this.inputControlUnit = new InputControlUnit(this.me);
this.physicsEngine.setCollisionDetector(this.me);
this._physicsEngine = new PhysicsEngine();
//this._makeBox();
if(Settings.IS_BROWSER_ENVIRONMENT) {
this.update();
}
this._me = new Player(this._physicsEngine, null);
this._me.spawn(100, 0);
this._inputControlUnit = new InputControlUnit(this._me);
//this._camera = Camera.getInstance()
//this._camera.follow(this._me);
//this._repository = Repository.getInstance();
this._physicsEngine.setCollisionDetector(this._me);
}
Processor.prototype.initServer = function() {
this.physicsEngine = new PhysicsEngine();
//this.physicsEngine.setCollisionDetector(players);
//new Chuck.Loader.Level(this._physicsEngine);u
//new Items();
//setInterval(this._update, 1000/60, this);
this._update();
this.update();
}
Processor.prototype.loadLevel = function(path) {
@ -56,69 +42,33 @@ define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box
this.level.unload();
}
this.level = new Level(path, this._physicsEngine);
this.level = new Level(path, this.physicsEngine);
this.level.loadLevelInToEngine();
}
Processor.prototype._makeBox = function() {
var world = this._physicsEngine.getWorld();
var fixDef = new Box2D.Dynamics.b2FixtureDef;
fixDef.density = 1.0;
fixDef.friction = 0.99;
fixDef.restitution = .51;
var bodyDef = new Box2D.Dynamics.b2BodyDef;
// create ground
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
fixDef.shape.SetAsBox(20, 2);
bodyDef.position.Set(10, 400 / 30 + 1.8);
world.CreateBody(bodyDef).CreateFixture(fixDef);
bodyDef.position.Set(10, -1.8);
world.CreateBody(bodyDef).CreateFixture(fixDef);
fixDef.shape.SetAsBox(2, 14);
bodyDef.position.Set(-1.8, 13);
world.CreateBody(bodyDef).CreateFixture(fixDef);
bodyDef.position.Set(21.8, 13);
world.CreateBody(bodyDef).CreateFixture(fixDef);
// create object
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
fixDef.shape.SetAsBox(0.4, 0.4);
bodyDef.position.x = 10;
bodyDef.position.y = 2;
bodyDef.userData = {
'bodyId': 1 + ''
};
world.CreateBody(bodyDef).CreateFixture(fixDef);
this._bodyDef = bodyDef;
}
Processor.prototype.getPhysicsEngine = function() {
return this._physicsEngine;
return this.physicsEngine;
}
Processor.prototype.getMe = function() {
return this._me;
return this.me;
}
Processor.prototype._update = function() {
Processor.prototype.update = function() {
requestAnimFrame(this._update.bind(this));
requestAnimFrame(this.update.bind(this));
//console.log(self._physicsEngine.getWorld().GetBodyList().GetPosition());
//console.log(self.physicsEngine.getWorld().GetBodyList().GetPosition());
this._physicsEngine.update();
this.physicsEngine.update();
if(Settings.IS_BROWSER_ENVIRONMENT) {
this._inputControlUnit.update();
this._me.update();
//self._camera.update();
//self._repository.update();
this.viewController.update();
this.inputControlUnit.update();
this.me.update();
//self.camera.update();
//self.repository.update();
}
}