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

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