first visible RagDoll
|
|
@ -19,7 +19,9 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
|
||||||
|
|
||||||
RagDoll.prototype.createMesh = function() {
|
RagDoll.prototype.createMesh = function() {
|
||||||
this.createLimbMesh("chest");
|
this.createLimbMesh("chest");
|
||||||
this.createLimbMesh("head");
|
for(var name in this.options.limbs) {
|
||||||
|
this.createLimbMesh(name);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RagDoll.prototype.createLimbMesh = function(name) {
|
RagDoll.prototype.createLimbMesh = function(name) {
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ function (Parent, Box2D, Options, Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Item.prototype.reposition = function(handPosition, direction) {
|
Item.prototype.reposition = function(handPosition, direction) {
|
||||||
|
this.body.SetAwake(true);
|
||||||
var position = new Box2D.Common.Math.b2Vec2(
|
var position = new Box2D.Common.Math.b2Vec2(
|
||||||
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
|
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
|
||||||
handPosition.y
|
handPosition.y
|
||||||
|
|
@ -118,15 +119,6 @@ function (Parent, Box2D, Options, Settings) {
|
||||||
Item.prototype.throw = function(x, y) {
|
Item.prototype.throw = function(x, y) {
|
||||||
var body = this.body;
|
var body = this.body;
|
||||||
body.SetAwake(true);
|
body.SetAwake(true);
|
||||||
/*
|
|
||||||
body.ApplyImpulse(
|
|
||||||
new Box2D.Common.Math.b2Vec2(
|
|
||||||
x * Settings.MAX_THROW_FORCE,
|
|
||||||
-y * Settings.MAX_THROW_FORCE * 1.5 // 1.5 is to throw higher then far
|
|
||||||
),
|
|
||||||
body.GetLocalCenter()
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
var vector = new Box2D.Common.Math.b2Vec2(
|
var vector = new Box2D.Common.Math.b2Vec2(
|
||||||
x * Settings.MAX_THROW_FORCE,
|
x * Settings.MAX_THROW_FORCE,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ function (Parent, Box2D, Settings) {
|
||||||
options.limbs = {};
|
options.limbs = {};
|
||||||
options.limbs.chest = {
|
options.limbs.chest = {
|
||||||
width: 6,
|
width: 6,
|
||||||
height: 12,
|
height: 18,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
};
|
};
|
||||||
|
|
@ -24,29 +24,154 @@ function (Parent, Box2D, Settings) {
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 12,
|
height: 12,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: - options.limbs.chest.height / 2 - 5
|
y: - options.limbs.chest.height / 2 - 7
|
||||||
};
|
};
|
||||||
|
|
||||||
|
options.limbs.upperLeftLeg = {
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
x: -2,
|
||||||
|
y: options.limbs.chest.height / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.upperRightLeg = {
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
x: 2,
|
||||||
|
y: options.limbs.chest.height / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.lowerLeftLeg = {
|
||||||
|
width: 4,
|
||||||
|
height: 4,
|
||||||
|
x: -2,
|
||||||
|
y: options.limbs.chest.height / 2 + options.limbs.upperLeftLeg.height
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.lowerRightLeg = {
|
||||||
|
width: 4,
|
||||||
|
height: 4,
|
||||||
|
x: 2,
|
||||||
|
y: options.limbs.chest.height / 2 + options.limbs.upperRightLeg.height
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
options.limbs.upperLeftArm = {
|
||||||
|
width: 2,
|
||||||
|
height: 8,
|
||||||
|
x: -2,
|
||||||
|
y: -options.limbs.chest.height / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.upperRightArm = {
|
||||||
|
width: 3,
|
||||||
|
height: 8,
|
||||||
|
x: 2,
|
||||||
|
y: -options.limbs.chest.height / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.lowerLeftArm = {
|
||||||
|
width: 2,
|
||||||
|
height: 5,
|
||||||
|
x: -2,
|
||||||
|
y: -options.limbs.chest.height / 2 + options.limbs.upperLeftArm.height
|
||||||
|
};
|
||||||
|
|
||||||
|
options.limbs.lowerRightArm = {
|
||||||
|
width: 2,
|
||||||
|
height: 5,
|
||||||
|
x: 2,
|
||||||
|
y: -options.limbs.chest.height / 2 + options.limbs.upperRightArm.height
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, uid, options);
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
this.createSensor();
|
//this.createSensor();
|
||||||
|
|
||||||
|
this.limbs = {};
|
||||||
|
|
||||||
this.limbs = {
|
|
||||||
head: null
|
|
||||||
};
|
|
||||||
this.addHead();
|
this.addHead();
|
||||||
|
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"upperLeftLeg",
|
||||||
|
this.body,
|
||||||
|
options.limbs.upperLeftLeg.x,
|
||||||
|
options.limbs.chest.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"upperRightLeg",
|
||||||
|
this.body,
|
||||||
|
options.limbs.upperRightLeg.x,
|
||||||
|
options.limbs.chest.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"lowerLeftLeg",
|
||||||
|
this.limbs.upperLeftLeg,
|
||||||
|
0,
|
||||||
|
options.limbs.upperLeftLeg.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"lowerRightLeg",
|
||||||
|
this.limbs.upperRightLeg,
|
||||||
|
0,
|
||||||
|
options.limbs.upperRightLeg.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"upperLeftArm",
|
||||||
|
this.body,
|
||||||
|
options.limbs.upperLeftArm.x,
|
||||||
|
-options.limbs.chest.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"upperRightArm",
|
||||||
|
this.body,
|
||||||
|
options.limbs.upperRightArm.x,
|
||||||
|
-options.limbs.chest.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"lowerLeftArm",
|
||||||
|
this.limbs.upperLeftArm,
|
||||||
|
0,
|
||||||
|
options.limbs.upperLeftArm.height / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addLimb(
|
||||||
|
"lowerRightArm",
|
||||||
|
this.limbs.upperRightArm,
|
||||||
|
0,
|
||||||
|
options.limbs.upperRightArm.height / 2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
RagDoll.prototype = Object.create(Parent.prototype);
|
RagDoll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
RagDoll.prototype.getId = function() {
|
RagDoll.prototype.getId = function() {
|
||||||
return 1; parseInt(this.uid.split("-")[1], 10);
|
return 55; //parseInt(this.uid.split("-")[1], 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
RagDoll.prototype.getBodyDef = function() {
|
RagDoll.prototype.getBodyDef = function() {
|
||||||
var bodyDef = Parent.prototype.getBodyDef.call(this);
|
var bodyDef = Parent.prototype.getBodyDef.call(this);
|
||||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
//bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||||
return bodyDef;
|
return bodyDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -123,21 +248,14 @@ function (Parent, Box2D, Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
RagDoll.prototype.attachHead = function() {
|
RagDoll.prototype.attachHead = function() {
|
||||||
var chestPosition = this.body.GetPosition();
|
|
||||||
|
|
||||||
var x = chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
|
|
||||||
y = chestPosition.y + this.options.limbs.head.y / Settings.RATIO;
|
|
||||||
|
|
||||||
var head = this.limbs.head;
|
var head = this.limbs.head;
|
||||||
head.SetPosition(new Box2D.Common.Math.b2Vec2(x, y));
|
|
||||||
head.SetAngle(0);
|
|
||||||
|
|
||||||
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
||||||
jointDef.enableMotor = false;
|
jointDef.enableMotor = false;
|
||||||
|
|
||||||
var point = chestPosition;
|
var pos = this.body.GetWorldCenter().Copy();
|
||||||
//point.y -= this.options.limbs.chest.height / 2 / Settings.RATIO;
|
pos.y -= this.options.limbs.chest.height / 2 / Settings.RATIO;
|
||||||
jointDef.Initialize(this.body, head, point);
|
jointDef.Initialize(this.body, head, pos);
|
||||||
jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
|
jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
|
||||||
jointDef.upperAngle = 0.25 * Box2D.Common.b2Settings.b2_pi; // 45 degrees
|
jointDef.upperAngle = 0.25 * Box2D.Common.b2Settings.b2_pi; // 45 degrees
|
||||||
jointDef.enableLimit = true;
|
jointDef.enableLimit = true;
|
||||||
|
|
@ -145,6 +263,51 @@ function (Parent, Box2D, Settings) {
|
||||||
this.body.GetWorld().CreateJoint(jointDef);
|
this.body.GetWorld().CreateJoint(jointDef);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RagDoll.prototype.addLimb = function(name, connectTo, xOffset, yOffset) {
|
||||||
|
var x = this.options.x + this.options.limbs[name].x,
|
||||||
|
y = this.options.y + this.options.limbs[name].y;
|
||||||
|
|
||||||
|
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||||
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||||
|
bodyDef.position.x = x / Settings.RATIO;
|
||||||
|
bodyDef.position.y = y / Settings.RATIO;
|
||||||
|
bodyDef.angle = 0;
|
||||||
|
|
||||||
|
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
|
shape.SetAsOrientedBox(
|
||||||
|
this.options.limbs[name].width / 2 / Settings.RATIO,
|
||||||
|
this.options.limbs[name].height / 2 / Settings.RATIO,
|
||||||
|
new Box2D.Common.Math.b2Vec2(0, this.options.limbs[name].height / 2 / Settings.RATIO)
|
||||||
|
);
|
||||||
|
|
||||||
|
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||||
|
fixtureDef.density = Settings.PLAYER_DENSITY;
|
||||||
|
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||||
|
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||||
|
fixtureDef.shape = shape;
|
||||||
|
fixtureDef.isSensor = false;
|
||||||
|
fixtureDef.filter.groupIndex = -this.getId();
|
||||||
|
|
||||||
|
var limb = this.body.GetWorld().CreateBody(bodyDef);
|
||||||
|
limb.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
|
this.limbs[name] = limb;
|
||||||
|
|
||||||
|
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
||||||
|
jointDef.enableMotor = false;
|
||||||
|
|
||||||
|
var pos = connectTo.GetWorldCenter().Copy();
|
||||||
|
pos.x += (xOffset / Settings.RATIO);
|
||||||
|
pos.y += (yOffset / Settings.RATIO);
|
||||||
|
jointDef.Initialize(connectTo, limb, pos);
|
||||||
|
jointDef.lowerAngle = -0.15 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
|
||||||
|
jointDef.upperAngle = 0.15 * Box2D.Common.b2Settings.b2_pi; // 45 degrees
|
||||||
|
jointDef.enableLimit = true;
|
||||||
|
|
||||||
|
this.body.GetWorld().CreateJoint(jointDef);
|
||||||
|
};
|
||||||
|
|
||||||
RagDoll.prototype.detachHead = function() {
|
RagDoll.prototype.detachHead = function() {
|
||||||
var joint = this.limbs.head.GetJointList().joint;
|
var joint = this.limbs.head.GetJointList().joint;
|
||||||
if(joint) {
|
if(joint) {
|
||||||
|
|
@ -173,15 +336,6 @@ function (Parent, Box2D, Settings) {
|
||||||
for(var name in this.limbs) {
|
for(var name in this.limbs) {
|
||||||
var body = this.limbs[name];
|
var body = this.limbs[name];
|
||||||
body.SetAwake(true);
|
body.SetAwake(true);
|
||||||
/*
|
|
||||||
body.ApplyImpulse(
|
|
||||||
new Box2D.Common.Math.b2Vec2(
|
|
||||||
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
|
|
||||||
-y * Settings.MAX_THROW_FORCE * 1.5 *limbDampingFactor // 1.5 is to throw higher then far
|
|
||||||
),
|
|
||||||
body.GetLocalCenter()
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
var vector = new Box2D.Common.Math.b2Vec2(
|
var vector = new Box2D.Common.Math.b2Vec2(
|
||||||
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
|
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
|
||||||
|
|
|
||||||
BIN
static/img/Characters/Chuck/chest.png
Executable file → Normal file
|
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 306 B |
|
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 148 B |
|
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 158 B |
|
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 148 B |
BIN
static/img/Characters/Chuck/lowerRightLeg.png
Executable file
|
After Width: | Height: | Size: 158 B |
|
Before Width: | Height: | Size: 145 B After Width: | Height: | Size: 145 B |
|
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
|
Before Width: | Height: | Size: 170 B After Width: | Height: | Size: 170 B |
BIN
static/img/Characters/Chuck/upperRightLeg.png
Executable file
|
After Width: | Height: | Size: 144 B |
|
|
@ -246,7 +246,7 @@
|
||||||
"properties":
|
"properties":
|
||||||
{
|
{
|
||||||
"category":"graveyard",
|
"category":"graveyard",
|
||||||
"grabAngle":"0",
|
"grabAngle":"-0.3",
|
||||||
"height":"12",
|
"height":"12",
|
||||||
"image":"chest.png",
|
"image":"chest.png",
|
||||||
"name":"RagDoll",
|
"name":"RagDoll",
|
||||||
|
|
@ -260,7 +260,7 @@
|
||||||
"visible":true,
|
"visible":true,
|
||||||
"width":0,
|
"width":0,
|
||||||
"x":244,
|
"x":244,
|
||||||
"y":448
|
"y":388
|
||||||
}],
|
}],
|
||||||
"opacity":1,
|
"opacity":1,
|
||||||
"type":"objectgroup",
|
"type":"objectgroup",
|
||||||
|
|
|
||||||