diff --git a/app/Game/Channel/GameObjects/Items/Rube.js b/app/Game/Channel/GameObjects/Items/Rube.js new file mode 100644 index 0000000..f663984 --- /dev/null +++ b/app/Game/Channel/GameObjects/Items/Rube.js @@ -0,0 +1,9 @@ +define([ + "Game/Core/GameObjects/Items/Rube" +], + +function (Parent) { + + return Parent; + +}); \ No newline at end of file diff --git a/app/Game/Client/GameObjects/Items/Rube.js b/app/Game/Client/GameObjects/Items/Rube.js new file mode 100644 index 0000000..e029668 --- /dev/null +++ b/app/Game/Client/GameObjects/Items/Rube.js @@ -0,0 +1,26 @@ +define([ + "Game/Core/GameObjects/Items/Rube" +], + +function (Parent) { + + function Rube(physicsEngine, uid, options) { + Parent.call(this, physicsEngine, uid, options); + } + + Rube.prototype = Object.create(Parent.prototype); + + Rube.prototype.createMesh = function() { + }; + + Rube.prototype.destroy = function() { + }; + + Rube.prototype.render = function() { + } + + Rube.prototype.flip = function(direction) { + }; + + return Rube; +}); \ No newline at end of file diff --git a/app/Game/Config/ItemSettings.js b/app/Game/Config/ItemSettings.js index e2a0897..1bd68e4 100644 --- a/app/Game/Config/ItemSettings.js +++ b/app/Game/Config/ItemSettings.js @@ -350,6 +350,22 @@ define(function() { "grabAngle": "-0.4", }, + + + + + "Rube": + { + "category": "kitchen", + "image": "banana.gif", + +// "type": "rube", + "weight": "1", + "width": "5", + "height": "9", + + "grabAngle": "0.5", + } } return ItemSettings; diff --git a/app/Game/Core/GameObjects/Items/Rube.js b/app/Game/Core/GameObjects/Items/Rube.js new file mode 100644 index 0000000..c5c66c5 --- /dev/null +++ b/app/Game/Core/GameObjects/Items/Rube.js @@ -0,0 +1,1408 @@ +define([ + "Game/" + GLOBALS.context + "/GameObjects/Item", + "Lib/Vendor/RubeLoader", + "Lib/Vendor/Box2D", + "Game/Config/Settings" +], + +function (Parent, RubeLoader, Box2D, Settings ) { + + // Fixme - make this loadable + var __ragdollJson; + + function Rube(physicsEngine, uid, options) { + + this.rubeLoader = null; + this.body = null; + + Parent.call(this, physicsEngine, uid, options); + var world = physicsEngine.getWorld(); + world.DestroyBody(this.body); + + var json = __ragdollJson; + + this.rubeLoader = new RubeLoader(json, world); + var scene = this.rubeLoader.getScene(); + + for (var i in scene.bodies) { + var body = scene.bodies[i]; + var position = body.GetPosition().Copy(); + position.Add(new Box2D.Common.Math.b2Vec2( + options.x / Settings.RATIO, + options.y / Settings.RATIO + )); + body.SetPosition(position); + + if(body.name == "chest"){ + this.body = body; + } + } + + var def = this.body.GetDefinition(); + def.userData = this; + this.body.SetUserData(this); + } + + Rube.prototype = Object.create(Parent.prototype); + + Rube.prototype.flip = function(direction) { + Parent.prototype.flip.call(this, direction); + // Extend + }; + + __ragdollJson = + +{ + "allowSleep" : true, + "autoClearForces" : true, + "body" : + [ + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.05748672783374786, + 0.05748672783374786, + -0.05748683214187622, + -0.05748683214187622 + ], + "y" : + [ + -0.2322469353675842, + 0.2322462797164917, + 0.2322462797164917, + -0.2322469353675842 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.001019014045596123, + "massData-center" : + { + "x" : -5.215406062575312e-08, + "y" : -3.278255462646484e-07 + }, + "massData-mass" : 0.05340443924069405, + "name" : "upperArmLeft", + "position" : + { + "x" : -0.1699507087469101, + "y" : 1.113796472549438 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture0", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.1718577891588211, + 0.1684816330671310, + 0.001688212156295776, + -0.1718577295541763, + -0.1718577295541763, + 0.001460619270801544 + ], + "y" : + [ + -0.3928470611572266, + 0.4921868443489075, + 0.4921868443489075, + 0.3841522336006165, + -0.4204435348510742, + -0.4519201517105103 + ] + } + } + }, + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture2", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.1679489463567734, + 0.1679489463567734, + -0.004204027354717255, + -0.004204027354717255 + ], + "y" : + [ + 0.4449140429496765, + 0.6170670390129089, + 0.6170670390129089, + 0.4449140429496765 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.03228222951292992, + "massData-center" : + { + "x" : 0.008858840912580490, + "y" : 0.06282533705234528 + }, + "massData-mass" : 0.3355117142200470, + "name" : "chest", + "position" : + { + "x" : -0.05338868126273155, + "y" : 0.9620395302772522 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "circle" : + { + "center" : + { + "x" : -0.007499951869249344, + "y" : 0.003749847412109375 + }, + "radius" : 0.2746430933475494 + }, + "density" : 0.2204959988594055, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture1" + }, + + { + "circle" : + { + "center" : + { + "x" : -0.03327952325344086, + "y" : -0.1384725570678711 + }, + "radius" : 0.2485582530498505 + }, + "density" : 0.2204959988594055, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture1" + } + ], + "linearVelocity" : 0, + "massData-I" : 0.004164268728345633, + "massData-center" : + { + "x" : -0.01910765282809734, + "y" : -0.06028826907277107 + }, + "massData-mass" : 0.09504657238721848, + "name" : "head", + "position" : + { + "x" : 0.04257059469819069, + "y" : 1.812389135360718 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.05748683214187622, + 0.05748683214187622, + -0.05748690664768219, + -0.05748690664768219 + ], + "y" : + [ + -0.1419981122016907, + 0.1419981718063354, + 0.1419981718063354, + -0.1419981122016907 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.0002554289239924401, + "massData-center" : + { + "x" : -3.725290298461914e-08, + "y" : 2.980232238769531e-08 + }, + "massData-mass" : 0.03265211358666420, + "name" : "lowerArmRight", + "position" : + { + "x" : 0.1177217364311218, + "y" : 0.8479318022727966 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.1415265351533890, + 0.1415265351533890, + -0.08457186818122864, + -0.08457186818122864 + ], + "y" : + [ + -0.1143886670470238, + -0.05680520832538605, + -0.05680520832538605, + -0.1143886670470238 + ] + } + } + }, + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.08623030036687851, + 0.08623030036687851, + -0.08623020350933075, + -0.08623020350933075 + ], + "y" : + [ + -0.1138511821627617, + 0.1565139442682266, + 0.1565139442682266, + -0.1138511821627617 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.0005858240183442831, + "massData-center" : + { + "x" : 0.006215983536094427, + "y" : -0.002008607611060143 + }, + "massData-mass" : 0.05964682996273041, + "name" : "lowerLegLeft", + "position" : + { + "x" : -0.08319067955017090, + "y" : 0.1298431605100632 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.05748684704303741, + 0.05748684704303741, + -0.05748672783374786, + -0.05748672783374786 + ], + "y" : + [ + -0.1419981122016907, + 0.1419981718063354, + 0.1419981718063354, + -0.1419981122016907 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.0002554284874349833, + "massData-center" : + { + "x" : 5.960464477539062e-08, + "y" : 2.980232238769531e-08 + }, + "massData-mass" : 0.03265206888318062, + "name" : "lowerArmLeft", + "position" : + { + "x" : -0.1699528992176056, + "y" : 0.8479318022727966 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.05748683214187622, + 0.05748683214187622, + -0.05748690664768219, + -0.05748690664768219 + ], + "y" : + [ + -0.2322469353675842, + 0.2322462797164917, + 0.2322462797164917, + -0.2322469353675842 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.001019015791825950, + "massData-center" : + { + "x" : -3.725290298461914e-08, + "y" : -3.278255462646484e-07 + }, + "massData-mass" : 0.05340452119708061, + "name" : "upperArmRight", + "position" : + { + "x" : 0.1177217364311218, + "y" : 1.113796472549438 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.08623021841049194, + 0.08623021841049194, + -0.08623008430004120, + -0.08623008430004120 + ], + "y" : + [ + -0.2315792292356491, + 0.2315795421600342, + 0.2315795421600342, + -0.2315792292356491 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.001625877106562257, + "massData-center" : + { + "x" : 6.705522537231445e-08, + "y" : 1.564621925354004e-07 + }, + "massData-mass" : 0.07987650483846664, + "name" : "upperLegRight", + "position" : + { + "x" : 0.03142313286662102, + "y" : 0.4171121716499329 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.08623032271862030, + 0.08623032271862030, + -0.08623017370700836, + -0.08623017370700836 + ], + "y" : + [ + -0.2315792292356491, + 0.2315795421600342, + 0.2315795421600342, + -0.2315792292356491 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.001625879434868693, + "massData-center" : + { + "x" : 7.450580596923828e-08, + "y" : 1.564621925354004e-07 + }, + "massData-mass" : 0.07987659424543381, + "name" : "upperLegLeft", + "position" : + { + "x" : -0.08319067955017090, + "y" : 0.4171121716499329 + }, + "type" : 2 + }, + + { + "angle" : 0, + "angularVelocity" : 0, + "awake" : true, + "fixture" : + [ + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.08623021841049194, + 0.08623021841049194, + -0.08623008430004120, + -0.08623008430004120 + ], + "y" : + [ + -0.1138515025377274, + 0.1563164740800858, + 0.1563164740800858, + -0.1138515025377274 + ] + } + } + }, + + { + "density" : 1, + "filter-groupIndex" : -55, + "friction" : 0.2, + "name" : "fixture3", + "polygon" : + { + "vertices" : + { + "x" : + [ + 0.1415264606475830, + 0.1415264606475830, + -0.08457189798355103, + -0.08457189798355103 + ], + "y" : + [ + -0.1143886670470238, + -0.05680520832538605, + -0.05680520832538605, + -0.1143886670470238 + ] + } + } + } + ], + "linearVelocity" : 0, + "massData-I" : 0.0005849063745699823, + "massData-center" : + { + "x" : 0.006219535600394011, + "y" : -0.002099231118336320 + }, + "massData-mass" : 0.05961277708411217, + "name" : "lowerLegRight", + "position" : + { + "x" : 0.03142313286662102, + "y" : 0.1298431605100632 + }, + "type" : 2 + } + ], + "collisionbitplanes" : + { + "names" : + [ + "bitplane1", + "bitplane2", + "bitplane3", + "bitplane4", + "bitplane5", + "bitplane6", + "bitplane7", + "bitplane8", + "bitplane9", + "bitplane10", + "bitplane11", + "bitplane12", + "bitplane13", + "bitplane14", + "bitplane15", + "bitplane16", + "bitplane17", + "bitplane18", + "bitplane19", + "bitplane20", + "bitplane21", + "bitplane22", + "bitplane23", + "bitplane24", + "bitplane25", + "bitplane26", + "bitplane27", + "bitplane28", + "bitplane29", + "bitplane30", + "bitplane31", + "bitplane32" + ] + }, + "continuousPhysics" : true, + "gravity" : + { + "x" : 0, + "y" : -10 + }, + "image" : + [ + + { + "aspectScale" : 1, + "body" : 9, + "center" : + { + "x" : 0.02911517955362797, + "y" : -0.0009155124425888062 + }, + "corners" : + { + "x" : + [ + -0.08536797016859055, + 0.1435983330011368, + 0.1435983330011368, + -0.08536797016859055 + ], + "y" : + [ + -0.1153986603021622, + -0.1153986603021622, + 0.1135676354169846, + 0.1135676354169846 + ] + }, + "file" : "../../img/Characters/Chuck/lowerLeftLeg.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.08536797016859055, + -0.1153986603021622, + 0.1435983330011368, + -0.1153986603021622, + 0.1435983330011368, + 0.1135676354169846, + -0.08536797016859055, + 0.1135676354169846 + ], + "name" : "image5", + "opacity" : 1, + "scale" : 0.2289662957191467 + }, + + { + "aspectScale" : 1, + "body" : 7, + "center" : + { + "x" : -0.02732392773032188, + "y" : 0.02671334147453308 + }, + "corners" : + { + "x" : + [ + -0.1425068378448486, + 0.08785898983478546, + 0.08785898983478546, + -0.1425068378448486 + ], + "y" : + [ + -0.2324482202529907, + -0.2324482202529907, + 0.2858749032020569, + 0.2858749032020569 + ] + }, + "file" : "../../img/Characters/Chuck/upperRightLeg.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.1425068378448486, + -0.2324482202529907, + 0.08785898983478546, + -0.2324482202529907, + 0.08785898983478546, + 0.2858749032020569, + -0.1425068378448486, + 0.2858749032020569 + ], + "name" : "image6", + "opacity" : 1, + "scale" : 0.5183231234550476 + }, + + { + "aspectScale" : 1, + "body" : 6, + "center" : + { + "x" : 0.0003027096390724182, + "y" : 0.0006600618362426758 + }, + "corners" : + { + "x" : + [ + -0.05836960300803185, + 0.05897502228617668, + 0.05897502228617668, + -0.05836960300803185 + ], + "y" : + [ + -0.2340291887521744, + -0.2340291887521744, + 0.2353493124246597, + 0.2353493124246597 + ] + }, + "file" : "../../img/Characters/Chuck/upperLeftArm.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.05836960300803185, + -0.2340291887521744, + 0.05897502228617668, + -0.2340291887521744, + 0.05897502228617668, + 0.2353493124246597, + -0.05836960300803185, + 0.2353493124246597 + ], + "name" : "image4", + "opacity" : 1, + "renderOrder" : 1, + "scale" : 0.4693785011768341 + }, + + { + "aspectScale" : 1, + "body" : 3, + "center" : + { + "x" : 0.0007003694772720337, + "y" : 0.001779437065124512 + }, + "corners" : + { + "x" : + [ + -0.05596264451742172, + 0.05736338347196579, + 0.05736338347196579, + -0.05596264451742172 + ], + "y" : + [ + -0.1398780941963196, + -0.1398780941963196, + 0.1434369683265686, + 0.1434369683265686 + ] + }, + "file" : "../../img/Characters/Chuck/lowerLeftArm.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.05596264451742172, + -0.1398780941963196, + 0.05736338347196579, + -0.1398780941963196, + 0.05736338347196579, + 0.1434369683265686, + -0.05596264451742172, + 0.1434369683265686 + ], + "name" : "image3", + "opacity" : 1, + "renderOrder" : 1, + "scale" : 0.2833150625228882 + }, + + { + "aspectScale" : 1, + "body" : 1, + "center" : + { + "x" : -0.0008481591939926147, + "y" : -0.001265347003936768 + }, + "corners" : + { + "x" : + [ + -0.1698881536722183, + 0.1681918352842331, + 0.1681918352842331, + -0.1698881536722183 + ], + "y" : + [ + -0.480212002992630, + -0.480212002992630, + 0.4776813089847565, + 0.4776813089847565 + ] + }, + "file" : "../../img/Characters/Chuck/chest.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.1698881536722183, + -0.480212002992630, + 0.1681918352842331, + -0.480212002992630, + 0.1681918352842331, + 0.4776813089847565, + -0.1698881536722183, + 0.4776813089847565 + ], + "name" : "image2", + "opacity" : 1, + "renderOrder" : 5, + "scale" : 0.9578933119773865 + }, + + { + "aspectScale" : 1, + "body" : 8, + "center" : + { + "x" : 0.003173574805259705, + "y" : -0.001172244548797607 + }, + "corners" : + { + "x" : + [ + -0.1414211541414261, + 0.1477683037519455, + 0.1477683037519455, + -0.1414211541414261 + ], + "y" : + [ + -0.2325238138437271, + -0.2325238138437271, + 0.2301793247461319, + 0.2301793247461319 + ] + }, + "file" : "../../img/Characters/Chuck/upperLeftLeg.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.1414211541414261, + -0.2325238138437271, + 0.1477683037519455, + -0.2325238138437271, + 0.1477683037519455, + 0.2301793247461319, + -0.1414211541414261, + 0.2301793247461319 + ], + "name" : "image6", + "opacity" : 1, + "renderOrder" : 6, + "scale" : 0.4627031385898590 + }, + + { + "aspectScale" : 1, + "body" : 4, + "center" : + { + "x" : 0.02851789817214012, + "y" : -0.0009155124425888062 + }, + "corners" : + { + "x" : + [ + -0.08596524596214294, + 0.1430010497570038, + 0.1430010497570038, + -0.08596524596214294 + ], + "y" : + [ + -0.1153986603021622, + -0.1153986603021622, + 0.1135676354169846, + 0.1135676354169846 + ] + }, + "file" : "../../img/Characters/Chuck/lowerLeftLeg.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.08596524596214294, + -0.1153986603021622, + 0.1430010497570038, + -0.1153986603021622, + 0.1430010497570038, + 0.1135676354169846, + -0.08596524596214294, + 0.1135676354169846 + ], + "name" : "image5", + "opacity" : 1, + "renderOrder" : 6, + "scale" : 0.2289662957191467 + }, + + { + "aspectScale" : 1, + "body" : 2, + "center" : + { + "x" : 0.01975236460566521, + "y" : -0.07194232940673828 + }, + "corners" : + { + "x" : + [ + -0.2679373621940613, + 0.3074420690536499, + 0.3074420690536499, + -0.2679373621940613 + ], + "y" : + [ + -0.4171699881553650, + -0.4171699881553650, + 0.2732853293418884, + 0.2732853293418884 + ] + }, + "file" : "../../img/Characters/Chuck/head.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.2679373621940613, + -0.4171699881553650, + 0.3074420690536499, + -0.4171699881553650, + 0.3074420690536499, + 0.2732853293418884, + -0.2679373621940613, + 0.2732853293418884 + ], + "name" : "image1", + "opacity" : 1, + "renderOrder" : 6, + "scale" : 0.6904553174972534 + }, + + { + "aspectScale" : 1, + "body" : 0, + "center" : + { + "x" : 0.002138927578926086, + "y" : 0.0006600618362426758 + }, + "corners" : + { + "x" : + [ + -0.05653338506817818, + 0.06081124022603035, + 0.06081124022603035, + -0.05653338506817818 + ], + "y" : + [ + -0.2340291887521744, + -0.2340291887521744, + 0.2353493124246597, + 0.2353493124246597 + ] + }, + "file" : "../../img/Characters/Chuck/upperLeftArm.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.05653338506817818, + -0.2340291887521744, + 0.06081124022603035, + -0.2340291887521744, + 0.06081124022603035, + 0.2353493124246597, + -0.05653338506817818, + 0.2353493124246597 + ], + "name" : "image4", + "opacity" : 1, + "renderOrder" : 8, + "scale" : 0.4693785011768341 + }, + + { + "aspectScale" : 1, + "body" : 5, + "center" : + { + "x" : 0.002538725733757019, + "y" : 0.001779437065124512 + }, + "corners" : + { + "x" : + [ + -0.05412428826093674, + 0.05920173972845078, + 0.05920173972845078, + -0.05412428826093674 + ], + "y" : + [ + -0.1398780941963196, + -0.1398780941963196, + 0.1434369683265686, + 0.1434369683265686 + ] + }, + "file" : "../../img/Characters/Chuck/lowerLeftArm.png", + "filter" : 0, + "glDrawElements" : [ 0, 1, 2, 2, 3, 0 ], + "glTexCoordPointer" : [ 0.0, 0.0, 1, 0.0, 1, 1, 0.0, 1 ], + "glVertexPointer" : + [ + -0.05412428826093674, + -0.1398780941963196, + 0.05920173972845078, + -0.1398780941963196, + 0.05920173972845078, + 0.1434369683265686, + -0.05412428826093674, + 0.1434369683265686 + ], + "name" : "image3", + "opacity" : 1, + "renderOrder" : 8, + "scale" : 0.2833150625228882 + } + ], + "joint" : + [ + + { + "anchorA" : + { + "x" : 0.001047849655151367, + "y" : -0.1790249347686768 + }, + "anchorB" : + { + "x" : 0.001048207283020020, + "y" : 0.08683943748474121 + }, + "bodyA" : 0, + "bodyB" : 5, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : 0, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint4", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 1.919862151145935 + }, + + { + "anchorA" : + { + "x" : -0.1165831685066223, + "y" : 0.3330366015434265 + }, + "anchorB" : + { + "x" : -2.135336399078369e-05, + "y" : 0.1812803745269775 + }, + "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.07454992830753326, + "y" : 0.5068108439445496 + }, + "anchorB" : + { + "x" : -0.02141102217137814, + "y" : -0.3435407876968384 + }, + "bodyA" : 1, + "bodyB" : 2, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -1.221730470657349, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint0", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 0.6981316804885864 + }, + + { + "anchorA" : + { + "x" : 0.1367489844560623, + "y" : -0.3606387376785278 + }, + "anchorB" : + { + "x" : 0.05056380107998848, + "y" : 0.1842886805534363 + }, + "bodyA" : 1, + "bodyB" : 7, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -0.6981316804885864, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint5", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 1.919862151145935 + }, + + { + "anchorA" : + { + "x" : -0.08329562842845917, + "y" : -0.3541148304939270 + }, + "anchorB" : + { + "x" : -0.05503869056701660, + "y" : 0.1909851431846619 + }, + "bodyA" : 1, + "bodyB" : 8, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -0.6981316804885864, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint6", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 1.919862151145935 + }, + + { + "anchorA" : + { + "x" : 0.1710196435451508, + "y" : 0.3308989405632019 + }, + "anchorB" : + { + "x" : -9.131431579589844e-05, + "y" : 0.1791421175003052 + }, + "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" : + { + "x" : 0.0004334598779678345, + "y" : 0.08706557750701904 + }, + "anchorB" : + { + "x" : 0.0004332214593887329, + "y" : -0.1787990331649780 + }, + "bodyA" : 3, + "bodyB" : 6, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : 0, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint1", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 1.919862151145935 + }, + + { + "anchorA" : + { + "x" : 0.002425249665975571, + "y" : -0.1845821887254715 + }, + "anchorB" : + { + "x" : 0.002425376325845718, + "y" : 0.1026860624551773 + }, + "bodyA" : 7, + "bodyB" : 9, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -2.268928050994873, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint8", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 0 + }, + + { + "anchorA" : + { + "x" : -0.0009558200836181641, + "y" : -0.1818936169147491 + }, + "anchorB" : + { + "x" : -0.0009555891156196594, + "y" : 0.1055182516574860 + }, + "bodyA" : 8, + "bodyB" : 4, + "enableLimit" : true, + "enableMotor" : false, + "jointSpeed" : 0, + "lowerLimit" : -2.268928050994873, + "maxMotorTorque" : 1, + "motorSpeed" : 0, + "name" : "joint7", + "refAngle" : 0, + "type" : "revolute", + "upperLimit" : 0 + } + ], + "positionIterations" : 3, + "stepsPerSecond" : 60.0, + "subStepping" : false, + "velocityIterations" : 8, + "warmStarting" : true +} + + + + + + + return Rube; + +}); \ No newline at end of file diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index 2709343..e20b6ab 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -6,9 +6,10 @@ define([ "Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", - "Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll" + "Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll", + "Game/" + GLOBALS.context + "/GameObjects/Items/Rube" -], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll) { +], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) { function Level (uid, engine) { this.uid = uid; @@ -30,6 +31,27 @@ define([ }); } + Level.prototype.createItem = function(uid, options) { + switch(options.type) { + case 'skateboard': + return new Skateboard(this.engine, uid, options); + case 'ragdoll': + return new RagDoll(this.engine, uid, options); + case 'rube': + return new Rube(this.engine, uid, options); + default: + return new Item(this.engine, uid, options); + } + }; + + Level.prototype.getRandomSpawnPoint = function() { + throw new Error("Level not loaded."); + return { + x: 150 + Math.random() * 300, + y: -500 + }; + }; + Level.prototype.destroy = function () { /* for (var key in this.gameObjects) { @@ -41,6 +63,7 @@ define([ this.isLoaded = false; } +/* Extended by TiledLevel Level.prototype.createTiles = function () { if (!this.levelData || !this.levelData.tiles || this.levelData.tiles.length < 1) { @@ -58,7 +81,9 @@ define([ //); } } +*/ +/* Extended by TiledLevel Level.prototype.createItems = function() { if (!this.levelData || !this.levelData.items) { return; @@ -72,25 +97,7 @@ define([ //this.gameObjects.animated.push(item); }; }; - - Level.prototype.createItem = function(uid, options) { - switch(options.type) { - case 'skateboard': - return new Skateboard(this.engine, uid, options); - case 'ragdoll': - return new RagDoll(this.engine, uid, options); - default: - return new Item(this.engine, uid, options); - } - }; - - Level.prototype.getRandomSpawnPoint = function() { - throw new Error("Level not loaded."); - return { - x: 150 + Math.random() * 300, - y: -500 - }; - }; +*/ return Level; }) \ No newline at end of file diff --git a/app/Lib/Vendor/Rube/loadrube.js b/app/Lib/Vendor/Rube/loadrube.js new file mode 100644 index 0000000..8ada785 --- /dev/null +++ b/app/Lib/Vendor/Rube/loadrube.js @@ -0,0 +1,416 @@ + +Object.prototype.hasOwnProperty = function(property) { + return typeof(this[property]) !== 'undefined' +}; + +function loadBodyFromRUBE(bodyJso, world) { + //console.log(bodyJso); + + if ( ! bodyJso.hasOwnProperty('type') ) { + console.log("Body does not have a 'type' property"); + return null; + } + + var bd = new b2BodyDef(); + if ( bodyJso.type == 2 ) + bd.type = b2_dynamicBody; + else if ( bodyJso.type == 1 ) + bd.type = b2_kinematicBody; + if ( bodyJso.hasOwnProperty('angle') ) + bd.angle = bodyJso.angle; + if ( bodyJso.hasOwnProperty('angularVelocity') ) + bd.angularVelocity = bodyJso.angularVelocity; + if ( bodyJso.hasOwnProperty('active') ) + bd.awake = bodyJso.active; + if ( bodyJso.hasOwnProperty('fixedRotation') ) + bd.fixedRotation = bodyJso.fixedRotation; + if ( bodyJso.hasOwnProperty('linearVelocity') && bodyJso.linearVelocity instanceof Object ) + bd.linearVelocity.SetV( bodyJso.linearVelocity ); + if ( bodyJso.hasOwnProperty('position') && bodyJso.position instanceof Object ) + bd.position.SetV( bodyJso.position ); + if ( bodyJso.hasOwnProperty('awake') ) + bd.awake = bodyJso.awake; + else + bd.awake = false; + var body = world.CreateBody(bd); + if ( bodyJso.hasOwnProperty('fixture') ) { + for (k = 0; k < bodyJso['fixture'].length; k++) { + var fixtureJso = bodyJso['fixture'][k]; + loadFixtureFromRUBE(body, fixtureJso); + } + } + if ( bodyJso.hasOwnProperty('name') ) + body.name = bodyJso.name; + if ( bodyJso.hasOwnProperty('customProperties') ) + body.customProperties = bodyJso.customProperties; + return body; +} + +function loadFixtureFromRUBE(body, fixtureJso) { + //console.log(fixtureJso); + var fd = new b2FixtureDef(); + if (fixtureJso.hasOwnProperty('friction')) + fd.friction = fixtureJso.friction; + if (fixtureJso.hasOwnProperty('density')) + fd.density = fixtureJso.density; + if (fixtureJso.hasOwnProperty('restitution')) + fd.restitution = fixtureJso.restitution; + if (fixtureJso.hasOwnProperty('sensor')) + fd.isSensor = fixtureJso.sensor; + if ( fixtureJso.hasOwnProperty('filter-categoryBits') ) + fd.filter.categoryBits = fixtureJso['filter-categoryBits']; + if ( fixtureJso.hasOwnProperty('filter-maskBits') ) + fd.filter.maskBits = fixtureJso['filter-maskBits']; + if ( fixtureJso.hasOwnProperty('filter-groupIndex') ) + fd.filter.groupIndex = fixtureJso['filter-groupIndex']; + if (fixtureJso.hasOwnProperty('circle')) { + fd.shape = new b2CircleShape(); + fd.shape.m_radius = fixtureJso.circle.radius; + if ( fixtureJso.circle.center ) + fd.shape.m_p.SetV(fixtureJso.circle.center); + var fixture = body.CreateFixture(fd); + if ( fixtureJso.name ) + fixture.name = fixtureJso.name; + } + else if (fixtureJso.hasOwnProperty('polygon')) { + fd.shape = new b2PolygonShape(); + var verts = []; + for (v = 0; v < fixtureJso.polygon.vertices.x.length; v++) + verts.push( new b2Vec2( fixtureJso.polygon.vertices.x[v], fixtureJso.polygon.vertices.y[v] ) ); + fd.shape.SetAsArray(verts, verts.length); + var fixture = body.CreateFixture(fd); + if ( fixture && fixtureJso.name ) + fixture.name = fixtureJso.name; + } + else if (fixtureJso.hasOwnProperty('chain')) { + fd.shape = new b2PolygonShape(); + var lastVertex = new b2Vec2(); + for (v = 0; v < fixtureJso.chain.vertices.x.length; v++) { + var thisVertex = new b2Vec2( fixtureJso.chain.vertices.x[v], fixtureJso.chain.vertices.y[v] ); + if ( v > 0 ) { + fd.shape.SetAsEdge( lastVertex, thisVertex ); + var fixture = body.CreateFixture(fd); + if ( fixtureJso.name ) + fixture.name = fixtureJso.name; + } + lastVertex = thisVertex; + } + } + else { + console.log("Could not find shape type for fixture"); + } +} + +function getVectorValue(val) { + if ( val instanceof Object ) + return val; + else + return { x:0, y:0 }; +} + +function loadJointCommonProperties(jd, jointJso, loadedBodies) { + jd.bodyA = loadedBodies[jointJso.bodyA]; + jd.bodyB = loadedBodies[jointJso.bodyB]; + jd.localAnchorA.SetV( getVectorValue(jointJso.anchorA) ); + jd.localAnchorB.SetV( getVectorValue(jointJso.anchorB) ); + if ( jointJso.collideConnected ) + jd.collideConnected = jointJso.collideConnected; +} + +function loadJointFromRUBE(jointJso, world, loadedBodies) +{ + if ( ! jointJso.hasOwnProperty('type') ) { + console.log("Joint does not have a 'type' property"); + return null; + } + if ( jointJso.bodyA >= loadedBodies.length ) { + console.log("Index for bodyA is invalid: " + jointJso.bodyA ); + return null; + } + if ( jointJso.bodyB >= loadedBodies.length ) { + console.log("Index for bodyB is invalid: " + jointJso.bodyB ); + return null; + } + + var joint = null; + if ( jointJso.type == "revolute" ) { + var jd = new b2RevoluteJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('refAngle') ) + jd.referenceAngle = jointJso.refAngle; + if ( jointJso.hasOwnProperty('lowerLimit') ) + jd.lowerAngle = jointJso.lowerLimit; + if ( jointJso.hasOwnProperty('upperLimit') ) + jd.upperAngle = jointJso.upperLimit; + if ( jointJso.hasOwnProperty('maxMotorTorque') ) + jd.maxMotorTorque = jointJso.maxMotorTorque; + if ( jointJso.hasOwnProperty('motorSpeed') ) + jd.motorSpeed = jointJso.motorSpeed; + if ( jointJso.hasOwnProperty('enableLimit') ) + jd.enableLimit = jointJso.enableLimit; + if ( jointJso.hasOwnProperty('enableMotor') ) + jd.enableMotor = jointJso.enableMotor; + joint = world.CreateJoint(jd); + } + else if ( jointJso.type == "distance" || jointJso.type == "rope" ) { + if ( jointJso.type == "rope" ) + console.log("Replacing unsupported rope joint with distance joint!"); + var jd = new b2DistanceJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('length') ) + jd.length = jointJso.length; + if ( jointJso.hasOwnProperty('dampingRatio') ) + jd.dampingRatio = jointJso.dampingRatio; + if ( jointJso.hasOwnProperty('frequency') ) + jd.frequencyHz = jointJso.frequency; + joint = world.CreateJoint(jd); + } + else if ( jointJso.type == "prismatic" ) { + var jd = new b2PrismaticJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('localAxisA') ) + jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) ); + if ( jointJso.hasOwnProperty('refAngle') ) + jd.referenceAngle = jointJso.refAngle; + if ( jointJso.hasOwnProperty('enableLimit') ) + jd.enableLimit = jointJso.enableLimit; + if ( jointJso.hasOwnProperty('lowerLimit') ) + jd.lowerTranslation = jointJso.lowerLimit; + if ( jointJso.hasOwnProperty('upperLimit') ) + jd.upperTranslation = jointJso.upperLimit; + if ( jointJso.hasOwnProperty('enableMotor') ) + jd.enableMotor = jointJso.enableMotor; + if ( jointJso.hasOwnProperty('maxMotorForce') ) + jd.maxMotorForce = jointJso.maxMotorForce; + if ( jointJso.hasOwnProperty('motorSpeed') ) + jd.motorSpeed = jointJso.motorSpeed; + joint = world.CreateJoint(jd); + } + else if ( jointJso.type == "wheel" ) { + //Make a fake wheel joint using a line joint and a distance joint. + //Return the line joint because it has the linear motor controls. + //Use ApplyTorque on the bodies to spin the wheel... + + var jd = new b2DistanceJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + jd.length = 0.0; + if ( jointJso.hasOwnProperty('springDampingRatio') ) + jd.dampingRatio = jointJso.springDampingRatio; + if ( jointJso.hasOwnProperty('springFrequency') ) + jd.frequencyHz = jointJso.springFrequency; + world.CreateJoint(jd); + + jd = new b2LineJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('localAxisA') ) + jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) ); + + joint = world.CreateJoint(jd); + } + else if ( jointJso.type == "friction" ) { + var jd = new b2FrictionJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('maxForce') ) + jd.maxForce = jointJso.maxForce; + if ( jointJso.hasOwnProperty('maxTorque') ) + jd.maxTorque = jointJso.maxTorque; + joint = world.CreateJoint(jd); + } + else if ( jointJso.type == "weld" ) { + var jd = new b2WeldJointDef(); + loadJointCommonProperties(jd, jointJso, loadedBodies); + if ( jointJso.hasOwnProperty('referenceAngle') ) + jd.referenceAngle = jointJso.referenceAngle; + joint = world.CreateJoint(jd); + } + else { + console.log("Unsupported joint type: " + jointJso.type); + console.log(jointJso); + } + if ( joint && jointJso.name ) + joint.name = jointJso.name; + return joint; +} + +function makeClone(obj) { + var newObj = (obj instanceof Array) ? [] : {}; + for (var i in obj) { + if (obj[i] && typeof obj[i] == "object") + newObj[i] = makeClone(obj[i]); + else + newObj[i] = obj[i]; + } + return newObj; +}; + +function loadImageFromRUBE(imageJso, world, loadedBodies) +{ + var image = makeClone(imageJso); + + if ( image.hasOwnProperty('body') && image.body >= 0 ) + image.body = loadedBodies[image.body];//change index to the actual body + else + image.body = null; + + image.center = new b2Vec2(); + image.center.SetV( getVectorValue(imageJso.center) ); + + return image; +} + + + +//mainly just a convenience for the testbed - uses global 'world' variable +function loadSceneFromRUBE(worldJso) { + return loadSceneIntoWorld(worldJso, world); +} + +//load the scene into an already existing world variable +function loadSceneIntoWorld(worldJso, world) { + var success = true; + + var loadedBodies = []; + if ( worldJso.hasOwnProperty('body') ) { + for (var i = 0; i < worldJso.body.length; i++) { + var bodyJso = worldJso.body[i]; + var body = loadBodyFromRUBE(bodyJso, world); + if ( body ) + loadedBodies.push( body ); + else + success = false; + } + } + + var loadedJoints = []; + if ( worldJso.hasOwnProperty('joint') ) { + for (var i = 0; i < worldJso.joint.length; i++) { + var jointJso = worldJso.joint[i]; + var joint = loadJointFromRUBE(jointJso, world, loadedBodies); + if ( joint ) + loadedJoints.push( joint ); + //else + // success = false; + } + } + + var loadedImages = []; + if ( worldJso.hasOwnProperty('image') ) { + for (var i = 0; i < worldJso.image.length; i++) { + var imageJso = worldJso.image[i]; + var image = loadImageFromRUBE(imageJso, world, loadedBodies); + if ( image ) + loadedImages.push( image ); + else + success = false; + } + world.images = loadedImages; + } + + return success; +} + +//create a world variable and return it if loading succeeds +function loadWorldFromRUBE(worldJso) { + var gravity = new b2Vec2(0,0); + if ( worldJso.hasOwnProperty('gravity') && worldJso.gravity instanceof Object ) + gravity.SetV( worldJso.gravity ); + var world = new b2World( gravity ); + if ( ! loadSceneIntoWorld(worldJso, world) ) + return false; + return world; +} + +function getNamedBodies(world, name) { + var bodies = []; + for (b = world.m_bodyList; b; b = b.m_next) { + if ( b.name == name ) + bodies.push(b); + } + return bodies; +} + +function getNamedFixtures(world, name) { + var fixtures = []; + for (b = world.m_bodyList; b; b = b.m_next) { + for (f = b.m_fixtureList; f; f = f.m_next) { + if ( f.name == name ) + fixtures.push(f); + } + } + return fixtures; +} + +function getNamedJoints(world, name) { + var joints = []; + for (j = world.m_jointList; j; j = j.m_next) { + if ( j.name == name ) + joints.push(j); + } + return joints; +} + +function getNamedImages(world, name) { + var images = []; + for (i = 0; i < world.images.length; i++) { + if ( world.images[i].name == name ) + images.push(world.images[i].name); + } + return images; +} + +//custom properties +function getBodiesByCustomProperty(world, propertyType, propertyName, valueToMatch) { + var bodies = []; + for (b = world.m_bodyList; b; b = b.m_next) { + if ( ! b.hasOwnProperty('customProperties') ) + continue; + for (var i = 0; i < b.customProperties.length; i++) { + if ( ! b.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! b.customProperties[i].hasOwnProperty(propertyType) ) + continue; + if ( b.customProperties[i].name == propertyName && + b.customProperties[i][propertyType] == valueToMatch) + bodies.push(b); + } + } + return bodies; +} + +function hasCustomProperty(item, propertyType, propertyName) { + if ( !item.hasOwnProperty('customProperties') ) + return false; + for (var i = 0; i < item.customProperties.length; i++) { + if ( ! item.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! item.customProperties[i].hasOwnProperty(propertyType) ) + continue; + return true; + } + return false; +} + +function getCustomProperty(item, propertyType, propertyName, defaultValue) { + if ( !item.hasOwnProperty('customProperties') ) + return defaultValue; + for (var i = 0; i < item.customProperties.length; i++) { + if ( ! item.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! item.customProperties[i].hasOwnProperty(propertyType) ) + continue; + if ( item.customProperties[i].name == propertyName ) + return item.customProperties[i][propertyType]; + } + return defaultValue; +} + + + + + + + + + + + diff --git a/app/Lib/Vendor/RubeLoader.js b/app/Lib/Vendor/RubeLoader.js new file mode 100644 index 0000000..49674c3 --- /dev/null +++ b/app/Lib/Vendor/RubeLoader.js @@ -0,0 +1,536 @@ +define([ + "Lib/Vendor/Box2D", +], + +/* +List of what has been done here +- enclose in require.js style class +- added box2d var names +- inversed y coordinates with body positions, polygon coordinates and in getVectorValue for joints + +*/ + +function (Box2D) { + + var b2Color = Box2D.Common.b2Color, + b2internal = Box2D.Common.b2internal, + b2Settings = Box2D.Common.b2Settings, + b2CircleShape = Box2D.Collision.Shapes.b2CircleShape, + b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef, + b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape, + b2MassData = Box2D.Collision.Shapes.b2MassData, + b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape, + b2Shape = Box2D.Collision.Shapes.b2Shape, + b2Mat22 = Box2D.Common.Math.b2Mat22, + b2Mat33 = Box2D.Common.Math.b2Mat33, + b2Math = Box2D.Common.Math.b2Math, + b2Sweep = Box2D.Common.Math.b2Sweep, + b2Transform = Box2D.Common.Math.b2Transform, + b2Vec2 = Box2D.Common.Math.b2Vec2, + b2Vec3 = Box2D.Common.Math.b2Vec3, + b2Body = Box2D.Dynamics.b2Body, + b2BodyDef = Box2D.Dynamics.b2BodyDef, + b2ContactFilter = Box2D.Dynamics.b2ContactFilter, + b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse, + b2ContactListener = Box2D.Dynamics.b2ContactListener, + b2ContactManager = Box2D.Dynamics.b2ContactManager, + b2DebugDraw = Box2D.Dynamics.b2DebugDraw, + b2DestructionListener = Box2D.Dynamics.b2DestructionListener, + b2FilterData = Box2D.Dynamics.b2FilterData, + b2Fixture = Box2D.Dynamics.b2Fixture, + b2FixtureDef = Box2D.Dynamics.b2FixtureDef, + b2Island = Box2D.Dynamics.b2Island, + b2TimeStep = Box2D.Dynamics.b2TimeStep, + b2World = Box2D.Dynamics.b2World, + b2AABB = Box2D.Collision.b2AABB, + b2Bound = Box2D.Collision.b2Bound, + b2BoundValues = Box2D.Collision.b2BoundValues, + b2Collision = Box2D.Collision.b2Collision, + b2ContactID = Box2D.Collision.b2ContactID, + b2ContactPoint = Box2D.Collision.b2ContactPoint, + b2Distance = Box2D.Collision.b2Distance, + b2DistanceInput = Box2D.Collision.b2DistanceInput, + b2DistanceOutput = Box2D.Collision.b2DistanceOutput, + b2DistanceProxy = Box2D.Collision.b2DistanceProxy, + b2DynamicTree = Box2D.Collision.b2DynamicTree, + b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase, + b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode, + b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair, + b2Manifold = Box2D.Collision.b2Manifold, + b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint, + b2Point = Box2D.Collision.b2Point, + b2RayCastInput = Box2D.Collision.b2RayCastInput, + b2RayCastOutput = Box2D.Collision.b2RayCastOutput, + b2Segment = Box2D.Collision.b2Segment, + b2SeparationFunction = Box2D.Collision.b2SeparationFunction, + b2Simplex = Box2D.Collision.b2Simplex, + b2SimplexCache = Box2D.Collision.b2SimplexCache, + b2SimplexVertex = Box2D.Collision.b2SimplexVertex, + b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact, + b2TOIInput = Box2D.Collision.b2TOIInput, + b2WorldManifold = Box2D.Collision.b2WorldManifold, + ClipVertex = Box2D.Collision.ClipVertex, + Features = Box2D.Collision.Features, + IBroadPhase = Box2D.Collision.IBroadPhase; + b2_dynamicBody = Box2D.Dynamics.b2Body.b2_dynamicBody; + b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge, + IBroadPhase = Box2D.Collision.IBroadPhase, + b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact, + b2Contact = Box2D.Dynamics.Contacts.b2Contact, + b2ContactConstraint = Box2D.Dynamics.Contacts.b2ContactConstraint, + b2ContactConstraintPoint = Box2D.Dynamics.Contacts.b2ContactConstraintPoint, + b2ContactEdge = Box2D.Dynamics.Contacts.b2ContactEdge, + b2ContactFactory = Box2D.Dynamics.Contacts.b2ContactFactory, + b2ContactRegister = Box2D.Dynamics.Contacts.b2ContactRegister, + b2ContactResult = Box2D.Dynamics.Contacts.b2ContactResult, + b2ContactSolver = Box2D.Dynamics.Contacts.b2ContactSolver, + b2EdgeAndCircleContact = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact, + b2NullContact = Box2D.Dynamics.Contacts.b2NullContact, + b2PolyAndCircleContact = Box2D.Dynamics.Contacts.b2PolyAndCircleContact, + b2PolyAndEdgeContact = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact, + b2PolygonContact = Box2D.Dynamics.Contacts.b2PolygonContact, + b2PositionSolverManifold = Box2D.Dynamics.Contacts.b2PositionSolverManifold, + b2Controller = Box2D.Dynamics.Controllers.b2Controller, + b2DistanceJoint = Box2D.Dynamics.Joints.b2DistanceJoint, + b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef, + b2FrictionJoint = Box2D.Dynamics.Joints.b2FrictionJoint, + b2FrictionJointDef = Box2D.Dynamics.Joints.b2FrictionJointDef, + b2GearJoint = Box2D.Dynamics.Joints.b2GearJoint, + b2GearJointDef = Box2D.Dynamics.Joints.b2GearJointDef, + b2Jacobian = Box2D.Dynamics.Joints.b2Jacobian, + b2Joint = Box2D.Dynamics.Joints.b2Joint, + b2JointDef = Box2D.Dynamics.Joints.b2JointDef, + b2JointEdge = Box2D.Dynamics.Joints.b2JointEdge, + b2LineJoint = Box2D.Dynamics.Joints.b2LineJoint, + b2LineJointDef = Box2D.Dynamics.Joints.b2LineJointDef, + b2MouseJoint = Box2D.Dynamics.Joints.b2MouseJoint, + b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef, + b2PrismaticJoint = Box2D.Dynamics.Joints.b2PrismaticJoint, + b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef, + b2PulleyJoint = Box2D.Dynamics.Joints.b2PulleyJoint, + b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef, + b2RevoluteJoint = Box2D.Dynamics.Joints.b2RevoluteJoint, + b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef, + b2WeldJoint = Box2D.Dynamics.Joints.b2WeldJoint, + b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDef; + + function RubeLoader(json, world) { + + this.scene = this.loadSceneIntoWorld(json, world); + } + + + Object.prototype.hasOwnProperty = function(property) { + return typeof(this[property]) !== 'undefined' + }; + + RubeLoader.prototype.getScene = function() { + return this.scene; + }; + + RubeLoader.prototype.loadBodyFromRUBE = function (bodyJson, world) { + //console.log(bodyJson); + + if ( ! bodyJson.hasOwnProperty('type') ) { + console.log("Body does not have a 'type' property"); + return null; + } + + var bd = new b2BodyDef(); + if ( bodyJson.type == 2 ) + bd.type = b2_dynamicBody; + else if ( bodyJson.type == 1 ) + bd.type = b2_kinematicBody; + if ( bodyJson.hasOwnProperty('angle') ) + bd.angle = bodyJson.angle; + if ( bodyJson.hasOwnProperty('angularVelocity') ) + bd.angularVelocity = bodyJson.angularVelocity; + if ( bodyJson.hasOwnProperty('active') ) + bd.awake = bodyJson.active; + if ( bodyJson.hasOwnProperty('fixedRotation') ) + bd.fixedRotation = bodyJson.fixedRotation; + if ( bodyJson.hasOwnProperty('linearVelocity') && bodyJson.linearVelocity instanceof Object ) + bd.linearVelocity.SetV( bodyJson.linearVelocity ); + if ( bodyJson.hasOwnProperty('position') && bodyJson.position instanceof Object ) + bodyJson.position.y *= -1; + bd.position.SetV( bodyJson.position ); + if ( bodyJson.hasOwnProperty('awake') ) + bd.awake = bodyJson.awake; + else + bd.awake = false; + var body = world.CreateBody(bd); + if ( bodyJson.hasOwnProperty('fixture') ) { + for (k = 0; k < bodyJson['fixture'].length; k++) { + var fixtureJson = bodyJson['fixture'][k]; + this.loadFixtureFromRUBE(body, fixtureJson); + } + } + if ( bodyJson.hasOwnProperty('name') ) + body.name = bodyJson.name; + if ( bodyJson.hasOwnProperty('customProperties') ) + body.customProperties = bodyJson.customProperties; + return body; + } + + RubeLoader.prototype.loadFixtureFromRUBE = function (body, fixtureJson) { + //console.log(fixtureJson); + var fd = new b2FixtureDef(); + if (fixtureJson.hasOwnProperty('friction')) + fd.friction = fixtureJson.friction; + if (fixtureJson.hasOwnProperty('density')) + fd.density = fixtureJson.density; + if (fixtureJson.hasOwnProperty('restitution')) + fd.restitution = fixtureJson.restitution; + if (fixtureJson.hasOwnProperty('sensor')) + fd.isSensor = fixtureJson.sensor; + if ( fixtureJson.hasOwnProperty('filter-categoryBits') ) + fd.filter.categoryBits = fixtureJson['filter-categoryBits']; + if ( fixtureJson.hasOwnProperty('filter-maskBits') ) + fd.filter.maskBits = fixtureJson['filter-maskBits']; + if ( fixtureJson.hasOwnProperty('filter-groupIndex') ) + fd.filter.groupIndex = fixtureJson['filter-groupIndex']; + if (fixtureJson.hasOwnProperty('circle')) { + fd.shape = new b2CircleShape(); + fd.shape.m_radius = fixtureJson.circle.radius; + if ( fixtureJson.circle.center ) + fd.shape.m_p.SetV(fixtureJson.circle.center); + var fixture = body.CreateFixture(fd); + if ( fixtureJson.name ) + fixture.name = fixtureJson.name; + } + else if (fixtureJson.hasOwnProperty('polygon')) { + fd.shape = new b2PolygonShape(); + var verts = []; + + + for (v = fixtureJson.polygon.vertices.x.length - 1; v >= 0 ; v--) + verts.push( new b2Vec2( fixtureJson.polygon.vertices.x[v], -fixtureJson.polygon.vertices.y[v] ) ); + fd.shape.SetAsArray(verts, verts.length); + var fixture = body.CreateFixture(fd); + if ( fixture && fixtureJson.name ) + fixture.name = fixtureJson.name; + } + else if (fixtureJson.hasOwnProperty('chain')) { + fd.shape = new b2PolygonShape(); + var lastVertex = new b2Vec2(); + for (v = fixtureJson.chain.vertices.x.length - 1; v >= 0; v--) { + var thisVertex = new b2Vec2( fixtureJson.chain.vertices.x[v], -fixtureJson.chain.vertices.y[v] ); + if ( v < fixtureJson.chain.vertices.x.length - 1 ) { + fd.shape.SetAsEdge( lastVertex, thisVertex ); + var fixture = body.CreateFixture(fd); + if ( fixtureJson.name ) + fixture.name = fixtureJson.name; + } + lastVertex = thisVertex; + } + } + else { + console.log("Could not find shape type for fixture"); + } + } + + RubeLoader.prototype.getVectorValue = function (val) { + if ( val instanceof Object ) { + val.y *= -1; + return val; + } else { + return { x:0, y:0 }; + } + } + + RubeLoader.prototype.loadJointCommonProperties = function (jd, jointJson, loadedBodies) { + jd.bodyA = loadedBodies[jointJson.bodyA]; + jd.bodyB = loadedBodies[jointJson.bodyB]; + jd.localAnchorA.SetV( this.getVectorValue(jointJson.anchorA) ); + jd.localAnchorB.SetV( this.getVectorValue(jointJson.anchorB) ); + if ( jointJson.collideConnected ) + jd.collideConnected = jointJson.collideConnected; + } + + RubeLoader.prototype.loadJointFromRUBE = function (jointJson, world, loadedBodies) + { + if ( ! jointJson.hasOwnProperty('type') ) { + console.log("Joint does not have a 'type' property"); + return null; + } + if ( jointJson.bodyA >= loadedBodies.length ) { + console.log("Index for bodyA is invalid: " + jointJson.bodyA ); + return null; + } + if ( jointJson.bodyB >= loadedBodies.length ) { + console.log("Index for bodyB is invalid: " + jointJson.bodyB ); + return null; + } + + var joint = null; + if ( jointJson.type == "revolute" ) { + var jd = new b2RevoluteJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('refAngle') ) + jd.referenceAngle = jointJson.refAngle; + if ( jointJson.hasOwnProperty('lowerLimit') ) + jd.lowerAngle = jointJson.lowerLimit; + if ( jointJson.hasOwnProperty('upperLimit') ) + jd.upperAngle = jointJson.upperLimit; + if ( jointJson.hasOwnProperty('maxMotorTorque') ) + jd.maxMotorTorque = jointJson.maxMotorTorque; + if ( jointJson.hasOwnProperty('motorSpeed') ) + jd.motorSpeed = jointJson.motorSpeed; + if ( jointJson.hasOwnProperty('enableLimit') ) + jd.enableLimit = jointJson.enableLimit; + if ( jointJson.hasOwnProperty('enableMotor') ) + jd.enableMotor = jointJson.enableMotor; + joint = world.CreateJoint(jd); + } + else if ( jointJson.type == "distance" || jointJson.type == "rope" ) { + if ( jointJson.type == "rope" ) + console.log("Replacing unsupported rope joint with distance joint!"); + var jd = new b2DistanceJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('length') ) + jd.length = jointJson.length; + if ( jointJson.hasOwnProperty('dampingRatio') ) + jd.dampingRatio = jointJson.dampingRatio; + if ( jointJson.hasOwnProperty('frequency') ) + jd.frequencyHz = jointJson.frequency; + joint = world.CreateJoint(jd); + } + else if ( jointJson.type == "prismatic" ) { + var jd = new b2PrismaticJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('localAxisA') ) + jd.localAxisA.SetV( this.getVectorValue(jointJson.localAxisA) ); + if ( jointJson.hasOwnProperty('refAngle') ) + jd.referenceAngle = jointJson.refAngle; + if ( jointJson.hasOwnProperty('enableLimit') ) + jd.enableLimit = jointJson.enableLimit; + if ( jointJson.hasOwnProperty('lowerLimit') ) + jd.lowerTranslation = jointJson.lowerLimit; + if ( jointJson.hasOwnProperty('upperLimit') ) + jd.upperTranslation = jointJson.upperLimit; + if ( jointJson.hasOwnProperty('enableMotor') ) + jd.enableMotor = jointJson.enableMotor; + if ( jointJson.hasOwnProperty('maxMotorForce') ) + jd.maxMotorForce = jointJson.maxMotorForce; + if ( jointJson.hasOwnProperty('motorSpeed') ) + jd.motorSpeed = jointJson.motorSpeed; + joint = world.CreateJoint(jd); + } + else if ( jointJson.type == "wheel" ) { + //Make a fake wheel joint using a line joint and a distance joint. + //Return the line joint because it has the linear motor controls. + //Use ApplyTorque on the bodies to spin the wheel... + + var jd = new b2DistanceJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + jd.length = 0.0; + if ( jointJson.hasOwnProperty('springDampingRatio') ) + jd.dampingRatio = jointJson.springDampingRatio; + if ( jointJson.hasOwnProperty('springFrequency') ) + jd.frequencyHz = jointJson.springFrequency; + world.CreateJoint(jd); + + jd = new b2LineJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('localAxisA') ) + jd.localAxisA.SetV( this.getVectorValue(jointJson.localAxisA) ); + + joint = world.CreateJoint(jd); + } + else if ( jointJson.type == "friction" ) { + var jd = new b2FrictionJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('maxForce') ) + jd.maxForce = jointJson.maxForce; + if ( jointJson.hasOwnProperty('maxTorque') ) + jd.maxTorque = jointJson.maxTorque; + joint = world.CreateJoint(jd); + } + else if ( jointJson.type == "weld" ) { + var jd = new b2WeldJointDef(); + this.loadJointCommonProperties(jd, jointJson, loadedBodies); + if ( jointJson.hasOwnProperty('referenceAngle') ) + jd.referenceAngle = jointJson.referenceAngle; + joint = world.CreateJoint(jd); + } + else { + console.log("Unsupported joint type: " + jointJson.type); + console.log(jointJson); + } + if ( joint && jointJson.name ) + joint.name = jointJson.name; + return joint; + } + + RubeLoader.prototype.makeClone = function (obj) { + var newObj = (obj instanceof Array) ? [] : {}; + for (var i in obj) { + if (obj[i] && typeof obj[i] == "object") + newObj[i] = this.makeClone(obj[i]); + else + newObj[i] = obj[i]; + } + return newObj; + }; + + RubeLoader.prototype.loadImageFromRUBE = function (imageJson, world, loadedBodies) + { + var image = this.makeClone(imageJson); + + if ( image.hasOwnProperty('body') && image.body >= 0 ) + image.body = loadedBodies[image.body];//change index to the actual body + else + image.body = null; + + image.center = new b2Vec2(); + image.center.SetV( this.getVectorValue(imageJson.center) ); + + return image; + } + + + //load the scene into an already existing world variable + RubeLoader.prototype.loadSceneIntoWorld = function (worldJson, world) { + + var loadedBodies = []; + if ( worldJson.hasOwnProperty('body') ) { + for (var i = 0; i < worldJson.body.length; i++) { + var bodyJson = worldJson.body[i]; + var body = this.loadBodyFromRUBE(bodyJson, world); + if ( body ) + loadedBodies.push( body ); + } + } + + + var loadedJoints = []; + if ( worldJson.hasOwnProperty('joint') ) { + for (var i = 0; i < worldJson.joint.length; i++) { + var jointJson = worldJson.joint[i]; + var joint = this.loadJointFromRUBE(jointJson, world, loadedBodies); + if ( joint ) + loadedJoints.push( joint ); + } + } + /* + var loadedImages = []; + if ( worldJson.hasOwnProperty('image') ) { + for (var i = 0; i < worldJson.image.length; i++) { + var imageJson = worldJson.image[i]; + var image = this.loadImageFromRUBE(imageJson, world, loadedBodies); + if ( image ) + loadedImages.push( image ); + } + world.images = loadedImages; + } + */ + + var scene = { + bodies: loadedBodies, + // joints: loadedJoints + }; + + return scene; + } + + //create a world variable and return it if loading succeeds + RubeLoader.prototype.loadWorldFromRUBE = function (worldJson) { + var gravity = new b2Vec2(0,0); + if ( worldJson.hasOwnProperty('gravity') && worldJson.gravity instanceof Object ) + gravity.SetV( worldJson.gravity ); + var world = new b2World( gravity ); + if ( ! this.loadSceneIntoWorld(worldJson, world) ) + return false; + return world; + } + + RubeLoader.prototype.getNamedBodies = function (world, name) { + var bodies = []; + for (b = world.m_bodyList; b; b = b.m_next) { + if ( b.name == name ) + bodies.push(b); + } + return bodies; + } + + RubeLoader.prototype.getNamedFixtures = function (world, name) { + var fixtures = []; + for (b = world.m_bodyList; b; b = b.m_next) { + for (f = b.m_fixtureList; f; f = f.m_next) { + if ( f.name == name ) + fixtures.push(f); + } + } + return fixtures; + } + + RubeLoader.prototype.getNamedJoints = function (world, name) { + var joints = []; + for (j = world.m_jointList; j; j = j.m_next) { + if ( j.name == name ) + joints.push(j); + } + return joints; + } + + RubeLoader.prototype.getNamedImages = function (world, name) { + var images = []; + for (i = 0; i < world.images.length; i++) { + if ( world.images[i].name == name ) + images.push(world.images[i].name); + } + return images; + } + + //custom properties + RubeLoader.prototype.getBodiesByCustomProperty = function (world, propertyType, propertyName, valueToMatch) { + var bodies = []; + for (b = world.m_bodyList; b; b = b.m_next) { + if ( ! b.hasOwnProperty('customProperties') ) + continue; + for (var i = 0; i < b.customProperties.length; i++) { + if ( ! b.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! b.customProperties[i].hasOwnProperty(propertyType) ) + continue; + if ( b.customProperties[i].name == propertyName && + b.customProperties[i][propertyType] == valueToMatch) + bodies.push(b); + } + } + return bodies; + } + + RubeLoader.prototype.hasCustomProperty = function (item, propertyType, propertyName) { + if ( !item.hasOwnProperty('customProperties') ) + return false; + for (var i = 0; i < item.customProperties.length; i++) { + if ( ! item.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! item.customProperties[i].hasOwnProperty(propertyType) ) + continue; + return true; + } + return false; + } + + RubeLoader.prototype.getCustomProperty = function (item, propertyType, propertyName, defaultValue) { + if ( !item.hasOwnProperty('customProperties') ) + return defaultValue; + for (var i = 0; i < item.customProperties.length; i++) { + if ( ! item.customProperties[i].hasOwnProperty("name") ) + continue; + if ( ! item.customProperties[i].hasOwnProperty(propertyType) ) + continue; + if ( item.customProperties[i].name == propertyName ) + return item.customProperties[i][propertyType]; + } + return defaultValue; + } + + + + + return RubeLoader; + +}); \ No newline at end of file diff --git a/static/maps/tiled/debug.json b/static/maps/tiled/debug.json index 8394622..9ea57bf 100644 --- a/static/maps/tiled/debug.json +++ b/static/maps/tiled/debug.json @@ -40,8 +40,8 @@ "type":"", "visible":true, "width":0, - "x":248.535368857004, - "y":176.525492560429 + "x":222.535368857004, + "y":170.525492560429 }, { "ellipse":true, @@ -186,7 +186,7 @@ }, { "height":0, - "name":"Knife", + "name":"Rube", "properties": { @@ -195,8 +195,8 @@ "type":"", "visible":true, "width":0, - "x":462.607333333333, - "y":357.255333333333 + "x":236.607333333333, + "y":471.255333333333 }, { "height":0, @@ -239,6 +239,20 @@ "width":0, "x":543.000000000001, "y":356.333333333333 + }, + { + "height":0, + "name":"Knife", + "properties": + { + + }, + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":464, + "y":357 }], "opacity":1, "type":"objectgroup",