replaced killed doll with ragdoll - fixes #50

This commit is contained in:
logsol 2014-02-18 01:15:24 +01:00
parent aa6fdaa2df
commit 413254bfa4
19 changed files with 330 additions and 88 deletions

View file

@ -1,10 +1,11 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D",
"Game/Config/Settings"
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Settings) {
function (Parent, Box2D, Settings, NotificationCenter) {
function RagDoll(physicsEngine, uid, options) {
@ -160,6 +161,9 @@ function (Parent, Box2D, Settings) {
0,
options.limbs.upperRightArm.height / 2
);
NotificationCenter.trigger("game/object/add", 'animated', this);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -168,6 +172,14 @@ function (Parent, Box2D, Settings) {
return 55; //parseInt(this.uid.split("-")[1], 10);
};
RagDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy();
};
RagDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy();
};
RagDoll.prototype.getBodyDef = function() {
var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
@ -212,11 +224,6 @@ function (Parent, Box2D, Settings) {
this.body.CreateFixture(fixtureDef);
};
RagDoll.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
// remove head!!11
};
RagDoll.prototype.addHead = function() {
var x = this.options.x + this.options.limbs.head.x,
y = this.options.y + this.options.limbs.head.y;
@ -341,11 +348,29 @@ function (Parent, Box2D, Settings) {
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
-y * Settings.MAX_THROW_FORCE * 1.5 *limbDampingFactor // 1.5 is to throw higher then far
);
this.body.SetLinearVelocity(vector);
body.SetLinearVelocity(vector);
// body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
}
};
RagDoll.prototype.setVelocities = function(options) {
this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity);
for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity);
}
};
RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("game/object/remove", 'animated', this);
var world = this.body.GetWorld();
Parent.prototype.destroy.call(this);
for (var name in this.limbs) {
world.DestroyBody(this.limbs[name]);
}
};
return RagDoll;
});