chuck.js/app/Game/Client/GameObjects/Items/RagDoll.js
Karl Pannek dc779def9c Complete Box2D to Planck.js migration
- Replace Box2D.js with Planck.js physics engine
- Update all require paths from 'Lib/Vendor/Box2D' to 'Lib/Vendor/Planck'
- Convert Box2D contact listeners to Planck.js event system
- Fix all method name capitalization (Get* -> get*, Set* -> set*)
- Update collision detection system for Planck.js compatibility
- Server now starts successfully and basic physics working
- Character can land on platforms - core physics functional

Major milestone: Game now running on modern, maintained physics engine
2025-07-16 15:01:59 +02:00

119 lines
No EOL
3.2 KiB
JavaScript

define([
"Game/Core/GameObjects/Items/RagDoll",
"Game/Core/GameObjects/Item",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
"Game/Client/View/Abstract/Layer"
],
function (Parent, CoreItem, Settings, nc, Layer) {
"use strict";
function RagDoll(physicsEngine, uid, options) {
this.layerId = Layer.ID.SPAWN;
this.limbMeshes = {};
this.baseMeshName = "chest";
this.characterName = "Chuck";
Parent.call(this, physicsEngine, uid, options);
}
RagDoll.prototype = Object.create(Parent.prototype);
RagDoll.prototype.createMesh = function() {
for(var name in this.options.limbs) {
this.createLimbMesh(name);
}
};
RagDoll.prototype.createLimbMesh = function(name) {
var self = this;
var texturePath = Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_CHARACTERS + '/'
+ this.characterName + '/';
var callback = function(mesh) {
if(name == self.baseMeshName) {
self.mesh = mesh;
} else {
self.limbMeshes[name] = mesh;
}
nc.trigger(nc.ns.client.view.mesh.add, self.layerId, mesh);
}
nc.trigger(nc.ns.client.view.mesh.create,
this.layerId,
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]) {
nc.trigger(nc.ns.client.view.mesh.update,
this.layerId,
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) {
nc.trigger(nc.ns.client.view.mesh.update,
this.layerId,
this.mesh,
{
xScale: direction
}
);
for (var name in this.limbMeshes) {
nc.trigger(nc.ns.client.view.mesh.update,
this.layerId,
this.limbMeshes[name],
{
xScale: direction
}
);
};
}
};
RagDoll.prototype.destroy = function() {
for (var name in this.limbMeshes) {
nc.trigger(nc.ns.client.view.mesh.remove, this.layerId, this.limbMeshes[name]);
};
Parent.prototype.destroy.call(this);
};
return RagDoll;
});