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
|
|
@ -37,7 +37,7 @@ function (Parent, DomController, Settings, NotificationCenter) {
|
||||||
var x = (((e.clientX - this.offsetLeft) / Settings.STAGE_WIDTH) * 2) - 1;
|
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;
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
||||||
this.xyInput = new MouseInput(this);
|
this.xyInput = new MouseInput(this);
|
||||||
|
|
||||||
NotificationCenter.on("input/onXyChange", this.setXY, this);
|
NotificationCenter.on("input/onXyChange", this.setXY, this);
|
||||||
NotificationCenter.on("input/onHandAction", this.handAction, this);
|
NotificationCenter.on("input/onHandActionRequest", this.handActionRequest, this);
|
||||||
|
|
||||||
var keys = {
|
var keys = {
|
||||||
w:87,
|
w:87,
|
||||||
|
|
@ -75,12 +75,10 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
||||||
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
|
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerController.prototype.handAction = function(x, y) {
|
PlayerController.prototype.handActionRequest = function(x, y) {
|
||||||
var options = {x:x, y:y};
|
var options = {x:x, y:y};
|
||||||
Parent.prototype.handAction.call(this, options);
|
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
|
||||||
NotificationCenter.trigger("sendGameCommand", "handAction", options);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
return PlayerController;
|
return PlayerController;
|
||||||
});
|
});
|
||||||
|
|
@ -93,6 +93,21 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
||||||
this.gameObjects.animated.push(player.getDoll());
|
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) {
|
GameController.prototype.loadLevel = function (path) {
|
||||||
Parent.prototype.loadLevel.call(this, path);
|
Parent.prototype.loadLevel.call(this, path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ define([
|
||||||
|
|
||||||
function (Parent, Settings, NotificationCenter, Exception) {
|
function (Parent, Settings, NotificationCenter, Exception) {
|
||||||
|
|
||||||
function Doll(physicsEngine, playerId) {
|
function Doll(physicsEngine, uid, player) {
|
||||||
this.animationDef = {
|
this.animationDef = {
|
||||||
"stand": [1,1],
|
"stand": [1,1],
|
||||||
"walk": [2,28],
|
"walk": [2,28],
|
||||||
|
|
@ -23,7 +23,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
||||||
this.animatedMeshes = {};
|
this.animatedMeshes = {};
|
||||||
this.headMesh = null;
|
this.headMesh = null;
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, playerId);
|
Parent.call(this, physicsEngine, uid, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype = Object.create(Parent.prototype);
|
Doll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ define({
|
||||||
FLY_SPEED: 6.2,
|
FLY_SPEED: 6.2,
|
||||||
JUMP_SPEED: 20,
|
JUMP_SPEED: 20,
|
||||||
MAX_THROW_FORCE: 18,
|
MAX_THROW_FORCE: 18,
|
||||||
|
MAX_THROW_ANGULAR_VELOCITY: 8,
|
||||||
|
MAX_RUNNING_WEIGHT: 9,
|
||||||
|
|
||||||
// restitution: bouncyness, friction: rubbing, density: mass
|
// restitution: bouncyness, friction: rubbing, density: mass
|
||||||
TILE_FRICTION: 0.99,
|
TILE_FRICTION: 0.99,
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,6 @@ define(function () {
|
||||||
if(options) this.player.lookAt(options.x, options.y);
|
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 () {
|
PlayerController.prototype.update = function () {
|
||||||
if(this._walkingDirectionStatus != 0) {
|
if(this._walkingDirectionStatus != 0) {
|
||||||
this.player.move(this._walkingDirectionStatus);
|
this.player.move(this._walkingDirectionStatus);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ define([
|
||||||
|
|
||||||
function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
|
|
||||||
function Doll (physicsEngine, uid) {
|
function Doll (physicsEngine, uid, player) {
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
this.height = 43;
|
this.height = 43;
|
||||||
this.width = 9;
|
this.width = 9;
|
||||||
this.headHeight = 12;
|
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;
|
var item = null;
|
||||||
if (this.lookDirection == -1) {
|
if (this.lookDirection == -1) {
|
||||||
item = this.reachableItems.left.shift();
|
item = this.reachableItems.left.shift();
|
||||||
|
|
@ -272,6 +280,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.positionHoldingItem = function() {
|
Doll.prototype.positionHoldingItem = function() {
|
||||||
|
|
@ -312,7 +321,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
),
|
),
|
||||||
body.GetLocalCenter()
|
body.GetLocalCenter()
|
||||||
);
|
);
|
||||||
body.SetAngularVelocity(8 * x);
|
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x); //
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ function (Parent, Box2D, Settings) {
|
||||||
this.createFixture();
|
this.createFixture();
|
||||||
this.body.ResetMassData();
|
this.body.ResetMassData();
|
||||||
this.flipDirection = 1;
|
this.flipDirection = 1;
|
||||||
|
this.heldByPlayers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.prototype = Object.create(Parent.prototype);
|
Item.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -67,6 +68,31 @@ function (Parent, Box2D, Settings) {
|
||||||
|
|
||||||
// FIXME: implement body flip if necessary
|
// 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;
|
return Item;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ function (Doll, Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.spawn = function (x, y) {
|
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.doll.spawn(x, y);
|
||||||
this.isSpawned = true;
|
this.isSpawned = true;
|
||||||
}
|
}
|
||||||
|
|
@ -52,17 +52,21 @@ function (Doll, Settings) {
|
||||||
if(this.doll) this.doll.lookAt(x, y);
|
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
|
// throw
|
||||||
this.doll.throw(this.holdingItem, x, y);
|
if(item.isReleasingAllowed()) {
|
||||||
this.holdingItem = null;
|
item.beingReleased(this);
|
||||||
|
this.doll.throw(item, x, y);
|
||||||
|
this.holdingItem = null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// take
|
// take
|
||||||
var item = this.doll.grab(x, y);
|
if(item.isGrabbingAllowed()) {
|
||||||
if(item) {
|
item.beingGrabbed(this);
|
||||||
this.holdingItem = item;
|
this.doll.grab(item);
|
||||||
|
this.holdingItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ function(Parent, NotificationCenter, Parser) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PlayerController.prototype.handActionRequest = function(options) {
|
||||||
|
if (options) this.player.handActionRequest(options.x, options.y);
|
||||||
|
};
|
||||||
|
|
||||||
return PlayerController;
|
return PlayerController;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -2,8 +2,32 @@ define([
|
||||||
"Game/Core/GameObjects/Doll"
|
"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;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -1,9 +1,45 @@
|
||||||
define([
|
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;
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue