diff --git a/app/Game/Client/Collision/Detector.js b/app/Game/Client/Collision/Detector.js index bd30450..3ed456e 100755 --- a/app/Game/Client/Collision/Detector.js +++ b/app/Game/Client/Collision/Detector.js @@ -5,20 +5,11 @@ define([ function (Box2D, Parent) { - function Detector (me) { - Parent.call(this); - this.me = me; + function Detector (player) { + Parent.call(this, player); } 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) { - - this.me.onFootSensorDetection(isColliding); - } - } - return Detector; }); \ No newline at end of file diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 7849e41..4d50a34 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -65,6 +65,8 @@ 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/Client/Networker.js b/app/Game/Client/Networker.js index c938712..8f92484 100755 --- a/app/Game/Client/Networker.js +++ b/app/Game/Client/Networker.js @@ -28,6 +28,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter) { NotificationCenter.on("sendGameCommand", this.sendGameCommand, this); } + // Socket callbacks Networker.prototype.onConnect = function () { @@ -64,6 +65,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter) { } } + // Sending commands Networker.prototype.sendCommand = function (command, options) { @@ -76,6 +78,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter) { this.sendCommand('gameCommand', message); } + // Commands from server Networker.prototype.onUserJoined = function (userId) { diff --git a/app/Game/Core/Collision/Detector.js b/app/Game/Core/Collision/Detector.js index 836dfdb..ce87e02 100755 --- a/app/Game/Core/Collision/Detector.js +++ b/app/Game/Core/Collision/Detector.js @@ -5,12 +5,14 @@ define([ function (Box2D, Parent) { - function Detector () { + function Detector (player) { // 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.EndContact = this.EndContact; + + this.player = player; } Detector.IDENTIFIER = { @@ -27,7 +29,12 @@ function (Box2D, Parent) { } Detector.prototype.handleStand = function (point, isColliding) { - throw "Overwrite this function"; + + 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); + } } /** Extension **/ diff --git a/app/Game/Core/Physics/Doll.js b/app/Game/Core/Physics/Doll.js index 287d689..ebb2881 100755 --- a/app/Game/Core/Physics/Doll.js +++ b/app/Game/Core/Physics/Doll.js @@ -63,7 +63,7 @@ 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.FOOTSENSOR; + fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.id; this.body.CreateFixture(fixtureDef); this.body.SetActive(false); diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index 6b4d1f5..de67e01 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -17,9 +17,9 @@ function (Settings, Box2D, CollisionDetector) { return this.world; } - Engine.prototype.setCollisionDetector = function (me) { + Engine.prototype.setCollisionDetector = function (player) { - var detector = new CollisionDetector(me); // FIXME: check if core collision detector works + var detector = new CollisionDetector(player); this.world.SetContactListener(detector.getListener()); } diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index 3c2b400..bcca2ff 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -158,12 +158,12 @@ function (Doll, Settings) { } this.setStanding(true); } else { - // TODO This needs some more thought to it. - // maybe take a look at collision groups for collision detection, - // to group all tiles together + // TODO This needs some more thought to it. + // maybe take a look at collision groups for collision detection, + // to group all tiles together - //this.setStanding(false); - //this.animate('jumploop'); + //this.setStanding(false); + //this.animate('jumploop'); } } @@ -174,7 +174,7 @@ function (Doll, Settings) { this.stop(); } - if (!this.doll.getBody().IsAwake()) { + if (!this.doll.getBody().IsAwake() && !this.isStanding()) { this.setStanding(true); } } diff --git a/app/Game/Server/Collision/Detector.js b/app/Game/Server/Collision/Detector.js index fddbc61..3ed456e 100755 --- a/app/Game/Server/Collision/Detector.js +++ b/app/Game/Server/Collision/Detector.js @@ -5,15 +5,11 @@ define([ function (Box2D, Parent) { - function Detector () { - Parent.call(this); + function Detector (player) { + Parent.call(this, player); } Detector.prototype = Object.create(Parent.prototype); - Detector.prototype.handleStand = function (point, isColliding) { - throw "Implement this function"; - } - return Detector; }); \ No newline at end of file diff --git a/app/Game/Server/GameController.js b/app/Game/Server/GameController.js index 1a46e55..44bb984 100755 --- a/app/Game/Server/GameController.js +++ b/app/Game/Server/GameController.js @@ -1,6 +1,6 @@ define([ "Game/Core/GameController", - "Game/Core/Physics/Engine", + "Game/Core/Physics/Engine", "Game/Config/Settings", "Game/Server/Control/InputController", "Lib/Utilities/RequestAnimFrame", @@ -61,6 +61,9 @@ 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; };