chuck.js/app/Game/Core/Collision/Detector.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

53 lines
No EOL
1.5 KiB
JavaScript
Executable file

define([
"Lib/Vendor/Planck"
],
function (Planck) {
"use strict";
function Detector () {
// In Planck.js, contact listeners are handled via world events
// We'll store the world reference when getListener is called
this.world = null;
}
Detector.prototype.getListener = function () {
// Instead of returning a listener object, we return a function
// that will set up the event listeners on the world
return this.setupWorldEvents.bind(this);
}
Detector.prototype.setupWorldEvents = function (world) {
this.world = world;
// Set up Planck.js event listeners
world.on('begin-contact', this.beginContact.bind(this));
world.on('end-contact', this.endContact.bind(this));
return this;
}
Detector.prototype.onCollisionChange = function (contact, isColliding) {
var userDataA = contact.getFixtureA().getUserData();
var userDataB = contact.getFixtureB().getUserData();
if (userDataA && userDataA.onCollisionChange) {
userDataA.onCollisionChange(isColliding, contact.getFixtureB());
}
if (userDataB && userDataB.onCollisionChange) {
userDataB.onCollisionChange(isColliding, contact.getFixtureA());
}
}
Detector.prototype.beginContact = function (contact) {
this.onCollisionChange(contact, true);
}
Detector.prototype.endContact = function (contact) {
this.onCollisionChange(contact, false);
}
return Detector;
});