mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fixed remote joint
This commit is contained in:
parent
0665348ae2
commit
b159bbb1cc
12 changed files with 143 additions and 29 deletions
|
|
@ -33,10 +33,6 @@ define(function () {
|
|||
if(options) this.player.lookAt(options.x, options.y);
|
||||
}
|
||||
|
||||
PlayerController.prototype.handAction = function(options) {
|
||||
if (options) this.player.handAction(options.x, options.y);
|
||||
};
|
||||
|
||||
PlayerController.prototype.update = function () {
|
||||
if(this._walkingDirectionStatus != 0) {
|
||||
this.player.move(this._walkingDirectionStatus);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ define([
|
|||
|
||||
function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||
|
||||
function Doll (physicsEngine, uid) {
|
||||
function Doll (physicsEngine, uid, player) {
|
||||
|
||||
this.player = player;
|
||||
this.height = 43;
|
||||
this.width = 9;
|
||||
this.headHeight = 12;
|
||||
|
|
@ -255,7 +256,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
}
|
||||
};
|
||||
|
||||
Doll.prototype.grab = function(x, y) {
|
||||
Doll.prototype.grab = function(item) {
|
||||
|
||||
this.holdingItem = item;
|
||||
this.positionHoldingItem();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
var item = null;
|
||||
if (this.lookDirection == -1) {
|
||||
item = this.reachableItems.left.shift();
|
||||
|
|
@ -272,6 +280,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
|
||||
return item;
|
||||
*/
|
||||
};
|
||||
|
||||
Doll.prototype.positionHoldingItem = function() {
|
||||
|
|
@ -312,7 +321,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
),
|
||||
body.GetLocalCenter()
|
||||
);
|
||||
body.SetAngularVelocity(8 * x);
|
||||
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x); //
|
||||
};
|
||||
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ function (Parent, Box2D, Settings) {
|
|||
this.createFixture();
|
||||
this.body.ResetMassData();
|
||||
this.flipDirection = 1;
|
||||
this.heldByPlayers = [];
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -67,6 +68,31 @@ function (Parent, Box2D, Settings) {
|
|||
|
||||
// FIXME: implement body flip if necessary
|
||||
};
|
||||
|
||||
Item.prototype.isGrabbingAllowed = function(player) {
|
||||
return this.heldByPlayers.length == 0;
|
||||
};
|
||||
|
||||
Item.prototype.beingGrabbed = function(player) {
|
||||
if(this.isGrabbingAllowed(player)) {
|
||||
this.heldByPlayers.push(player);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Item.prototype.isReleasingAllowed = function(player) {
|
||||
return true;
|
||||
};
|
||||
|
||||
Item.prototype.beingReleased = function(player) {
|
||||
if(this.isReleasingAllowed(player)) {
|
||||
var pos = this.heldByPlayers.indexOf(player);
|
||||
if(pos >= 0) {
|
||||
this.heldByPlayers.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Item;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function (Doll, Settings) {
|
|||
};
|
||||
|
||||
Player.prototype.spawn = function (x, y) {
|
||||
this.doll = new Doll(this.physicsEngine, "doll-" + this.id);
|
||||
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
|
||||
this.doll.spawn(x, y);
|
||||
this.isSpawned = true;
|
||||
}
|
||||
|
|
@ -52,17 +52,21 @@ function (Doll, Settings) {
|
|||
if(this.doll) this.doll.lookAt(x, y);
|
||||
}
|
||||
|
||||
Player.prototype.handAction = function(x, y) {
|
||||
Player.prototype.handAction = function(x, y, isHolding, item) {
|
||||
|
||||
if (this.holdingItem) {
|
||||
if (isHolding) {
|
||||
// throw
|
||||
this.doll.throw(this.holdingItem, x, y);
|
||||
this.holdingItem = null;
|
||||
if(item.isReleasingAllowed()) {
|
||||
item.beingReleased(this);
|
||||
this.doll.throw(item, x, y);
|
||||
this.holdingItem = null;
|
||||
}
|
||||
} else {
|
||||
// take
|
||||
var item = this.doll.grab(x, y);
|
||||
if(item) {
|
||||
this.holdingItem = item;
|
||||
if(item.isGrabbingAllowed()) {
|
||||
item.beingGrabbed(this);
|
||||
this.doll.grab(item);
|
||||
this.holdingItem = item;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue