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

@ -37,7 +37,7 @@ function (Parent, DomController, Settings, NotificationCenter) {
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1;
var y = (((Settings.STAGE_HEIGHT - (e.clientY - this.offsetTop)) / Settings.STAGE_HEIGHT) * 2) -1;
NotificationCenter.trigger("input/onHandAction", x, y);
NotificationCenter.trigger("input/onHandActionRequest", x, y);
}
};

View file

@ -15,7 +15,7 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
this.xyInput = new MouseInput(this);
NotificationCenter.on("input/onXyChange", this.setXY, this);
NotificationCenter.on("input/onHandAction", this.handAction, this);
NotificationCenter.on("input/onHandActionRequest", this.handActionRequest, this);
var keys = {
w:87,
@ -75,12 +75,10 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
};
PlayerController.prototype.handAction = function(x, y) {
PlayerController.prototype.handActionRequest = function(x, y) {
var options = {x:x, y:y};
Parent.prototype.handAction.call(this, options);
NotificationCenter.trigger("sendGameCommand", "handAction", options);
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
};
return PlayerController;
});

View file

@ -93,6 +93,21 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
this.gameObjects.animated.push(player.getDoll());
}
GameController.prototype.onHandActionResponse = function(options) {
var player = this.players[options.playerId];
var item = null;
for (var i = 0; i < this.gameObjects.animated.length; i++) {
var currentItem = this.gameObjects.animated[i];
if(currentItem.uid == options.itemUid) {
item = currentItem;
break;
}
};
player.handAction(options.x, options.y, options.isHolding, item);
};
GameController.prototype.loadLevel = function (path) {
Parent.prototype.loadLevel.call(this, path);
}

View file

@ -7,7 +7,7 @@ define([
function (Parent, Settings, NotificationCenter, Exception) {
function Doll(physicsEngine, playerId) {
function Doll(physicsEngine, uid, player) {
this.animationDef = {
"stand": [1,1],
"walk": [2,28],
@ -23,7 +23,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
this.animatedMeshes = {};
this.headMesh = null;
Parent.call(this, physicsEngine, playerId);
Parent.call(this, physicsEngine, uid, player);
}
Doll.prototype = Object.create(Parent.prototype);

View file

@ -27,6 +27,8 @@ define({
FLY_SPEED: 6.2,
JUMP_SPEED: 20,
MAX_THROW_FORCE: 18,
MAX_THROW_ANGULAR_VELOCITY: 8,
MAX_RUNNING_WEIGHT: 9,
// restitution: bouncyness, friction: rubbing, density: mass
TILE_FRICTION: 0.99,

View file

@ -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);

View file

@ -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) {

View file

@ -12,6 +12,7 @@ function (Parent, Box2D, Settings) {
this.createFixture();
this.body.ResetMassData();
this.flipDirection = 1;
this.heldByPlayers = [];
}
Item.prototype = Object.create(Parent.prototype);
@ -68,6 +69,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;
});

View file

@ -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,16 +52,20 @@ 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);
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) {
if(item.isGrabbingAllowed()) {
item.beingGrabbed(this);
this.doll.grab(item);
this.holdingItem = item;
}
}

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) {
return Parent;
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
}
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;
});