mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added angular throwing
This commit is contained in:
parent
9100215ceb
commit
d24ab60756
12 changed files with 93 additions and 34 deletions
|
|
@ -354,12 +354,12 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
}
|
||||
};
|
||||
|
||||
Doll.prototype.throw = function(item, x, y) {
|
||||
Doll.prototype.throw = function(item, options) {
|
||||
this.body.GetWorld().DestroyJoint(this.holdingJoint);
|
||||
this.holdingJoint = null;
|
||||
this.holdingItem = null;
|
||||
|
||||
item.throw(x, y);
|
||||
item.throw(options);
|
||||
};
|
||||
|
||||
Doll.prototype.isAnotherPlayerNearby = function() {
|
||||
|
|
|
|||
|
|
@ -129,17 +129,17 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
return this.body.GetWorldCenter();
|
||||
};
|
||||
|
||||
Item.prototype.throw = function(x, y) {
|
||||
Item.prototype.throw = function(options) {
|
||||
var body = this.body;
|
||||
body.SetAwake(true);
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE / this.options.weight,
|
||||
-y * Settings.MAX_THROW_FORCE / this.options.weight
|
||||
options.x * Settings.MAX_THROW_FORCE / this.options.weight,
|
||||
-options.y * Settings.MAX_THROW_FORCE / this.options.weight
|
||||
);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
|
||||
body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY);
|
||||
};
|
||||
|
||||
Item.prototype.destroy = function() {
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
this.holdingItem = item;
|
||||
};
|
||||
|
||||
Player.prototype.throw = function(x, y, item) {
|
||||
Player.prototype.throw = function(options, item) {
|
||||
if(!this.isSpawned) return false;
|
||||
this.doll.throw(item, x, y);
|
||||
this.doll.throw(item, options);
|
||||
item.beingReleased(this);
|
||||
this.holdingItem = null;
|
||||
};
|
||||
|
|
@ -99,7 +99,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
|
||||
// FIXME: do something better then just respawn in GameController
|
||||
if(this.holdingItem) {
|
||||
this.throw(0, 0, this.holdingItem)
|
||||
this.throw(0, 0, 0, this.holdingItem)
|
||||
}
|
||||
|
||||
// prepare for creating the ragdoll
|
||||
|
|
@ -144,7 +144,12 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
|
||||
|
||||
if(this.holdingItem) {
|
||||
this.throw(0, 0, this.holdingItem);
|
||||
var options = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
av: 0
|
||||
};
|
||||
this.throw(options, this.holdingItem);
|
||||
}
|
||||
|
||||
this.spectatorDoll.destroy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue