fixed remote joint

This commit is contained in:
Jeena 2014-01-20 16:22:31 +01:00
parent 0665348ae2
commit b159bbb1cc
12 changed files with 143 additions and 29 deletions

View file

@ -31,6 +31,10 @@ function(Parent, NotificationCenter, Parser) {
}
};
PlayerController.prototype.handActionRequest = function(options) {
if (options) this.player.handActionRequest(options.x, options.y);
};
return PlayerController;
});

View file

@ -2,8 +2,32 @@ define([
"Game/Core/GameObjects/Doll"
],
function(Parent) {
function (Parent) {
return Parent;
function Doll(physicsEngine, uid, player) {
Parent.call(this, physicsEngine, uid, player);
}
Doll.prototype = Object.create(Parent.prototype);
Doll.prototype.findCloseItem = function(x, y) {
function findItem(array) {
for (var i = 0; i < array.length; i++) {
var item = array[i];
if(item.isGrabbingAllowed(this.player)) {
return item;
}
}
}
if (x < 0) { // looking left
return findItem(this.reachableItems.left);
} else {
return findItem(this.reachableItems.right);
}
}
return Doll;
});

View file

@ -1,9 +1,45 @@
define([
"Game/Core/Player"
"Game/Core/Player",
"Lib/Utilities/NotificationCenter"
],
function(Parent) {
function (Parent, NotificationCenter) {
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
}
return Parent;
Player.prototype = Object.create(Parent.prototype);
Player.prototype.handActionRequest = function(x, y) {
var item = null;
var isHolding = !!this.holdingItem;
if (isHolding) {
item = this.holdingItem;
} else {
item = this.doll.findCloseItem(x, y);
}
if(item) {
this.handAction(x, y, isHolding, item);
var message = {
handActionResponse: {
playerId: this.id,
isHolding: isHolding,
itemUid: item.uid,
x: x,
y: y
}
};
NotificationCenter.trigger("sendControlCommandToAllUsers", "gameCommand", message);
}
}
return Player;
});