mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
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
This commit is contained in:
parent
875abd60d9
commit
dc779def9c
43 changed files with 701 additions and 14524 deletions
|
|
@ -1,56 +1,52 @@
|
|||
define([
|
||||
"Lib/Vendor/Box2D"
|
||||
"Lib/Vendor/Planck"
|
||||
],
|
||||
|
||||
function (Box2D) {
|
||||
function (Planck) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function Detector () {
|
||||
this.listener = new Box2D.Dynamics.b2ContactListener();
|
||||
this.listener.BeginContact = this.beginContact.bind(this);
|
||||
//this.listener.PostSolve = this.postSolve.bind(this);
|
||||
this.listener.EndContact = this.endContact.bind(this);
|
||||
// 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 () {
|
||||
return this.listener;
|
||||
// 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.onCollisionChange = function (point, isColliding) {
|
||||
var userDataA = point.GetFixtureA().GetUserData();
|
||||
var userDataB = point.GetFixtureB().GetUserData();
|
||||
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, point.GetFixtureB());
|
||||
userDataA.onCollisionChange(isColliding, contact.getFixtureB());
|
||||
}
|
||||
|
||||
if (userDataB && userDataB.onCollisionChange) {
|
||||
userDataB.onCollisionChange(isColliding, point.GetFixtureA());
|
||||
userDataB.onCollisionChange(isColliding, contact.getFixtureA());
|
||||
}
|
||||
}
|
||||
|
||||
/** Extension **/
|
||||
|
||||
Detector.prototype.beginContact = function (point) {
|
||||
this.onCollisionChange(point, true);
|
||||
Detector.prototype.beginContact = function (contact) {
|
||||
this.onCollisionChange(contact, true);
|
||||
}
|
||||
|
||||
/*
|
||||
Detector.prototype.postSolve = function (point, impulse) {
|
||||
var userDataA = point.GetFixtureA().GetUserData();
|
||||
var userDataB = point.GetFixtureB().GetUserData();
|
||||
|
||||
if (userDataA && userDataA.onImpulse) {
|
||||
userDataA.onImpulse(impulse, point.GetFixtureB());
|
||||
} else if (userDataB && userDataB.onImpulse) {
|
||||
userDataB.onImpulse(impulse, point.GetFixtureA());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Detector.prototype.endContact = function (point) {
|
||||
this.onCollisionChange(point, false);
|
||||
Detector.prototype.endContact = function (contact) {
|
||||
this.onCollisionChange(contact, false);
|
||||
}
|
||||
|
||||
return Detector;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue