mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
implemented holding arm. fixes #75
This commit is contained in:
parent
03cb005372
commit
ebf167107a
3 changed files with 107 additions and 39 deletions
|
|
@ -20,27 +20,49 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
"run": [104,126]
|
"run": [104,126]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.animatedMeshes = {};
|
this.animatedMeshesContainer = {
|
||||||
|
withArms: {},
|
||||||
|
withoutArms: {}
|
||||||
|
};
|
||||||
|
this.animatedMeshes = this.animatedMeshesContainer.withArms;
|
||||||
this.headMesh = null;
|
this.headMesh = null;
|
||||||
|
this.holdingArmMesh = null;
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, uid, player);
|
Parent.call(this, physicsEngine, uid, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype = Object.create(Parent.prototype);
|
Doll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
Doll.prototype.setActionState = function(state) {
|
Doll.prototype.setActionState = function(state, force) {
|
||||||
|
|
||||||
if(this.actionState == state) return;
|
if(!force && this.actionState == state) return;
|
||||||
|
console.log(state)
|
||||||
|
|
||||||
if(!state) throw new Exception("action state is undefined");
|
if(!state) throw new Exception("action state is undefined");
|
||||||
|
|
||||||
if(this.animatedMeshes[this.actionState]) {
|
if(this.animatedMeshes[this.actionState]) {
|
||||||
Nc.trigger(Nc.ns.client.view.mesh.update, this.animatedMeshes[this.actionState], { visible: false });
|
Nc.trigger(
|
||||||
|
Nc.ns.client.view.mesh.update,
|
||||||
|
this.animatedMeshesContainer.withArms[this.actionState],
|
||||||
|
{ visible: false }
|
||||||
|
);
|
||||||
|
Nc.trigger(
|
||||||
|
Nc.ns.client.view.mesh.update,
|
||||||
|
this.animatedMeshesContainer.withoutArms[this.actionState],
|
||||||
|
{ visible: false }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parent.prototype.setActionState.call(this, state);
|
Parent.prototype.setActionState.call(this, state);
|
||||||
|
|
||||||
Nc.trigger(Nc.ns.client.view.mesh.update, this.animatedMeshes[this.actionState], { visible: true });
|
Nc.trigger(
|
||||||
|
Nc.ns.client.view.mesh.update,
|
||||||
|
this.animatedMeshes[this.actionState],
|
||||||
|
{
|
||||||
|
visible: true,
|
||||||
|
xScale: this.lookDirection
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.createMesh = function() {
|
Doll.prototype.createMesh = function() {
|
||||||
|
|
@ -55,6 +77,9 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
var arms = ["withArms", "withoutArms"];
|
||||||
|
for (var j = 0; j < arms.length; j++) {
|
||||||
|
var arm = arms[j];
|
||||||
for (var key in this.animationDef) {
|
for (var key in this.animationDef) {
|
||||||
var start = this.animationDef[key][0];
|
var start = this.animationDef[key][0];
|
||||||
var end = this.animationDef[key][1];
|
var end = this.animationDef[key][1];
|
||||||
|
|
@ -65,15 +90,14 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
Settings.GRAPHICS_PATH
|
Settings.GRAPHICS_PATH
|
||||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||||
+ this.characterName
|
+ this.characterName
|
||||||
//+ "/Animation/WithoutArms/ChuckAnimationsWithoutArms0"
|
+ "/Animation/" + arm.toUpperCaseFirstChar() + "/ChuckAnimations0"
|
||||||
+ "/Animation/WithArms/ChuckAnimations0"
|
|
||||||
+ padF(i)
|
+ padF(i)
|
||||||
+ ".png"
|
+ ".png"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var callback = function(mesh) {
|
var callback = function(mesh) {
|
||||||
self.animatedMeshes[key] = mesh;
|
self.animatedMeshesContainer[arm][key] = mesh;
|
||||||
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
|
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -88,6 +112,8 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// Head
|
// Head
|
||||||
|
|
||||||
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
|
var texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/head.png";
|
||||||
|
|
@ -104,6 +130,21 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
height: 12
|
height: 12
|
||||||
});
|
});
|
||||||
|
|
||||||
|
texturePath = Settings.GRAPHICS_PATH + "Characters/Chuck/holdingArm.png";
|
||||||
|
var callback = function (mesh) {
|
||||||
|
self.holdingArmMesh = mesh;
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.add, mesh);
|
||||||
|
}
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.create, texturePath, callback, {
|
||||||
|
visible: false,
|
||||||
|
pivot: {
|
||||||
|
x: 35/2 * 4,
|
||||||
|
y: 40 * 4
|
||||||
|
},
|
||||||
|
width: 35,
|
||||||
|
height: 40
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.lookAt = function(x, y) {
|
Doll.prototype.lookAt = function(x, y) {
|
||||||
|
|
@ -120,6 +161,13 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.update,
|
||||||
|
this.holdingArmMesh,
|
||||||
|
{
|
||||||
|
xScale: this.lookDirection
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
|
var angle = Math.atan2(this.lookAtXY.x, this.lookAtXY.y) / 2 - 0.7855 * this.lookDirection; // 0.7855 = 45°
|
||||||
|
|
@ -133,6 +181,19 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Doll.prototype.grab = function(item) {
|
||||||
|
Parent.prototype.grab.call(this, item);
|
||||||
|
this.animatedMeshes = this.animatedMeshesContainer.withoutArms;
|
||||||
|
this.setActionState(this.actionState, true);
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.throw = function(item, x, y) {
|
||||||
|
Parent.prototype.throw.call(this, item, x, y);
|
||||||
|
this.animatedMeshes = this.animatedMeshesContainer.withArms;
|
||||||
|
this.setActionState(this.actionState, true);
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.update, this.holdingArmMesh, { visible: false });
|
||||||
|
};
|
||||||
|
|
||||||
Doll.prototype.destroy = function () {
|
Doll.prototype.destroy = function () {
|
||||||
for (var key in this.animatedMeshes) {
|
for (var key in this.animatedMeshes) {
|
||||||
|
|
@ -151,7 +212,7 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
{
|
{
|
||||||
x: this.body.GetPosition().x * Settings.RATIO,
|
x: this.body.GetPosition().x * Settings.RATIO,
|
||||||
y: this.body.GetPosition().y * Settings.RATIO,
|
y: this.body.GetPosition().y * Settings.RATIO,
|
||||||
rotation: this.body.GetAngle()
|
//rotation: this.body.GetAngle()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -162,6 +223,14 @@ function (Parent, Settings, Nc, Exception) {
|
||||||
y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight
|
y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.update,
|
||||||
|
this.holdingArmMesh,
|
||||||
|
{
|
||||||
|
x: this.body.GetPosition().x * Settings.RATIO,
|
||||||
|
y: this.body.GetPosition().y * Settings.RATIO
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,21 +56,20 @@ function (Parent, Settings, Nc, PIXI) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var characterNames = ["Chuck"];
|
var characterNames = ["Chuck"];
|
||||||
var animationSets = ["WithArms"];//, "WithArms"];
|
var animationSets = ["WithArms", "WithoutArms"];
|
||||||
var addition = "";
|
var addition = "";
|
||||||
for (var i = 0; i < characterNames.length; i++) {
|
for (var i = 0; i < characterNames.length; i++) {
|
||||||
var characterName = characterNames[i];
|
var characterName = characterNames[i];
|
||||||
for (var j = 1; j <= 126; j++) {
|
for (var j = 1; j <= 126; j++) {
|
||||||
for (var k = 0; k < animationSets.length; k++) {
|
for (var k = 0; k < animationSets.length; k++) {
|
||||||
var animationSet = animationSets[k];
|
var animationSet = animationSets[k];
|
||||||
addition = animationSet == "WithoutArms" ? "WithoutArms" : "";
|
|
||||||
paths.push(
|
paths.push(
|
||||||
Settings.GRAPHICS_PATH
|
Settings.GRAPHICS_PATH
|
||||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||||
+ characterName
|
+ characterName
|
||||||
+ "/Animation/"
|
+ "/Animation/"
|
||||||
+ animationSet
|
+ animationSet
|
||||||
+ "/ChuckAnimations" + addition + "0"
|
+ "/ChuckAnimations0"
|
||||||
+ padF(j)
|
+ padF(j)
|
||||||
+ ".png"
|
+ ".png"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
||||||
var bodyPosition = this.body.GetPosition();
|
var bodyPosition = this.body.GetPosition();
|
||||||
var handPosition = new Box2D.Common.Math.b2Vec2(
|
var handPosition = new Box2D.Common.Math.b2Vec2(
|
||||||
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
|
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||||
bodyPosition.y - this.height / 3 * 2 / Settings.RATIO // 2/3 of the body height
|
bodyPosition.y - this.height / 4 * 2 / Settings.RATIO // 2/3 of the body height
|
||||||
);
|
);
|
||||||
|
|
||||||
this.holdingItem.reposition(handPosition, this.lookDirection);
|
this.holdingItem.reposition(handPosition, this.lookDirection);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue