diff --git a/app/Game/Client/Control/Key.js b/app/Game/Client/Control/Key.js index 0c3f6bc..ca6e505 100755 --- a/app/Game/Client/Control/Key.js +++ b/app/Game/Client/Control/Key.js @@ -1,4 +1,4 @@ -define(function () { + define(function () { function Key () { this._active = false; diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index a8558ad..b2a34ae 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -1,13 +1,15 @@ define([ + "Lib/Vendor/Box2D", "Game/Core/GameController", "Game/Client/Physics/Engine", "Game/Client/View/ViewController", "Game/Client/Control/PlayerController", "Game/Core/NotificationCenter", - "Lib/Utilities/RequestAnimFrame" + "Lib/Utilities/RequestAnimFrame", + "Game/Config/Settings" ], -function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame) { +function (Box2D, Parent, PhysicsEngine, ViewController, PlayerController, NotificationCenter, requestAnimFrame, Settings) { function GameController () { this.viewController = new ViewController(); @@ -23,6 +25,25 @@ function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationC GameController.prototype = Object.create(Parent.prototype); + GameController.prototype.makeMouseJoint = function(p) { + var ground = this.physicsEngine.getGround(); + var body = this.me.getBody(); + + var def = new Box2D.Dynamics.Joints.b2MouseJointDef(); + + def.bodyA = ground; + def.bodyB = body; + def.target = p; + + def.collideConnected = false; + def.maxForce = 100; + def.dampingRatio = 0.99; + + this.mouse_joint = this.physicsEngine.world.CreateJoint(def); + + body.SetAwake(true); + } + GameController.prototype.destruct = function() { //destroy box2d world etc. }; @@ -48,13 +69,41 @@ function (Parent, PhysicsEngine, ViewController, PlayerController, NotificationC var body = this.physicsEngine.world.GetBodyList(); do { var bodyName = body.GetUserData(); - if(bodyName && updateData[bodyName]) { + if(bodyName && updateData[bodyName]) { var update = updateData[bodyName]; - body.SetAwake(true); - body.SetPosition(update.p); - body.SetAngle(update.a); - body.SetLinearVelocity(update.lv); - body.SetAngularVelocity(update.av); + body.SetAwake(true); + + if(false && this.me && this.me.getBody() == body) { + + var p = body.GetPosition(); + var x = update.p.x - p.x; + var y = update.p.y - p.y; + + var max = 0.5; + var factor = 0.2; + + //if(x > max || x < -max || y > max || y < -max) { + if(!this.mouse_joint) this.makeMouseJoint(update.p); + else this.mouse_joint.SetTarget(update.p); + var self = this; + /*setTimeout(function() { + self.physicsEngine.world.DestroyJoint(self.mouse_joint); + self.mouse_joint = null; + }, Settings.WORLD_UPDATE_BROADCAST_INTERVAL / 2)*/ + //} else { + //this.physicsEngine.world.DestroyJoint(this.mouse_joint); + //this.mouse_joint = null; + //} + + // NEXT TIME, try to create a simple body, that gets position and velocities from server doll + // and connect the joint to that. + + } else { + body.SetPosition(update.p); + body.SetAngle(update.a); + body.SetLinearVelocity(update.lv); + body.SetAngularVelocity(update.av); + } } } while (body = body.GetNext()); diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index aff75d5..b914398 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -22,7 +22,7 @@ define({ WALK_SPEED: 2.5, RUN_SPEED: 4.0, FLY_SPEED: 3.2, - JUMP_SPEED: 3.0, + JUMP_SPEED: 4.0, JUMP_UPLIFT: 0.05, // restitution: bouncyness, friction: rubbing, density: mass @@ -46,5 +46,5 @@ define({ DEBUG_MODE: true, // NETWORKING - WORLD_UPDATE_BROADCAST_INTERVAL: 100 + WORLD_UPDATE_BROADCAST_INTERVAL: 70 }) \ No newline at end of file diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index de67e01..de441c3 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -11,12 +11,17 @@ function (Settings, Box2D, CollisionDetector) { new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), Settings.BOX2D_ALLOW_SLEEP ); + this.ground = null; } Engine.prototype.getWorld = function () { return this.world; } + Engine.prototype.getGround = function () { + return this.ground; + } + Engine.prototype.setCollisionDetector = function (player) { var detector = new CollisionDetector(player); @@ -24,7 +29,9 @@ function (Settings, Box2D, CollisionDetector) { } Engine.prototype.createBody = function (bodyDef) { - return this.world.CreateBody(bodyDef); + var body = this.world.CreateBody(bodyDef); + if(!this.ground) this.ground = body; + return body; } Engine.prototype.update = function () {