diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 4d50a34..ee7cffc 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -14,6 +14,8 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio Parent.call(this, new PhysicsEngine()); + this.physicsEngine.setCollisionDetector(); + this.me = null; this.keyboardController = null; @@ -65,8 +67,6 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio //this.onSpawnPlayer(options); this.me = this.players[playerId]; this.keyboardController = new KeyboardController(this.me, this); - - this.physicsEngine.setCollisionDetector(this.me); } GameController.prototype.onSpawnPlayer = function(options) { diff --git a/app/Game/Core/Collision/Detector.js b/app/Game/Core/Collision/Detector.js index ce87e02..e9c22e9 100755 --- a/app/Game/Core/Collision/Detector.js +++ b/app/Game/Core/Collision/Detector.js @@ -5,14 +5,12 @@ define([ function (Box2D, Parent) { - function Detector (player) { // FIXME evtl.bind(this) ? + function Detector () { // FIXME evtl.bind(this) ? this.listener = new Box2D.Dynamics.b2ContactListener(); this.listener.chuckDetector = this; this.listener.BeginContact = this.BeginContact; - this.listener.PostSolve = this.PostSolve; + //this.listener.PostSolve = this.PostSolve; this.listener.EndContact = this.EndContact; - - this.player = player; } Detector.IDENTIFIER = { @@ -30,10 +28,10 @@ function (Box2D, Parent) { Detector.prototype.handleStand = function (point, isColliding) { - if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.player.id - || point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.player.id) { - - this.player.onFootSensorDetection(isColliding); + if (point.GetFixtureA().GetUserData().identifier == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) { + point.GetFixtureA().GetUserData().player.onFootSensorDetection(isColliding); + } else if (point.GetFixtureB().GetUserData().identifier == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) { + point.GetFixtureB().GetUserData().player.onFootSensorDetection(isColliding); } } @@ -44,7 +42,7 @@ function (Box2D, Parent) { } Detector.prototype.PostSolve = function (point, impulse) { - this.chuckDetector.handleStand(point, true); + //this.chuckDetector.handleStand(point, true); } Detector.prototype.EndContact = function (point) { diff --git a/app/Game/Core/Physics/Doll.js b/app/Game/Core/Physics/Doll.js index ebb2881..fc0db2f 100755 --- a/app/Game/Core/Physics/Doll.js +++ b/app/Game/Core/Physics/Doll.js @@ -6,8 +6,8 @@ define([ function (Box2D, Settings, CollisionDetector) { - function Doll (physicsEngine, id) { - this.id = id; + function Doll (physicsEngine, player) { + this.player = player; this.physicsEngine = physicsEngine; this.body; this.legs; @@ -24,7 +24,7 @@ function (Box2D, Settings, CollisionDetector) { bodyDef.fixedRotation = true; bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; - bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.id; + bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.player.id; this.body = world.CreateBody(bodyDef); @@ -63,7 +63,12 @@ function (Box2D, Settings, CollisionDetector) { feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO)); fixtureDef.shape = feetShape; fixtureDef.isSensor = true; - fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.id; + + fixtureDef.userData = { + identifier: CollisionDetector.IDENTIFIER.PLAYER_FOOT_SENSOR, + player: this.player + } + this.body.CreateFixture(fixtureDef); this.body.SetActive(false); diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index bcca2ff..8545004 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -19,7 +19,7 @@ function (Doll, Settings) { } Player.prototype.spawn = function (x, y) { - this.doll = new Doll(this.physicsEngine, this.id); + this.doll = new Doll(this.physicsEngine, this); this.doll.spawn(x, y); this.isSpawned = true; } diff --git a/app/Game/Server/GameController.js b/app/Game/Server/GameController.js index 44bb984..849d2a5 100755 --- a/app/Game/Server/GameController.js +++ b/app/Game/Server/GameController.js @@ -13,6 +13,8 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No function GameController (channel) { Parent.call(this, new PhysicsEngine()); + this.physicsEngine.setCollisionDetector(); + this.channel = channel; this.update(); @@ -61,8 +63,6 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No GameController.prototype.createPlayer = function(user) { var player = new Player(user.id, this.physicsEngine); player.setInputController(new InputController(player)) - - this.physicsEngine.setCollisionDetector(player); return player; };