From 5caa21f45340e70db781abb77b5352e6f8eb7171 Mon Sep 17 00:00:00 2001 From: logsol Date: Sat, 7 Feb 2015 14:30:55 +0100 Subject: [PATCH] fixed item throw interface of ragdoll fixes #93 --- app/Game/Core/GameObjects/Item.js | 8 ++++++-- app/Game/Core/GameObjects/Items/RagDoll.js | 14 +++----------- app/Game/Core/GameObjects/Items/Skateboard.js | 11 +++-------- app/Game/Core/Loader/Level.js | 4 ++-- app/Server/PipeToChannel.js | 6 +++++- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index 6584931..a350bb9 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -130,15 +130,19 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) { }; Item.prototype.throw = function(options, carrierVelocity) { - var body = this.body; + this.accelerateBody(this.body, options, carrierVelocity); + }; + + Item.prototype.accelerateBody = function(body, options, carrierVelocity) { + body.SetAwake(true); var vector = new Box2D.Common.Math.b2Vec2( options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x, -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y ); - this.body.SetLinearVelocity(vector); + body.SetLinearVelocity(vector); body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY); }; diff --git a/app/Game/Core/GameObjects/Items/RagDoll.js b/app/Game/Core/GameObjects/Items/RagDoll.js index be7bfec..fa2bdd0 100644 --- a/app/Game/Core/GameObjects/Items/RagDoll.js +++ b/app/Game/Core/GameObjects/Items/RagDoll.js @@ -334,21 +334,13 @@ function (Parent, Box2D, Settings, Nc) { this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction); }; - RagDoll.prototype.throw = function(x, y) { - Parent.prototype.throw.call(this, x, y); - - var limbDampingFactor = 1; + RagDoll.prototype.throw = function(options, carrierVelocity) { + Parent.prototype.throw.call(this, options, carrierVelocity); for(var name in this.limbs) { var body = this.limbs[name]; - body.SetAwake(true); - var vector = new Box2D.Common.Math.b2Vec2( - x * Settings.MAX_THROW_FORCE * limbDampingFactor / this.options.weight, - -y * Settings.MAX_THROW_FORCE * limbDampingFactor / this.options.weight - ); - body.SetLinearVelocity(vector); - // body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x); + this.accelerateBody(body, options, carrierVelocity); } }; diff --git a/app/Game/Core/GameObjects/Items/Skateboard.js b/app/Game/Core/GameObjects/Items/Skateboard.js index cf1837e..0be6e76 100755 --- a/app/Game/Core/GameObjects/Items/Skateboard.js +++ b/app/Game/Core/GameObjects/Items/Skateboard.js @@ -87,18 +87,13 @@ function (Parent, Box2D, Settings) { // FIXME: implement body flip if necessary }; - Skateboard.prototype.throw = function(x, y) { - Parent.prototype.throw.call(this, x, y); + Skateboard.prototype.throw = function(options, carrierVelocity) { + Parent.prototype.throw.call(this, options, carrierVelocity); for (var i = 0; i < this.wheels.length; i++) { var body = this.wheels[i]; - body.SetAwake(true); - var vector = new Box2D.Common.Math.b2Vec2( - x * Settings.MAX_THROW_FORCE / this.options.weight, - -y * Settings.MAX_THROW_FORCE / this.options.weight - ); - body.SetLinearVelocity(vector); + this.accelerateBody(body, options, carrierVelocity); } }; diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index b94c777..cf3a74b 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -44,8 +44,8 @@ define([ Level.prototype.createItem = function(uid, options) { switch(options.type) { - //case 'skateboard': - // return new Skateboard(this.engine, uid, options); + case 'skateboard': + return new Skateboard(this.engine, uid, options); case 'ragdoll': return new RagDoll(this.engine, uid, options); case 'rube': diff --git a/app/Server/PipeToChannel.js b/app/Server/PipeToChannel.js index 289d8db..0e4ff97 100755 --- a/app/Server/PipeToChannel.js +++ b/app/Server/PipeToChannel.js @@ -14,7 +14,11 @@ function (Nc, childProcess) { this.fork = null; try { - this.fork = fork('channel.js'); + this.fork = fork('channel.js' + /*, { + execArgv: ['--debug=5859'] + }*/ + ); } catch (err) { throw 'Failed to fork channel! (' + err + ')'; }