diff --git a/app/Game/Asset/RubeDoll.json b/app/Game/Asset/RubeDoll.json index 114e29f..37e4c0e 100644 --- a/app/Game/Asset/RubeDoll.json +++ b/app/Game/Asset/RubeDoll.json @@ -5,6 +5,57 @@ "body" : [ + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture2", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.1570904254913330, + 0.1570904254913330, + -0.1156365871429443, + -0.1156365871429443 + ], + "y" : + [ + -0.3584164977073669, + 0.4034895300865173, + 0.4034895300865173, + -0.3584164977073669 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.01153474207967520, + "massData-center" : + { + "x" : 0.02072691917419434, + "y" : 0.02253651618957520 + }, + "massData-mass" : 0.2077923566102982, + "name" : "chest", + "position" : + { + "x" : -0.04104747623205185, + "y" : 0.7829875946044922 + }, + "type" : 2 + }, + { "angle" : 0, "angularVelocity" : 0, @@ -67,86 +118,42 @@ "density" : 1, "filter-groupIndex" : -55, "friction" : 0.2, - "name" : "fixture0", + "name" : "fixture3", "polygon" : { "vertices" : { "x" : [ - 0.1402979493141174, - 0.1375417709350586, - 0.001378186047077179, - -0.1402979493141174, - -0.1402979493141174, - 0.001192390918731689 + 0.07039496302604675, + 0.07039496302604675, + -0.07039486616849899, + -0.07039486616849899 ], "y" : [ - -0.3207050263881683, - 0.4018019437789917, - 0.4018019437789917, - 0.3136067390441895, - -0.3432337343692780, - -0.3689299821853638 + -0.09294389933347702, + 0.1276105940341949, + 0.1276105940341949, + -0.09294389933347702 ] } } } ], "linearVelocity" : 0, - "massData-I" : 0.01047351956367493, + "massData-I" : 0.0001864957448560745, "massData-center" : { - "x" : 0.001456731930375099, - "y" : 0.01425695233047009 + "x" : 4.842877032729120e-08, + "y" : 0.01733334921300411 }, - "massData-mass" : 0.2038488984107971, - "name" : "chest", + "massData-mass" : 0.03105182945728302, + "name" : "lowerRightLeg", "position" : { - "x" : -0.04104747623205185, - "y" : 0.7829875946044922 - }, - "type" : 2 - }, - - { - "angle" : 0, - "angularVelocity" : 0, - "awake" : true, - "fixture" : - [ - - { - "circle" : - { - "center" : - { - "x" : -0.002679032273590565, - "y" : 0.004700660705566406 - }, - "radius" : 0.2268356680870056 - }, - "density" : 0.2204959988594055, - "filter-groupIndex" : -55, - "friction" : 0.2, - "name" : "fixture1" - } - ], - "linearVelocity" : 0, - "massData-I" : 0.0009180362685583532, - "massData-center" : - { - "x" : -0.002679032273590565, - "y" : 0.004700660705566406 - }, - "massData-mass" : 0.03564291819930077, - "name" : "head", - "position" : - { - "x" : 0.009572610259056091, - "y" : 1.462979435920715 + "x" : 0.02818956598639488, + "y" : 0.1036150008440018 }, "type" : 2 }, @@ -169,35 +176,35 @@ { "x" : [ - 0.04693000018596649, - 0.04693000018596649, - -0.04693005979061127, - -0.04693005979061127 + 0.07039505988359451, + 0.07039505988359451, + -0.07039495557546616, + -0.07039495557546616 ], "y" : [ - -0.1159216761589050, - 0.1159217953681946, - 0.1159217953681946, - -0.1159216761589050 + -0.1890522241592407, + 0.1890524625778198, + 0.1890524625778198, + -0.1890522241592407 ] } } } ], "linearVelocity" : 0, - "massData-I" : 0.0001134485355578363, + "massData-I" : 0.000722132739610970, "massData-center" : { - "x" : -2.980232238769531e-08, - "y" : 5.960464477539062e-08 + "x" : 5.215406417846680e-08, + "y" : 1.192092824453539e-07 }, - "massData-mass" : 0.02176084183156490, - "name" : "lowerRightArm", + "massData-mass" : 0.05323336645960808, + "name" : "upperLeftLeg", "position" : { - "x" : 0.09864036738872528, - "y" : 0.6898344159126282 + "x" : -0.06537666171789169, + "y" : 0.3381301760673523 }, "type" : 2 }, @@ -304,57 +311,6 @@ "type" : 2 }, - { - "angle" : 0, - "angularVelocity" : 0, - "awake" : true, - "fixture" : - [ - - { - "density" : 1, - "filter-groupIndex" : -55, - "friction" : 0.2, - "name" : "fixture3", - "polygon" : - { - "vertices" : - { - "x" : - [ - 0.04693000018596649, - 0.04693000018596649, - -0.04693005979061127, - -0.04693005979061127 - ], - "y" : - [ - -0.1895973682403564, - 0.1895966529846191, - 0.1895966529846191, - -0.1895973682403564 - ] - } - } - } - ], - "linearVelocity" : 0, - "massData-I" : 0.0004525946278590709, - "massData-center" : - { - "x" : -2.980232238769531e-08, - "y" : -3.576278686523438e-07 - }, - "massData-mass" : 0.03559117391705513, - "name" : "upperRightArm", - "position" : - { - "x" : 0.09864036738872528, - "y" : 0.9068759679794312 - }, - "type" : 2 - }, - { "angle" : 0, "angularVelocity" : 0, @@ -424,35 +380,35 @@ { "x" : [ - 0.07039505988359451, - 0.07039505988359451, - -0.07039495557546616, - -0.07039495557546616 + 0.04693000018596649, + 0.04693000018596649, + -0.04693005979061127, + -0.04693005979061127 ], "y" : [ - -0.1890522241592407, - 0.1890524625778198, - 0.1890524625778198, - -0.1890522241592407 + -0.1895973682403564, + 0.1895966529846191, + 0.1895966529846191, + -0.1895973682403564 ] } } } ], "linearVelocity" : 0, - "massData-I" : 0.000722132739610970, + "massData-I" : 0.0004525946278590709, "massData-center" : { - "x" : 5.215406417846680e-08, - "y" : 1.192092824453539e-07 + "x" : -2.980232238769531e-08, + "y" : -3.576278686523438e-07 }, - "massData-mass" : 0.05323336645960808, - "name" : "upperLeftLeg", + "massData-mass" : 0.03559117391705513, + "name" : "upperRightArm", "position" : { - "x" : -0.06537666171789169, - "y" : 0.3381301760673523 + "x" : 0.09864036738872528, + "y" : 0.9068759679794312 }, "type" : 2 }, @@ -475,35 +431,75 @@ { "x" : [ - 0.07039496302604675, - 0.07039496302604675, - -0.07039486616849899, - -0.07039486616849899 + 0.04693000018596649, + 0.04693000018596649, + -0.04693005979061127, + -0.04693005979061127 ], "y" : [ - -0.09294389933347702, - 0.1276105940341949, - 0.1276105940341949, - -0.09294389933347702 + -0.1159216761589050, + 0.1159217953681946, + 0.1159217953681946, + -0.1159216761589050 ] } } } ], "linearVelocity" : 0, - "massData-I" : 0.0001864957448560745, + "massData-I" : 0.0001134485355578363, "massData-center" : { - "x" : 4.842877032729120e-08, - "y" : 0.01733334921300411 + "x" : -2.980232238769531e-08, + "y" : 5.960464477539062e-08 }, - "massData-mass" : 0.03105182945728302, - "name" : "lowerRightLeg", + "massData-mass" : 0.02176084183156490, + "name" : "lowerRightArm", "position" : { - "x" : 0.02818956598639488, - "y" : 0.1036150008440018 + "x" : 0.09864036738872528, + "y" : 0.6898344159126282 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "circle" : + { + "center" : + { + "x" : -0.01561669446527958, + "y" : 0.004700659774243832 + }, + "radius" : 0.2268356680870056 + }, + "density" : 0.2204959988594055, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture1" + } + ], + "linearVelocity" : 0, + "massData-I" : 0.0009264730615541339, + "massData-center" : + { + "x" : -0.01561669446527958, + "y" : 0.004700659774243832 + }, + "massData-mass" : 0.03564291819930077, + "name" : "head", + "position" : + { + "x" : 0.009572610259056091, + "y" : 1.462979435920715 }, "type" : 2 } @@ -555,181 +551,6 @@ "joint" : [ - { - "anchorA" : - { - "x" : 0.06392270326614380, - "y" : 0.4330990314483643 - }, - "anchorB" : - { - "x" : 0.01330260001122952, - "y" : -0.2468919754028320 - }, - "bodyA" : 1, - "bodyB" : 2, - "enableLimit" : true, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : -0.6981316804885864, - "maxMotorTorque" : 0, - "motorSpeed" : 0, - "name" : "joint9", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 1.221730470657349 - }, - - { - "anchorA" : - { - "x" : 0.0008554458618164062, - "y" : -0.1461489200592041 - }, - "anchorB" : - { - "x" : 0.0008557140827178955, - "y" : 0.07089227437973022 - }, - "bodyA" : 0, - "bodyB" : 5, - "enableLimit" : true, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : -1.919862151145935, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint4", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 0.01745329238474369 - }, - - { - "anchorA" : - { - "x" : 0.0003538504242897034, - "y" : 0.07107692956924438 - }, - "anchorB" : - { - "x" : 0.0003536641597747803, - "y" : -0.1459646224975586 - }, - "bodyA" : 3, - "bodyB" : 6, - "enableLimit" : true, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : -1.919862151145935, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint1", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 0.01745329238474369 - }, - - { - "anchorA" : - { - "x" : 0.001979876309633255, - "y" : -0.1506856828927994 - }, - "anchorB" : - { - "x" : 0.001979988068342209, - "y" : 0.08382888138294220 - }, - "bodyA" : 7, - "bodyB" : 9, - "enableLimit" : true, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : 0.01745329238474369, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint8", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 2.268928050994873 - }, - - { - "anchorA" : - { - "x" : -0.0007802918553352356, - "y" : -0.1484908312559128 - }, - "anchorB" : - { - "x" : -0.0007800981402397156, - "y" : 0.08614097535610199 - }, - "bodyA" : 8, - "bodyB" : 4, - "enableLimit" : true, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : 0.01745329238474369, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint7", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 2.268928050994873 - }, - - { - "anchorA" : - { - "x" : -0.09517393261194229, - "y" : 0.2718780040740967 - }, - "anchorB" : - { - "x" : -1.741945743560791e-05, - "y" : 0.1479903459548950 - }, - "bodyA" : 1, - "bodyB" : 0, - "enableLimit" : false, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : -2.268928050994873, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint3", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 3.141592741012573 - }, - - { - "anchorA" : - { - "x" : 0.1396137326955795, - "y" : 0.2701327800750732 - }, - "anchorB" : - { - "x" : -7.455050945281982e-05, - "y" : 0.1462446451187134 - }, - "bodyA" : 1, - "bodyB" : 6, - "enableLimit" : false, - "enableMotor" : false, - "jointSpeed" : 0, - "lowerLimit" : -2.268928050994873, - "maxMotorTorque" : 1, - "motorSpeed" : 0, - "name" : "joint2", - "refAngle" : 0, - "type" : "revolute", - "upperLimit" : 3.141592741012573 - }, - { "anchorA" : { @@ -741,8 +562,8 @@ "x" : -0.04493143409490585, "y" : 0.1559127867221832 }, - "bodyA" : 1, - "bodyB" : 8, + "bodyA" : 0, + "bodyB" : 3, "enableLimit" : true, "enableMotor" : false, "jointSpeed" : 0, @@ -766,8 +587,8 @@ "x" : 0.04127830639481544, "y" : 0.1504460573196411 }, - "bodyA" : 1, - "bodyB" : 7, + "bodyA" : 0, + "bodyB" : 6, "enableLimit" : true, "enableMotor" : false, "jointSpeed" : 0, @@ -778,6 +599,181 @@ "refAngle" : 0, "type" : "revolute", "upperLimit" : 1.919862151145935 + }, + + { + "anchorA" : + { + "x" : -0.0007802918553352356, + "y" : -0.1484908312559128 + }, + "anchorB" : + { + "x" : -0.0007800981402397156, + "y" : 0.08614097535610199 + }, + "bodyA" : 3, + "bodyB" : 4, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : 0.01745329238474369, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint7", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 2.268928050994873 + }, + + { + "anchorA" : + { + "x" : 0.001979876309633255, + "y" : -0.1506856828927994 + }, + "anchorB" : + { + "x" : 0.001979988068342209, + "y" : 0.08382888138294220 + }, + "bodyA" : 6, + "bodyB" : 2, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : 0.01745329238474369, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint8", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 2.268928050994873 + }, + + { + "anchorA" : + { + "x" : 0.0003538504242897034, + "y" : 0.07107692956924438 + }, + "anchorB" : + { + "x" : 0.0003536641597747803, + "y" : -0.1459646224975586 + }, + "bodyA" : 8, + "bodyB" : 7, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -1.919862151145935, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint1", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 0 + }, + + { + "anchorA" : + { + "x" : 0.06392270326614380, + "y" : 0.4330990314483643 + }, + "anchorB" : + { + "x" : 0.01330260001122952, + "y" : -0.2468919754028320 + }, + "bodyA" : 0, + "bodyB" : 9, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -0.6981316804885864, + "maxMotorTorque" : 0, + "motorSpeed" : 0, + "name" : "joint9", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 1.221730470657349 + }, + + { + "anchorA" : + { + "x" : 0.1396137326955795, + "y" : 0.2701327800750732 + }, + "anchorB" : + { + "x" : -7.455050945281982e-05, + "y" : 0.1462446451187134 + }, + "bodyA" : 0, + "bodyB" : 7, + "enableLimit" : false, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -2.268928050994873, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint2", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 3.141592741012573 + }, + + { + "anchorA" : + { + "x" : -0.09517393261194229, + "y" : 0.2718780040740967 + }, + "anchorB" : + { + "x" : -1.741945743560791e-05, + "y" : 0.1479903459548950 + }, + "bodyA" : 0, + "bodyB" : 1, + "enableLimit" : false, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -2.268928050994873, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint3", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 3.141592741012573 + }, + + { + "anchorA" : + { + "x" : 0.0008554458618164062, + "y" : -0.1461489200592041 + }, + "anchorB" : + { + "x" : 0.0008557140827178955, + "y" : 0.07089227437973022 + }, + "bodyA" : 1, + "bodyB" : 5, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -1.919862151145935, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint4", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 0.01745329238474369 } ], "positionIterations" : 3, diff --git a/app/Game/Channel/GameController.js b/app/Game/Channel/GameController.js index 571b088..6b3b1db 100755 --- a/app/Game/Channel/GameController.js +++ b/app/Game/Channel/GameController.js @@ -9,10 +9,10 @@ define([ "Game/Channel/Player", "Game/Channel/GameObjects/GameObject", "Game/Channel/GameObjects/Doll", - "Game/Channel/GameObjects/Items/RagDoll" + "Game/Channel/GameObjects/Items/RubeDoll" ], -function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RagDoll) { +function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RubeDoll) { "use strict"; @@ -172,7 +172,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N var objects = []; for (var i = 0; i < this.gameObjects.animated.length; i++) { - if(this.gameObjects.animated[i] instanceof RagDoll) { + if(this.gameObjects.animated[i] instanceof RubeDoll) { var object = this.gameObjects.animated[i]; var options = object.options; options.x = object.getPosition().x; diff --git a/app/Game/Channel/GameObjects/Items/RubeDoll.js b/app/Game/Channel/GameObjects/Items/RubeDoll.js index b810471..dfad73f 100644 --- a/app/Game/Channel/GameObjects/Items/RubeDoll.js +++ b/app/Game/Channel/GameObjects/Items/RubeDoll.js @@ -9,10 +9,20 @@ function (Parent, Settings, Nc) { "use strict"; function RubeDoll(physicsEngine, uid, options) { + this.scheduledForDestruction = false; + this.destructionTimeout = null; + Parent.call(this, physicsEngine, uid, options); } RubeDoll.prototype = Object.create(Parent.prototype); + + RubeDoll.prototype.beingGrabbed = function(player) { + Parent.prototype.beingGrabbed.call(this, player); + if(this.scheduledForDestruction) { + clearTimeout(this.destructionTimeout); + } + }; RubeDoll.prototype.beingReleased = function(player) { Parent.prototype.beingReleased.call(this, player); diff --git a/app/Game/Client/GameObjects/Items/RubeDoll.js b/app/Game/Client/GameObjects/Items/RubeDoll.js index 078fd9a..4075560 100644 --- a/app/Game/Client/GameObjects/Items/RubeDoll.js +++ b/app/Game/Client/GameObjects/Items/RubeDoll.js @@ -93,6 +93,7 @@ function (Parent, Layer, Settings, Nc) { this.limbMeshes = {}; this.baseMeshName = "chest"; this.characterName = "Chuck"; + this.lastFlipDirection = 1; Parent.call(this, physicsEngine, uid, options); } @@ -101,10 +102,8 @@ function (Parent, Layer, Settings, Nc) { RubeDoll.prototype.createMesh = function() { - this.createLimbMesh("lowerRightLeg"); this.createLimbMesh("upperRightLeg"); - this.createLimbMesh("lowerRightArm"); this.createLimbMesh("upperRightArm"); @@ -113,7 +112,6 @@ function (Parent, Layer, Settings, Nc) { this.createLimbMesh("lowerLeftLeg"); this.createLimbMesh("upperLeftLeg"); - this.createLimbMesh("lowerLeftArm"); this.createLimbMesh("upperLeftArm"); @@ -187,6 +185,48 @@ function (Parent, Layer, Settings, Nc) { }; RubeDoll.prototype.flip = function(direction) { + Parent.prototype.flip.call(this, direction); + + if(this.limbs) { + for(var name in this.limbMeshes) { + if(this.limbs[name]) { + Nc.trigger(Nc.ns.client.view.mesh.update, + this.layerId, + this.limbMeshes[name], + { + xScale: direction, + } + ); + } + } + } + + // flipping depth of right body side arm/leg images with left + if (this.lastFlipDirection != direction) { + + this.lastFlipDirection = direction; + + Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes, + this.layerId, + this.limbMeshes["lowerRightLeg"], + this.limbMeshes["lowerLeftLeg"] + ); + Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes, + this.layerId, + this.limbMeshes["upperRightLeg"], + this.limbMeshes["upperLeftLeg"] + ); + Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes, + this.layerId, + this.limbMeshes["lowerRightArm"], + this.limbMeshes["lowerLeftArm"] + ); + Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes, + this.layerId, + this.limbMeshes["upperRightArm"], + this.limbMeshes["upperLeftArm"] + ); + } }; return RubeDoll; diff --git a/app/Game/Client/View/LayerManager.js b/app/Game/Client/View/LayerManager.js index 3ad6dea..7adec2f 100644 --- a/app/Game/Client/View/LayerManager.js +++ b/app/Game/Client/View/LayerManager.js @@ -20,7 +20,8 @@ function (Nc, Exception, Layer) { Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this), Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this), Nc.on(Nc.ns.client.view.mesh.addFilter, this.addFilter, this), - Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this) + Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this), + Nc.on(Nc.ns.client.view.mesh.swapMeshIndexes, this.swapMeshIndexes, this) ]; } @@ -157,6 +158,11 @@ function (Nc, Exception, Layer) { this.delegate.apply(this, arguments); }; + LayerManager.prototype.swapMeshIndexes = function() { + Array.prototype.splice.call(arguments, 0, 0, 'swapMeshIndexes') + this.delegate.apply(this, arguments); + }; + LayerManager.prototype.destroy = function() { for (var i = 0; i < this.ncTokens.length; i++) { Nc.off(this.ncTokens[i]); diff --git a/app/Game/Client/View/Pixi/Layer.js b/app/Game/Client/View/Pixi/Layer.js index acd0f98..58a0fd8 100644 --- a/app/Game/Client/View/Pixi/Layer.js +++ b/app/Game/Client/View/Pixi/Layer.js @@ -95,6 +95,14 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter, Nc) { this.container.removeChild(mesh); }; + Layer.prototype.swapMeshIndexes = function(meshA, meshB) { + var indexA = this.container.getChildIndex(meshA); + var indexB = this.container.getChildIndex(meshB); + + this.container.setChildIndex(meshA, indexB); + this.container.setChildIndex(meshB, indexA); + }; + Layer.prototype.createMesh = function (texturePath, callback, options) { var texture = (options && options.fromFrame) diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 8090fb8..7dd7780 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -40,7 +40,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Asser this.holdingJoint = null; this.holdingItem = null; - this.ragDoll = {head: null, body: null}; + this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it? this.createFixtures(); this.body.SetActive(false); diff --git a/app/Game/Core/GameObjects/Items/RubeDoll.js b/app/Game/Core/GameObjects/Items/RubeDoll.js index ea5b6c0..eeca209 100644 --- a/app/Game/Core/GameObjects/Items/RubeDoll.js +++ b/app/Game/Core/GameObjects/Items/RubeDoll.js @@ -18,10 +18,27 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) { this.rubeLoader = null; this.body = null; this.limbs = {}; + this.joints = null; + this.limits = []; var chest = null; var world = physicsEngine.getWorld(); this.rubeLoader = new RubeLoader(RubeDollJson, world); + + this.loadRubeDollFromScene(options); + + Parent.call(this, physicsEngine, uid, options); + world.DestroyBody(this.body); + this.body = this.limbs.chest; + + this.body.SetUserData(this); + + this.flip(options.direction); + } + + RubeDoll.prototype = Object.create(Parent.prototype); + + RubeDoll.prototype.loadRubeDollFromScene = function(options) { var scene = this.rubeLoader.getScene(); for (var i in scene.bodies) { @@ -35,19 +52,17 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) { this.limbs[body.name] = body; } - Parent.call(this, physicsEngine, uid, options); - world.DestroyBody(this.body); - this.body = this.limbs.chest; + this.joints = scene.joints; - var def = this.body.GetDefinition(); - def.userData = this; - this.body.SetUserData(this); - } - - RubeDoll.prototype = Object.create(Parent.prototype); + for (var i in this.joints) { + this.limits[i] = { + lower: this.joints[i].GetLowerLimit(), + upper: this.joints[i].GetUpperLimit(), + }; + } + }; RubeDoll.prototype.getFixtureDef = function() { - var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape(); return fixtureDef; @@ -55,7 +70,28 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) { RubeDoll.prototype.flip = function(direction) { Parent.prototype.flip.call(this, direction); - // Extend + + for (var i in this.joints) { + var joint = this.joints[i]; + var limits = this.limits[i]; + + if (joint instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) { + + if (direction > 0) { + joint.SetLimits(limits.lower, limits.upper); + continue; + } + + var a1 = limits.lower * -1; + var a2 = limits.upper * -1; + + if (a2 > a1) { + joint.SetLimits(a1, a2); + } else { + joint.SetLimits(a2, a1); + } + } + } }; RubeDoll.prototype.reposition = function(handPosition, direction) { diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index 67b492b..d40a748 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -129,22 +129,23 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll image: "chest.png", name: "RagDoll", rotation: 0, - type: "ragdoll", + type: "rubedoll", weight: 3, width: 5, height: 12, - primaryColor: primaryColor + primaryColor: primaryColor, + direction: this.doll.lookDirection }; - var ragDoll = new RubeDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options); - ragDoll.setVelocities(this.doll.getVelocities()); + var rubeDoll = new RubeDoll(this.physicsEngine, "rubeDoll-" + this.id + "-" + ragDollId, options); + rubeDoll.setVelocities(this.doll.getVelocities()); this.spawned = false; this.doll.destroy(); this.doll = null; - this.ragDoll = ragDoll; + this.ragDoll = rubeDoll; }; Player.prototype.update = function () { diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index 33f8eb7..ec4beb3 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -41,7 +41,8 @@ function (Exception) { remove: null, update: null, addFilter: null, - removeFilter: null + removeFilter: null, + swapMeshIndexes: null }, animatedMesh: { create: null diff --git a/app/Lib/Vendor/RubeLoader.js b/app/Lib/Vendor/RubeLoader.js index 2b6d5a1..b1f3b83 100644 --- a/app/Lib/Vendor/RubeLoader.js +++ b/app/Lib/Vendor/RubeLoader.js @@ -426,7 +426,7 @@ function (Box2D) { var scene = { bodies: loadedBodies, - // joints: loadedJoints + joints: loadedJoints }; return scene; diff --git a/static/items/rube/ragdoll.rube b/static/items/rube/ragdoll.rube index b7f646a..5a3b727 100644 --- a/static/items/rube/ragdoll.rube +++ b/static/items/rube/ragdoll.rube @@ -482,18 +482,18 @@ ], "vertices" : { - "x" : [ -0.002679032273590565 ], - "y" : [ 0.004700660705566406 ] + "x" : [ -0.01561669446527958 ], + "y" : [ 0.004700659774243832 ] } } ], "id" : 8, "linearVelocity" : 0, - "massData-I" : 0.0009180362685583532, + "massData-I" : 0.0009264730615541339, "massData-center" : { - "x" : -0.002679032273590565, - "y" : 0.004700660705566406 + "x" : -0.01561669446527958, + "y" : 0.004700659774243832 }, "massData-mass" : 0.03564291819930077, "name" : "head", @@ -516,8 +516,8 @@ "density" : 1, "filter-groupIndex" : -55, "friction" : 0.2, - "id" : 13, - "name" : "fixture0", + "id" : 11, + "name" : "fixture2", "shapes" : [ @@ -529,34 +529,30 @@ { "x" : [ - 0.1402979493141174, - 0.1375417709350586, - 0.001378186047077179, - -0.1402979493141174, - -0.1402979493141174, - 0.001192390918731689 + -0.1156365871429443, + 0.1570904254913330, + 0.1570904254913330, + -0.1156365871429443 ], "y" : [ - -0.3207050263881683, - 0.4018019437789917, - 0.4018019437789917, - 0.3136067390441895, - -0.3432337343692780, - -0.3689299821853638 + -0.3584164977073669, + -0.3584164977073669, + 0.4034895300865173, + 0.4034895300865173 ] } } ], "id" : 9, "linearVelocity" : 0, - "massData-I" : 0.01047351956367493, + "massData-I" : 0.01153474207967520, "massData-center" : { - "x" : 0.001456731930375099, - "y" : 0.01425695233047009 + "x" : 0.02072691917419434, + "y" : 0.02253651618957520 }, - "massData-mass" : 0.2038488984107971, + "massData-mass" : 0.2077923566102982, "name" : "chest", "position" : { @@ -701,7 +697,7 @@ "name" : "joint1", "referenceAngle" : 0, "type" : "revolute", - "upperLimit" : 0.01745329238474369 + "upperLimit" : 0 }, { @@ -747,13 +743,13 @@ "enableLimit" : true, "enableMotor" : false, "id" : 5, - "lowerLimit" : -0.6981316804885864, + "lowerLimit" : -0.7853981852531433, "maxMotorTorque" : 1, "motorSpeed" : 0, "name" : "joint6", "referenceAngle" : 0, "type" : "revolute", - "upperLimit" : 1.919862151145935 + "upperLimit" : 1.570796370506287 }, { @@ -773,13 +769,13 @@ "enableLimit" : true, "enableMotor" : false, "id" : 6, - "lowerLimit" : -0.6981316804885864, + "lowerLimit" : -0.7853981852531433, "maxMotorTorque" : 1, "motorSpeed" : 0, "name" : "joint5", "referenceAngle" : 0, "type" : "revolute", - "upperLimit" : 1.919862151145935 + "upperLimit" : 1.570796370506287 }, {