From f35b9f5ba9d5e27383607eed8ee906a6fda0378f Mon Sep 17 00:00:00 2001 From: Jeena Date: Sun, 2 Aug 2015 17:22:41 +0200 Subject: [PATCH] fixed flip for RubeDoll --- app/Game/Client/GameObjects/Items/RubeDoll.js | 3 -- app/Game/Config/ItemSettings.js | 2 +- app/Game/Core/GameObjects/Item.js | 2 +- app/Game/Core/GameObjects/Items/RubeDoll.js | 51 +++++++++++-------- static/maps/tiled/debug.json | 2 +- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/app/Game/Client/GameObjects/Items/RubeDoll.js b/app/Game/Client/GameObjects/Items/RubeDoll.js index c494b77..6c848a2 100644 --- a/app/Game/Client/GameObjects/Items/RubeDoll.js +++ b/app/Game/Client/GameObjects/Items/RubeDoll.js @@ -197,9 +197,6 @@ function (Parent, Layer, Settings, Nc) { }; RubeDoll.prototype.flip = function(direction) { - return; - - Parent.prototype.flip.call(this, direction); diff --git a/app/Game/Config/ItemSettings.js b/app/Game/Config/ItemSettings.js index 28ccd63..8724c0a 100644 --- a/app/Game/Config/ItemSettings.js +++ b/app/Game/Config/ItemSettings.js @@ -417,7 +417,7 @@ function () { "image": "banana.gif", "weight": "3", - "width": "5", + "width": "15", "height": "9", "type": "rubedoll", diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index 0662ee4..893f2c8 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -128,8 +128,8 @@ function (Parent, Box2D, Options, Settings, Exception, Nc, Assert) { handPosition.y ); this.body.SetPosition(position); - this.flip(direction); this.body.SetAngle((this.options.grabAngle || 0.0) * direction); + this.flip(direction); }; Item.prototype.getGrabPoint = function() { diff --git a/app/Game/Core/GameObjects/Items/RubeDoll.js b/app/Game/Core/GameObjects/Items/RubeDoll.js index 215a406..33a54ab 100644 --- a/app/Game/Core/GameObjects/Items/RubeDoll.js +++ b/app/Game/Core/GameObjects/Items/RubeDoll.js @@ -73,7 +73,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) lower: this.joints[i].GetLowerLimit(), upper: this.joints[i].GetUpperLimit(), }; - +/* this.joints[i].EnableLimit(false); if(count < 4 && this.joints[i] instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) { @@ -82,6 +82,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) body.GetWorld().DestroyJoint(this.joints[i]); } count++; + */ } }; @@ -92,39 +93,46 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) }; RubeDoll.prototype.flip = function(direction) { + var oldFlipDirection = this.flipDirection; - //Parent.prototype.flip.call(this, direction); - /* + Parent.prototype.flip.call(this, direction); - for (var i in this.joints) { - var joint = this.joints[i]; - var limits = this.limits[i]; + if(oldFlipDirection != direction) { - if (joint instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) { + for (var i in this.joints) { + var joint = this.joints[i]; + var limits = this.limits[i]; - if (direction > 0) { - joint.SetLimits(limits.lower, limits.upper); - continue; - } + if (joint instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) { - var a1 = limits.lower * -1; - var a2 = limits.upper * -1; + if (direction > 0) { + joint.SetLimits(limits.lower, limits.upper); + continue; + } - if (a2 > a1) { - joint.SetLimits(a1, a2); - } else { - joint.SetLimits(a2, a1); + var a1 = limits.lower * -1; + var a2 = limits.upper * -1; + + if (a2 > a1) { + joint.SetLimits(a1, a2); + } else { + joint.SetLimits(a2, a1); + } + + // joint.SetAngle(joint.GetAngle() * -1); } } - }*/ + } }; RubeDoll.prototype.reposition = function(handPosition, direction) { - console.log('repo'); - var oldPosition = this.getPosition(); var oldAngle = this.body.GetAngle(); + var oldDirection = this.flipDirection; + + // calls flip() at the end of Parent reposition() Parent.prototype.reposition.call(this, handPosition, direction); + var differenceAngle = oldAngle - this.body.GetAngle(); //this.body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0)); @@ -154,7 +162,8 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, Matrix, RubeDollJson) limb.SetPosition(globalPoint); // relative limb rotating by chest rotation difference - limb.SetAngle(limb.GetAngle() - differenceAngle); + var d = (oldDirection == direction) ? -1 : 1; + limb.SetAngle((limb.GetAngle() - differenceAngle) * d); //limb.SetType(Box2D.Dynamics.b2Body.b2_staticBody); //limb.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0)); diff --git a/static/maps/tiled/debug.json b/static/maps/tiled/debug.json index 9a065a2..120737a 100644 --- a/static/maps/tiled/debug.json +++ b/static/maps/tiled/debug.json @@ -215,7 +215,7 @@ { "height":0, "id":10, - "name":"Small Cleaver", + "name":"RubeDoll", "properties": {