chuck.js/app/Game/Core/GameObjects/GameObject.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

63 lines
No EOL
1.6 KiB
JavaScript
Executable file

define([
"Lib/Vendor/Planck",
"Lib/Utilities/Exception",
"Lib/Utilities/Assert",
"Lib/Utilities/NotificationCenter"
],
function (planck, Exception, Assert, nc) {
"use strict";
function GameObject(physicsEngine, uid) {
this.uid = uid;
var def = this.getBodyDef();
def.userData = this;
this.body = physicsEngine.createBody(def);
this.ncTokens = (this.ncTokens || []).concat([
nc.on(nc.ns.client.game.events.destroy, this.destroy, this)
]);
}
GameObject.prototype.getBodyDef = function() {
throw new Exception('Abstract method GameObject.getBodyDef not overwritten');
};
GameObject.prototype.destroy = function() {
if(this.body) {
this.body.getWorld().destroyBody(this.body);
} else {
throw new Exception("can not destroy body");
}
nc.off(this.ncTokens);
};
GameObject.prototype.getBody = function() {
return this.body;
};
GameObject.prototype.getPosition = function() {
return this.body.getPosition().clone();
};
GameObject.prototype.setUpdateData = function(update) {
Assert.number(update.p.x, update.p.y);
Assert.number(update.a);
Assert.number(update.lv.x, update.lv.y);
Assert.number(update.av);
this.body.setAwake(true);
this.body.setPosition(update.p);
this.body.setAngle(update.a);
this.body.setLinearVelocity(update.lv);
this.body.setAngularVelocity(update.av);
};
return GameObject;
});