added ragdoll with one limb

This commit is contained in:
Jeena 2014-02-12 00:30:09 +01:00
parent b55f6d58fc
commit e488beb203
18 changed files with 511 additions and 132 deletions

View file

@ -23,6 +23,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
s:83,
d:68,
f:70,
g:71,
up: 38,
left: 37,
down: 40,
@ -51,6 +54,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
this.keyboardInput.registerKey(keys.space, 'jump');
this.keyboardInput.registerKey(keys.tab, 'showInfo', 'hideInfo');
this.keyboardInput.registerKey(keys.f, 'handActionLeft');
this.keyboardInput.registerKey(keys.g, 'handActionRight');
}
PlayerController.prototype.moveLeft = function () {
@ -79,6 +85,14 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
};
PlayerController.prototype.handActionLeft = function() {
this.handActionRequest(-0.5, 0.5);
};
PlayerController.prototype.handActionRight = function() {
this.handActionRequest(0.5, 0.5);
};
PlayerController.prototype.handActionRequest = function(x, y) {
var options = {x:x, y:y};
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);

View file

@ -71,7 +71,10 @@ function (Parent, Settings, NotificationCenter, Exception) {
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, {
visible: false,
pivot: "mb",
pivot: {
x: 35/2,
y: 40
},
width: 35,
height: 40
});
@ -85,7 +88,10 @@ function (Parent, Settings, NotificationCenter, Exception) {
NotificationCenter.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh", texturePath, callback, {
pivot: "mb",
pivot: {
x: 5,
y: 12
},
width: 10,
height: 12
});

View file

@ -31,7 +31,10 @@ function (Parent, Settings, NotificationCenter) {
{
width: this.options.width,
height: this.options.height,
pivot: "mb"
pivot: {
x: this.options.width / 2,
y: this.options.height
}
}
);
};

View file

@ -0,0 +1,104 @@
define([
"Game/Core/GameObjects/Items/RagDoll",
"Game/Core/GameObjects/Item",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
],
function (Parent, CoreItem, Settings, NotificationCenter) {
function RagDoll(physicsEngine, uid, options) {
this.limbMeshes = {};
this.baseMeshName = "chest";
this.characterName = "Chuck";
Parent.call(this, physicsEngine, uid, options);
}
RagDoll.prototype = Object.create(Parent.prototype);
RagDoll.prototype.createMesh = function() {
this.createLimbMesh("chest");
this.createLimbMesh("head");
};
RagDoll.prototype.createLimbMesh = function(name) {
var self = this;
var texturePath = Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_CHARACTERS + '/'
+ this.characterName + '/';
var callback = function(mesh) {
console.log(name, self.baseMeshName)
if(name == self.baseMeshName) {
self.mesh = mesh;
} else {
self.limbMeshes[name] = mesh;
}
NotificationCenter.trigger("view/addMesh", mesh);
}
NotificationCenter.trigger("view/createMesh",
texturePath + name + ".png",
callback,
{
width: this.options.limbs[name].width,
height: this.options.limbs[name].height,
pivot: {
x: this.options.limbs[name].width / 2,
y: this.options.limbs[name].height / 2
}
}
);
};
RagDoll.prototype.render = function() {
Parent.prototype.render.call(this);
if(this.limbs) {
for(var name in this.limbMeshes) {
if(this.limbs[name]) {
NotificationCenter.trigger("view/updateMesh",
this.limbMeshes[name],
{
x: this.limbs[name].GetPosition().x * Settings.RATIO,
y: this.limbs[name].GetPosition().y * Settings.RATIO,
rotation: this.limbs[name].GetAngle()
}
);
}
}
}
}
RagDoll.prototype.flip = function(direction) {
var oldFlipDirection = this.flipDirection;
// Parent of parent
CoreItem.prototype.flip.call(this, direction);
if(oldFlipDirection != direction) {
NotificationCenter.trigger("view/updateMesh",
this.mesh,
{
xScale: direction
}
);
for (var name in this.limbMeshes) {
NotificationCenter.trigger("view/updateMesh",
this.limbMeshes[name],
{
xScale: direction
}
);
};
}
};
return RagDoll;
});

View file

@ -35,7 +35,11 @@ function (Parent, Settings, NotificationCenter) {
callback,
{
width: Settings.TILE_SIZE,
height: Settings.TILE_SIZE
height: Settings.TILE_SIZE,
pivot: {
x: Settings.TILE_SIZE / 2 * Settings.TILE_RATIO,
y: Settings.TILE_SIZE / 2 * Settings.TILE_RATIO
}
}
);
};
@ -50,8 +54,8 @@ function (Parent, Settings, NotificationCenter) {
NotificationCenter.trigger("view/updateMesh",
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO - Settings.TILE_SIZE / 2,
y: this.body.GetPosition().y * Settings.RATIO - Settings.TILE_SIZE / 2
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO
}
);
}

View file

@ -121,26 +121,12 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
if (options.x) mesh.position.x = options.x;
if (options.y) mesh.position.y = options.y;
if (options.rotation) mesh.rotation = options.rotation;
if (options.xScale) mesh.scale.x = options.xScale;
if (options.yScale) mesh.scale.y = options.yScale;
if (options.width) mesh.width = options.width;
if (options.height) mesh.height = options.height;
if (options.xScale) mesh.width = Math.abs(mesh.width) * options.xScale;
if (options.yScale) mesh.scale.y = options.yScale;
if (options.visible === true || options.visible === false) mesh.visible = options.visible;
if (options.pivot) {
if(options.pivot.length) {
switch(options.pivot) {
case "lb":
mesh.pivot.x = mesh.width / 2;
mesh.pivot.y = mesh.height / 2;
break;
default:
mesh.pivot.x = mesh.width / 2;
mesh.pivot.y = mesh.height;
break;
}
}
};
if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y);
}
PixiView.prototype.calculateCameraPosition = function() {