diff --git a/app/Game/Client/GameObjects/Doll.js b/app/Game/Client/GameObjects/Doll.js index 7671555..288513c 100755 --- a/app/Game/Client/GameObjects/Doll.js +++ b/app/Game/Client/GameObjects/Doll.js @@ -20,27 +20,49 @@ function (Parent, Settings, Nc, Exception) { "run": [104,126] } - this.animatedMeshes = {}; + this.animatedMeshesContainer = { + withArms: {}, + withoutArms: {} + }; + this.animatedMeshes = this.animatedMeshesContainer.withArms; this.headMesh = null; + this.holdingArmMesh = null; Parent.call(this, physicsEngine, uid, player); } 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(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); - 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() { @@ -55,38 +77,42 @@ function (Parent, Settings, Nc, Exception) { var self = this; - for (var key in this.animationDef) { - var start = this.animationDef[key][0]; - var end = this.animationDef[key][1]; + var arms = ["withArms", "withoutArms"]; + for (var j = 0; j < arms.length; j++) { + var arm = arms[j]; + for (var key in this.animationDef) { + var start = this.animationDef[key][0]; + var end = this.animationDef[key][1]; - var texturePaths = []; - for (var i = start; i <= end; i++) { - texturePaths.push( - Settings.GRAPHICS_PATH - + Settings.GRAPHICS_SUBPATH_CHARACTERS - + this.characterName - //+ "/Animation/WithoutArms/ChuckAnimationsWithoutArms0" - + "/Animation/WithArms/ChuckAnimations0" - + padF(i) - + ".png" - ); + var texturePaths = []; + for (var i = start; i <= end; i++) { + texturePaths.push( + Settings.GRAPHICS_PATH + + Settings.GRAPHICS_SUBPATH_CHARACTERS + + this.characterName + + "/Animation/" + arm.toUpperCaseFirstChar() + "/ChuckAnimations0" + + padF(i) + + ".png" + ); + } + + var callback = function(mesh) { + self.animatedMeshesContainer[arm][key] = mesh; + Nc.trigger(Nc.ns.client.view.mesh.add, mesh); + }; + + Nc.trigger(Nc.ns.client.view.animatedMesh.create, texturePaths, callback, { + visible: false, + pivot: { + x: 35/2 * 4, + y: 40 * 4 + }, + width: 35, + height: 40 + }); } - var callback = function(mesh) { - self.animatedMeshes[key] = mesh; - Nc.trigger(Nc.ns.client.view.mesh.add, mesh); - }; - - Nc.trigger(Nc.ns.client.view.animatedMesh.create, texturePaths, callback, { - visible: false, - pivot: { - x: 35/2 * 4, - y: 40 * 4 - }, - width: 35, - height: 40 - }); - } + }; // Head @@ -104,6 +130,21 @@ function (Parent, Settings, Nc, Exception) { 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) { @@ -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° @@ -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 () { for (var key in this.animatedMeshes) { @@ -151,7 +212,7 @@ function (Parent, Settings, Nc, Exception) { { x: this.body.GetPosition().x * 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 } ) + + Nc.trigger(Nc.ns.client.view.mesh.update, + this.holdingArmMesh, + { + x: this.body.GetPosition().x * Settings.RATIO, + y: this.body.GetPosition().y * Settings.RATIO + } + ) } } diff --git a/app/Game/Client/Loader/Level.js b/app/Game/Client/Loader/Level.js index f732196..72543b5 100755 --- a/app/Game/Client/Loader/Level.js +++ b/app/Game/Client/Loader/Level.js @@ -56,21 +56,20 @@ function (Parent, Settings, Nc, PIXI) { } var characterNames = ["Chuck"]; - var animationSets = ["WithArms"];//, "WithArms"]; + var animationSets = ["WithArms", "WithoutArms"]; var addition = ""; for (var i = 0; i < characterNames.length; i++) { var characterName = characterNames[i]; for (var j = 1; j <= 126; j++) { for (var k = 0; k < animationSets.length; k++) { var animationSet = animationSets[k]; - addition = animationSet == "WithoutArms" ? "WithoutArms" : ""; paths.push( Settings.GRAPHICS_PATH + Settings.GRAPHICS_SUBPATH_CHARACTERS + characterName + "/Animation/" + animationSet - + "/ChuckAnimations" + addition + "0" + + "/ChuckAnimations0" + padF(j) + ".png" ); diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 1847956..5863019 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -340,7 +340,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) { var bodyPosition = this.body.GetPosition(); var handPosition = new Box2D.Common.Math.b2Vec2( 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);