mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
replaced killed doll with ragdoll - fixes #50
This commit is contained in:
parent
aa6fdaa2df
commit
413254bfa4
19 changed files with 330 additions and 88 deletions
|
|
@ -158,16 +158,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.setActionState("fall");
|
||||
}
|
||||
|
||||
Doll.prototype.kill = function() {
|
||||
this.body.SetFixedRotation(false);
|
||||
};
|
||||
|
||||
Doll.prototype.getPosition = function() {
|
||||
var pos = this.body.GetPosition();
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y
|
||||
};
|
||||
return this.body.GetPosition().Copy();
|
||||
};
|
||||
|
||||
Doll.prototype.getHeadPosition = function() {
|
||||
|
|
@ -235,7 +227,13 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
Doll.prototype.stop = function () {
|
||||
this.moveDirection = 0;
|
||||
this.setFriction(Settings.PLAYER_FRICTION);
|
||||
if(this.isStanding()) this.setActionState("stand");
|
||||
if(this.isStanding()) {
|
||||
this.setActionState("stand");
|
||||
} else {
|
||||
var vector = this.body.GetLinearVelocity().Copy();
|
||||
vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR;
|
||||
this.body.SetLinearVelocity(vector);
|
||||
}
|
||||
}
|
||||
|
||||
Doll.prototype.jump = function () {
|
||||
|
|
@ -251,6 +249,17 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
}
|
||||
}
|
||||
|
||||
Doll.prototype.jumpStop = function () {
|
||||
if (!this.isStanding() ) {
|
||||
this.body.SetAwake(true);
|
||||
var vector = this.body.GetLinearVelocity().Copy();
|
||||
if(vector.y < 0) {
|
||||
vector.y *= Settings.JUMP_STOP_DAMPING_FACTOR;
|
||||
this.body.SetLinearVelocity(vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Doll.prototype.setStanding = function (isStanding) {
|
||||
if (this.standing == isStanding) return;
|
||||
this.standing = isStanding;
|
||||
|
|
@ -344,6 +353,13 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
}
|
||||
}
|
||||
|
||||
Doll.prototype.getVelocities = function() {
|
||||
return {
|
||||
linearVelocity: this.body.GetLinearVelocity(),
|
||||
angularVelocity: this.body.GetAngularVelocity()
|
||||
};
|
||||
};
|
||||
|
||||
Doll.prototype.update = function() {
|
||||
|
||||
if (this.body.GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
});
|
||||
37
app/Game/Core/GameObjects/SpectatorDoll.js
Normal file
37
app/Game/Core/GameObjects/SpectatorDoll.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
|
||||
"Lib/Vendor/Box2D"
|
||||
],
|
||||
|
||||
function (Parent, Box2D) {
|
||||
|
||||
function SpectatorDoll(physicsEngine, uid, player) {
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
}
|
||||
|
||||
SpectatorDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
SpectatorDoll.prototype.getBodyDef = function() {
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = this.getPosition().x;
|
||||
bodyDef.position.y = this.getPosition().y;
|
||||
bodyDef.angle = 0;
|
||||
|
||||
return bodyDef;
|
||||
};
|
||||
|
||||
SpectatorDoll.prototype.getPosition = function() {
|
||||
return {x: 10, y: 10};
|
||||
}
|
||||
|
||||
SpectatorDoll.prototype.getHeadPosition = function() {
|
||||
return {x: 10, y: 10};
|
||||
}
|
||||
|
||||
SpectatorDoll.prototype.update = function() {
|
||||
};
|
||||
|
||||
return SpectatorDoll;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue