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,6 +1,6 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Vendor/Planck",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
|
@ -20,12 +20,11 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
Assert.number(this.options.width, this.options.height);
|
||||
Assert.number(this.options.weight);
|
||||
|
||||
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = 2 / Settings.RATIO;
|
||||
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO)));
|
||||
var deckShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(4.5 / Settings.RATIO)));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
|
||||
fixtureDef.shape = deckShape;
|
||||
|
||||
var offset = 4,
|
||||
|
|
@ -36,7 +35,7 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
fixtureDef.restitution = 0.2;
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
this.body.createFixture(fixtureDef);
|
||||
|
||||
|
||||
this.addWheel(
|
||||
|
|
@ -54,18 +53,16 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
Skateboard.prototype.addWheel = function(x, y) {
|
||||
Assert.number(x, y);
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = x / Settings.RATIO;
|
||||
bodyDef.position.y = y / Settings.RATIO;
|
||||
bodyDef.angle = 0;
|
||||
var bodyDef = {
|
||||
type: 'dynamic',
|
||||
position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
|
||||
angle: 0
|
||||
};
|
||||
|
||||
var wheelShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
wheelShape.SetRadius(2.5 / Settings.RATIO);
|
||||
wheelShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
||||
var wheelShape = planck.Circle(2.5 / Settings.RATIO, planck.Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
||||
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
var density = ((0.1 + offset) / 3 / 3) * factor;
|
||||
|
|
@ -75,7 +72,7 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
fixtureDef.isSensor = false;
|
||||
fixtureDef.friction = 0.0005;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
this.body.createFixture(fixtureDef);
|
||||
};
|
||||
|
||||
Skateboard.prototype.flip = function(direction) {
|
||||
|
|
@ -90,7 +87,7 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
/*
|
||||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Vendor/Planck",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
|
@ -121,12 +118,11 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
Assert.number(this.options.width, this.options.height);
|
||||
Assert.number(this.options.weight);
|
||||
|
||||
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = 1.5 / Settings.RATIO;
|
||||
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO)));
|
||||
var deckShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(4.5 / Settings.RATIO)));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
|
||||
fixtureDef.shape = deckShape;
|
||||
|
||||
var offset = 4,
|
||||
|
|
@ -137,23 +133,21 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
fixtureDef.restitution = Settings.ITEM_RESTITUTION;
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
this.body.createFixture(fixtureDef);
|
||||
};
|
||||
|
||||
Skateboard.prototype.addWheel = function(x, y) {
|
||||
Assert.number(x, y);
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = x / Settings.RATIO;
|
||||
bodyDef.position.y = y / Settings.RATIO;
|
||||
bodyDef.angle = 0;
|
||||
var bodyDef = {
|
||||
type: 'dynamic',
|
||||
position: planck.Vec2(x / Settings.RATIO, y / Settings.RATIO),
|
||||
angle: 0
|
||||
};
|
||||
|
||||
var wheelShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
wheelShape.SetRadius(1.5 / Settings.RATIO);
|
||||
wheelShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
var wheelShape = planck.Circle(1.5 / Settings.RATIO, planck.Vec2(0, 0));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
var density = ((0.1 + offset) / 3 / 3) * factor;
|
||||
|
|
@ -163,7 +157,7 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
fixtureDef.friction = 0;
|
||||
|
||||
var wheelBody = this.body.GetWorld().CreateBody(bodyDef);
|
||||
wheelBody.CreateFixture(fixtureDef);
|
||||
wheelBody.createFixture(fixtureDef);
|
||||
|
||||
//var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
||||
var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
|
||||
|
|
@ -171,7 +165,7 @@ function (Parent, Box2D, Settings, Assert) {
|
|||
|
||||
|
||||
|
||||
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter());
|
||||
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.getWorldCenter());
|
||||
var j = this.body.GetWorld().CreateJoint(revoluteJointDef);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue