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:
Karl Pannek 2025-07-16 15:01:59 +02:00
parent 875abd60d9
commit dc779def9c
43 changed files with 701 additions and 14524 deletions

View file

@ -53,8 +53,8 @@ function(Parent, nc, Parser, Settings) {
}
var difference = {
x: Math.abs(update.p.x - this.player.doll.body.GetPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
x: Math.abs(update.p.x - this.player.doll.body.getPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.getPosition().y)
};
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
@ -67,8 +67,8 @@ function(Parent, nc, Parser, Settings) {
var body = this.player.doll.body;
var options = {
p: body.GetPosition(),
lv: body.GetLinearVelocity()
p: body.getPosition(),
lv: body.getLinearVelocity()
};
nc.trigger(nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options);

View file

@ -4,7 +4,7 @@ define([
"Game/Config/Settings",
"Lib/Utilities/RequestAnimFrame",
"Lib/Utilities/NotificationCenter",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Game/Channel/Player",
"Game/Channel/GameObjects/GameObject",
"Game/Channel/GameObjects/Doll",
@ -131,8 +131,8 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, nc, Box2D, Player,
/*
var body = this.physicsEngine.world.GetBodyList();
do {
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) {
var userData = body.GetUserData();
if((getSleeping || body.isAwake()) && body.getType() === 'dynamic') {
var userData = body.getUserData();
if (userData instanceof GameObject) {
var gameObject = userData;

View file

@ -1,7 +1,7 @@
define([
"Game/Core/GameObjects/Doll",
"Game/Channel/GameObjects/Item",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert"
],
@ -42,14 +42,14 @@ function (Parent, Item, Box2D, nc, Assert) {
Parent.prototype.onImpact.call(this, isColliding, fixture);
if(isColliding) {
var otherBody = fixture.GetBody();
var otherBody = fixture.getBody();
if(otherBody) {
var item = otherBody.GetUserData();
var item = otherBody.getUserData();
if(item instanceof Item) {
var itemVelocity = item.body.GetLinearVelocity();
//var itemMass = item.body.GetMass();
var itemVelocity = item.body.getLinearVelocity();
//var itemMass = item.body.getMass();
var ownVelocity = this.body.GetLinearVelocity();
var ownVelocity = this.body.getLinearVelocity();
var b2Math = Box2D.Common.Math.b2Math;
var absItemVelocity = b2Math.AbsV(itemVelocity);
@ -97,9 +97,9 @@ function (Parent, Item, Box2D, nc, Assert) {
if(!this.isAnotherPlayerNearby()) {
Assert.number(update.p.x, update.p.y);
Assert.number(update.lv.x, update.lv.y);
this.body.SetAwake(true);
this.body.SetPosition(update.p);
this.body.SetLinearVelocity(update.lv);
this.body.setAwake(true);
this.body.setPosition(update.p);
this.body.setLinearVelocity(update.lv);
}
};

View file

@ -1,6 +1,6 @@
define([
"Game/Core/GameObjects/GameObject",
"Lib/Vendor/Box2D"
"Lib/Vendor/Planck"
],
function (Parent, Box2D) {
@ -19,19 +19,19 @@ function (Parent, Box2D) {
return null;
}
if (this.body.GetType() === Box2D.Dynamics.b2Body.b2_staticBody) {
if (this.body.getType() === 'static') {
return null;
}
if (!getSleeping && !this.body.IsAwake()) {
if (!getSleeping && !this.body.isAwake()) {
return null;
}
return {
p: this.body.GetPosition(),
a: this.body.GetAngle(),
lv: this.body.GetLinearVelocity(),
av: this.body.GetAngularVelocity()
p: this.body.getPosition(),
a: this.body.getAngle(),
lv: this.body.getLinearVelocity(),
av: this.body.getAngularVelocity()
};
}

View file

@ -74,9 +74,9 @@ function (Parent, nc) {
Item.prototype.onCollisionChange = function(isColliding, fixture) {
if(isColliding) {
var otherBody = fixture.GetBody();
var otherBody = fixture.getBody();
if(otherBody) {
var otherItem = otherBody.GetUserData();
var otherItem = otherBody.getUserData();
if(otherItem instanceof Item) {
if(!this.lastMoved && !otherItem.lastMoved) return;

View file

@ -56,10 +56,10 @@ function (Parent, Settings, nc) {
for(var name in this.limbs) {
limbUpdateData[name] = {
p: this.limbs[name].GetPosition(),
a: this.limbs[name].GetAngle(),
lv: this.limbs[name].GetLinearVelocity(),
av: this.limbs[name].GetAngularVelocity()
p: this.limbs[name].getPosition(),
a: this.limbs[name].getAngle(),
lv: this.limbs[name].getLinearVelocity(),
av: this.limbs[name].getAngularVelocity()
};
}
updateData['limbs'] = limbUpdateData;

View file

@ -1,6 +1,6 @@
define([
"Game/Core/GameController",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Game/Client/Physics/Engine",
"Game/Client/View/ViewManager",
"Game/Client/Control/PlayerController",
@ -49,6 +49,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, nc, reque
this.animationRequestId = requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
this.physicsEngine.renderDebug(); // Render Planck.js debug draw
if(this.me) {
this.me.update();

View file

@ -276,8 +276,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId,
this.animatedMeshes[this.actionState],
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO,
x: this.body.getPosition().x * Settings.RATIO,
y: this.body.getPosition().y * Settings.RATIO,
animationSpeed: factor
//rotation: this.body.GetAngle()
}
@ -287,8 +287,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId,
this.headMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight
x: this.body.getPosition().x * Settings.RATIO,
y: this.body.getPosition().y * Settings.RATIO - this.height + this.headHeight
}
)
@ -296,8 +296,8 @@ function (Parent, Settings, nc, Exception, ColorConverter, Layer) {
this.layerId,
this.holdingArmMesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO
x: this.body.getPosition().x * Settings.RATIO,
y: this.body.getPosition().y * Settings.RATIO
}
)
}

View file

@ -59,9 +59,9 @@ function (Parent, Settings, nc, Layer) {
this.layerId,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO,
rotation: this.body.GetAngle()
x: this.body.getPosition().x * Settings.RATIO,
y: this.body.getPosition().y * Settings.RATIO,
rotation: this.body.getAngle()
}
);
}

View file

@ -68,9 +68,9 @@ function (Parent, CoreItem, Settings, nc, Layer) {
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()
x: this.limbs[name].getPosition().x * Settings.RATIO,
y: this.limbs[name].getPosition().y * Settings.RATIO,
rotation: this.limbs[name].getAngle()
}
);
}

View file

@ -173,9 +173,9 @@ function (Parent, Layer, Settings, nc) {
this.layerId,
this.mesh,
{
x: this.body.GetPosition().x * Settings.RATIO,
y: this.body.GetPosition().y * Settings.RATIO,
rotation: this.body.GetAngle()
x: this.body.getPosition().x * Settings.RATIO,
y: this.body.getPosition().y * Settings.RATIO,
rotation: this.body.getAngle()
}
);
@ -186,9 +186,9 @@ function (Parent, Layer, Settings, nc) {
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()
x: this.limbs[name].getPosition().x * Settings.RATIO,
y: this.limbs[name].getPosition().y * Settings.RATIO,
rotation: this.limbs[name].getAngle()
}
);
}

View file

@ -65,8 +65,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
}
var difference = {
x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.GetPosition().x),
y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.GetPosition().y)
x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.getPosition().x),
y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.getPosition().y)
};
if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS ||
@ -78,8 +78,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
Me.prototype.getPositionStateOverride = function() {
return {
p: this.doll.body.GetPosition().Copy(),
lv: this.doll.body.GetLinearVelocity().Copy()
p: this.doll.body.getPosition().clone(),
lv: this.doll.body.getLinearVelocity().clone()
};
};
@ -91,8 +91,8 @@ function (Parent, Settings, nc, Assert, PlayerController) {
Me.prototype.resetPositionState = function(options) {
Assert.number(options.p.x, options.p.y);
Assert.number(options.lv.x, options.lv.y);
this.doll.body.SetPosition(options.p);
this.doll.body.SetLinearVelocity(options.lv);
this.doll.body.setPosition(options.p);
this.doll.body.setLinearVelocity(options.lv);
};
Me.prototype.createAndAddArrow = function() {

View file

@ -2,13 +2,13 @@ define([
"Game/Core/Physics/Engine",
"Game/Config/Settings",
"Game/Client/View/DomController",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter",
"Game/Client/View/Pixi/DebugDraw",
"Game/Client/View/Pixi/PlanckDebugDraw",
"Game/Client/View/Pixi/Layers/Debug"
],
function (Parent, Settings, domController, Box2D, nc, DebugDraw, debugLayer) {
function (Parent, Settings, domController, Box2D, nc, PlanckDebugDraw, debugLayer) {
"use strict";
@ -34,25 +34,26 @@ function (Parent, Settings, domController, Box2D, nc, DebugDraw, debugLayer) {
Engine.prototype.setupDebugDraw = function () {
// set debug draw
this.debugDraw = new DebugDraw();
// set debug draw for Planck.js
var canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = 'absolute';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '1000';
document.body.appendChild(canvas);
this.debugDraw = new PlanckDebugDraw(canvas);
this.debugCanvas = canvas;
};
this.debugDraw.SetSprite(debugLayer.graphics);
this.debugDraw.SetDrawScale(Settings.RATIO);
this.debugDraw.SetFillAlpha(0.5);
this.debugDraw.SetLineThickness(1.0);
this.debugDraw.SetFlags(null
| Box2D.Dynamics.b2DebugDraw.e_shapeBit
| Box2D.Dynamics.b2DebugDraw.e_jointBit
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
);
this.world.SetDebugDraw(this.debugDraw);
Engine.prototype.renderDebug = function () {
if (this.debugDraw) {
this.debugDraw.clear();
this.debugDraw.drawWorld(this.world);
}
};
Engine.prototype.update = function () {

View file

@ -1,5 +1,5 @@
define([
"Lib/Vendor/Box2D"
"Lib/Vendor/Planck"
],
function (Box2D) {

View file

@ -0,0 +1,154 @@
define([
"Game/Config/Settings"
],
function (Settings) {
"use strict";
function PlanckDebugDraw(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.scale = Settings.RATIO;
this.flags = {
shapes: true,
joints: false,
aabb: false,
pairs: false,
centerOfMass: false
};
}
PlanckDebugDraw.prototype.clear = function() {
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
PlanckDebugDraw.prototype.drawWorld = function(world) {
if (!this.flags.shapes) return;
this.ctx.save();
this.ctx.scale(this.scale, this.scale);
this.ctx.lineWidth = 1 / this.scale;
// Iterate through all bodies
for (var body = world.getBodyList(); body; body = body.getNext()) {
var transform = body.getTransform();
// Iterate through all fixtures
for (var fixture = body.getFixtureList(); fixture; fixture = fixture.getNext()) {
var shape = fixture.getShape();
if (body.isDynamic()) {
this.ctx.strokeStyle = '#ff0000'; // Red for dynamic bodies
this.ctx.fillStyle = 'rgba(255, 0, 0, 0.1)';
} else if (body.isStatic()) {
this.ctx.strokeStyle = '#00ff00'; // Green for static bodies
this.ctx.fillStyle = 'rgba(0, 255, 0, 0.1)';
} else {
this.ctx.strokeStyle = '#0000ff'; // Blue for kinematic bodies
this.ctx.fillStyle = 'rgba(0, 0, 255, 0.1)';
}
this.drawShape(shape, transform);
}
}
this.ctx.restore();
};
PlanckDebugDraw.prototype.drawShape = function(shape, transform) {
var type = shape.getType();
if (type === 'circle') {
this.drawCircle(shape, transform);
} else if (type === 'polygon') {
this.drawPolygon(shape, transform);
} else if (type === 'edge') {
this.drawEdge(shape, transform);
} else if (type === 'chain') {
this.drawChain(shape, transform);
}
};
PlanckDebugDraw.prototype.drawCircle = function(shape, transform) {
var center = transform.p;
var radius = shape.getRadius();
this.ctx.beginPath();
this.ctx.arc(center.x, center.y, radius, 0, 2 * Math.PI);
this.ctx.fill();
this.ctx.stroke();
// Draw radius line to show rotation
this.ctx.beginPath();
this.ctx.moveTo(center.x, center.y);
this.ctx.lineTo(center.x + radius, center.y);
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawPolygon = function(shape, transform) {
var vertices = shape.m_vertices;
if (!vertices || vertices.length < 3) return;
this.ctx.beginPath();
// Transform first vertex
var v = this.transformVertex(vertices[0], transform);
this.ctx.moveTo(v.x, v.y);
// Transform and draw remaining vertices
for (var i = 1; i < vertices.length; i++) {
v = this.transformVertex(vertices[i], transform);
this.ctx.lineTo(v.x, v.y);
}
this.ctx.closePath();
this.ctx.fill();
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawEdge = function(shape, transform) {
var v1 = this.transformVertex(shape.m_vertex1, transform);
var v2 = this.transformVertex(shape.m_vertex2, transform);
this.ctx.beginPath();
this.ctx.moveTo(v1.x, v1.y);
this.ctx.lineTo(v2.x, v2.y);
this.ctx.stroke();
};
PlanckDebugDraw.prototype.drawChain = function(shape, transform) {
var vertices = shape.m_vertices;
if (!vertices || vertices.length < 2) return;
this.ctx.beginPath();
var v = this.transformVertex(vertices[0], transform);
this.ctx.moveTo(v.x, v.y);
for (var i = 1; i < vertices.length; i++) {
v = this.transformVertex(vertices[i], transform);
this.ctx.lineTo(v.x, v.y);
}
this.ctx.stroke();
};
PlanckDebugDraw.prototype.transformVertex = function(vertex, transform) {
// Apply transform: rotated_vertex = transform.q * vertex + transform.p
var cos = Math.cos(transform.q.getAngle());
var sin = Math.sin(transform.q.getAngle());
return {
x: transform.p.x + (cos * vertex.x - sin * vertex.y),
y: transform.p.y + (sin * vertex.x + cos * vertex.y)
};
};
PlanckDebugDraw.prototype.setFlags = function(flags) {
this.flags = flags;
};
return PlanckDebugDraw;
});

View file

@ -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;

View file

@ -43,7 +43,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it?
this.createFixtures();
this.body.SetActive(false);
this.body.setActive(false);
nc.trigger(nc.ns.core.game.worldUpdateObjects.add, this);
}
@ -67,16 +67,16 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
var self = this;
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = 0;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
var radius = this.width / 2 / Settings.RATIO;
headShape.SetRadius(radius);
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO));
var headShape = planck.Circle(
radius,
planck.Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO)
);
fixtureDef.shape = headShape;
fixtureDef.isSensor = false;
fixtureDef.userData = {
@ -85,19 +85,20 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.body.createFixture(fixtureDef);
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
bodyShape.SetAsOrientedBox(
var bodyShape = planck.Box(
this.width / 2 / Settings.RATIO,
(this.height - this.width) / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, -this.height / 2 / Settings.RATIO)
planck.Vec2(0, -this.height / 2 / Settings.RATIO),
0
);
fixtureDef.shape = bodyShape;
fixtureDef.isSensor = false;
this.body.createFixture(fixtureDef);
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
legsShape.SetRadius(this.width / 2 / Settings.RATIO);
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -this.width / 2 / Settings.RATIO));
var legsShape = planck.Circle(
this.width / 2 / Settings.RATIO,
planck.Vec2(0, -this.width / 2 / Settings.RATIO)
);
fixtureDef.shape = legsShape;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false;
@ -106,9 +107,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
fixtureDef.density = 0;
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
feetShape.SetRadius((this.width - 1) / 2 / Settings.RATIO); // the -1 one prevents collisions with walls
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 2 / Settings.RATIO)); // 2 is offset into ground
var feetShape = planck.Circle(
(this.width - 1) / 2 / Settings.RATIO, // the -1 one prevents collisions with walls
planck.Vec2(0, 2 / Settings.RATIO) // 2 is offset into ground
);
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
@ -118,11 +120,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.footSensor = this.body.createFixture(fixtureDef);
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape();
grabSensorLeftShape.SetAsOrientedBox(
var grabSensorLeftShape = planck.Box(
this.reachDistance / 2 / Settings.RATIO,
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(
planck.Vec2(
-this.reachDistance / 2 / Settings.RATIO,
-this.height / 2 / Settings.RATIO
)
@ -136,11 +137,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
};
this.body.createFixture(fixtureDef);
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape();
grabSensorRightShape.SetAsOrientedBox(
var grabSensorRightShape = planck.Box(
this.reachDistance / 2 / Settings.RATIO,
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(
planck.Vec2(
this.reachDistance / 2 / Settings.RATIO,
-this.height / 2 / Settings.RATIO
)
@ -157,11 +157,10 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.body.createFixture(fixtureDef);
// Area Sensor
var areaSensorShape = new Box2D.Collision.Shapes.b2PolygonShape();
areaSensorShape.SetAsOrientedBox(
var areaSensorShape = planck.Box(
(this.width + this.areaSize) / 2 / Settings.RATIO,
(this.height + this.areaSize) / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(
planck.Vec2(
0,
-this.height / 2 / Settings.RATIO
)
@ -171,7 +170,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
fixtureDef.userData = {
onCollisionChange: function(isColliding, fixture) {
var userData = fixture.GetBody().GetUserData();
var userData = fixture.getBody().getUserData();
if(userData instanceof Doll) {
var doll = userData;
var i = self.nearbyDolls.indexOf(doll);
@ -205,13 +204,13 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.spawn = function (x, y) {
Assert.number(x, y);
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
this.body.SetActive(true);
this.body.setPosition(planck.Vec2(x / Settings.RATIO, y / Settings.RATIO));
this.body.setActive(true);
this.setActionState("fall");
};
Doll.prototype.getHeadPosition = function() {
var pos = this.body.GetPosition();
var pos = this.body.getPosition();
return {
x: pos.x,
y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO
@ -255,11 +254,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
}
this.setFriction(Settings.PLAYER_MOTION_FRICTION);
this.body.SetAwake(true);
this.body.setAwake(true);
Assert.number(speed, direction);
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
this.body.SetLinearVelocity(vector);
var vector = planck.Vec2(speed * direction, this.body.getLinearVelocity().y);
this.body.setLinearVelocity(vector);
if(this.isStanding()) {
if(this.moveDirection == this.lookDirection) {
@ -282,19 +281,19 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
if(this.isStanding()) {
this.setActionState("stand");
} else {
var vector = this.body.GetLinearVelocity().Copy();
var vector = this.body.getLinearVelocity().clone();
vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector);
this.body.setLinearVelocity(vector);
}
};
Doll.prototype.jump = function () {
if (this.isStanding()) {
this.body.SetAwake(true);
this.body.setAwake(true);
var vector = new Box2D.Common.Math.b2Vec2(0, -Settings.JUMP_SPEED);
this.body.SetLinearVelocity(vector);
var vector = planck.Vec2(0, -Settings.JUMP_SPEED);
this.body.setLinearVelocity(vector);
this.setStanding(false);
this.setActionState("jump");
@ -303,11 +302,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.jumpStop = function () {
if (!this.isStanding() ) {
this.body.SetAwake(true);
var vector = this.body.GetLinearVelocity().Copy();
this.body.setAwake(true);
var vector = this.body.getLinearVelocity().clone();
if(vector.y < 0) {
vector.y *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector);
this.body.setLinearVelocity(vector);
}
}
};
@ -325,7 +324,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.lookAt = function(x, y) {
var oldLookDirection = this.lookDirection;
this.body.SetAwake(true);
this.body.setAwake(true);
if(x < 0) {
this.lookDirection = -1;
} else {
@ -353,11 +352,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.holdingJoint = null;
}
var bodyPosition = this.body.GetPosition();
var bodyPosition = this.body.getPosition();
Assert.number(this.width, this.height);
Assert.number(this.lookDirection);
var handPosition = new Box2D.Common.Math.b2Vec2(
var handPosition = planck.Vec2(
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
bodyPosition.y - this.height / 4 * 2 / Settings.RATIO // 2/3 of the body height
);
@ -384,8 +383,8 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
this.holdingItem = null;
var dollVelocity = {
x: this.body.GetLinearVelocity().x,
y: this.body.GetLinearVelocity().y
x: this.body.getLinearVelocity().x,
y: this.body.getLinearVelocity().y
};
item.throw(options, dollVelocity);
@ -399,7 +398,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
var self = this;
var hasJumpStartVelocity = this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED;
var hasJumpStartVelocity = this.body.getLinearVelocity().y < -Settings.JUMP_SPEED;
if(isColliding) {
if(!hasJumpStartVelocity) {
@ -417,11 +416,11 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
continue;
}
if(contact.GetFixtureA() === self.footSensor) {
if(contact.getFixtureA() === self.footSensor) {
contactCount++;
}
if(contact.GetFixtureB() === self.footSensor) {
if(contact.getFixtureB() === self.footSensor) {
contactCount++;
}
@ -439,7 +438,7 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
};
Doll.prototype.onFixtureWithinReach = function(isColliding, side, fixture) {
var item = fixture.GetBody().GetUserData();
var item = fixture.getBody().getUserData();
if (!(item instanceof Item)) return;
if(isColliding) {
@ -456,18 +455,18 @@ function (Parent, Exception, planck, Settings, CollisionDetector, Item, nc, Asse
Doll.prototype.getVelocities = function() {
return {
linearVelocity: this.body.GetLinearVelocity(),
angularVelocity: this.body.GetAngularVelocity()
linearVelocity: this.body.getLinearVelocity(),
angularVelocity: this.body.getAngularVelocity()
};
};
Doll.prototype.update = function() {
if (this.body.GetLinearVelocity().x === 0 && this.isWalking()) {
if (this.body.getLinearVelocity().x === 0 && this.isWalking()) {
this.stop();
}
if (!this.body.IsAwake() && !this.isStanding()) {
if (!this.body.isAwake() && !this.isStanding()) {
this.setStanding(true);
}
};

View file

@ -51,11 +51,11 @@ function (planck, Exception, Assert, nc) {
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);
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;

View file

@ -1,6 +1,6 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/OptionsHelper",
"Game/Config/Settings",
"Lib/Utilities/Exception",
@ -37,7 +37,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
this.createFixture();
this.body.ResetMassData();
this.flipDirection = 1;
if (this.body.GetMass() < 1) {
if (this.body.getMass() < 1) {
this.body.SetBullet(true);
}
@ -48,11 +48,11 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Item.prototype.getBodyDef = function() {
Assert.number(this.options.x, this.options.y);
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.position.x = this.options.x / Settings.RATIO;
bodyDef.position.y = this.options.y / Settings.RATIO;
bodyDef.angle = 0;
var bodyDef = {
type: 'dynamic',
position: planck.Vec2(this.options.x / Settings.RATIO, this.options.y / Settings.RATIO),
angle: 0
};
return bodyDef;
};
@ -68,15 +68,12 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
if(this.options.type == "circle") {
var r = (w + h) / 4 ;
itemShape = new Box2D.Collision.Shapes.b2CircleShape();
itemShape.SetRadius(r);
itemShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -r));
itemShape = planck.Circle(r, planck.Vec2(0, -r));
} else {
itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
itemShape = planck.Box(w / 2, h / 2, planck.Vec2(0, -(h/2)));
}
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = itemShape;
fixtureDef.density = this.options.weight;
@ -95,7 +92,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Item.prototype.createFixture = function () {
var fixtureDef = this.getFixtureDef();
this.body.CreateFixture(fixtureDef);
this.body.createFixture(fixtureDef);
};
Item.prototype.flip = function(direction) {
@ -122,8 +119,8 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Assert.number(this.options.width);
Assert.number(this.options.grabAngle);
this.body.SetAwake(true);
var position = new Box2D.Common.Math.b2Vec2(
this.body.setAwake(true);
var position = planck.Vec2(
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
handPosition.y
);
@ -133,7 +130,7 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
};
Item.prototype.getGrabPoint = function() {
return this.body.GetWorldCenter();
return this.body.getWorldCenter();
};
Item.prototype.throw = function(options, carrierVelocity) {
@ -146,15 +143,15 @@ function (Parent, Box2D, optionsHelper, Settings, Exception, nc, Assert) {
Assert.number(options.x, options.y);
Assert.number(options.av);
body.SetAwake(true);
body.setAwake(true);
var x = options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x;
var y = -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y;
var vector = new Box2D.Common.Math.b2Vec2(x, y);
var vector = planck.Vec2(x, y);
body.SetLinearVelocity(vector);
var av = -options.av * Settings.MAX_THROW_ANGULAR_VELOCITY;
body.SetAngularVelocity(av);
body.setAngularVelocity(av);
};
Item.prototype.destroy = function() {

View file

@ -1,6 +1,6 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert",
@ -174,17 +174,17 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
};
RagDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy();
return this.body.GetPosition().clone();
};
RagDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy();
return this.limbs.head.GetPosition().clone();
};
RagDoll.prototype.getBodyDef = function() {
var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.type = 'dynamic';
bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground
return bodyDef;
@ -199,11 +199,10 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
fixtureDef.filter.groupIndex = -this.getId();
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
shape.SetAsOrientedBox(
var shape = planck.Box(
this.options.limbs.chest.width / 2 / Settings.RATIO,
this.options.limbs.chest.height / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, 0)
planck.Vec2(0, 0)
);
fixtureDef.shape = shape;
@ -217,10 +216,9 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var w = this.options.width / Settings.RATIO;
var h = this.options.height / Settings.RATIO;
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, 0));
var itemShape = planck.Box(w / 2, h / 2, 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 };
fixtureDef.shape = itemShape;
fixtureDef.isSensor = true;
@ -228,7 +226,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
onCollisionChange: this.onCollisionChange.bind(this)
};
this.body.CreateFixture(fixtureDef);
this.body.createFixture(fixtureDef);
};
RagDoll.prototype.addHead = function() {
@ -239,17 +237,15 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var x = this.options.x + this.options.limbs.head.x,
y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground;
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 shape = new Box2D.Collision.Shapes.b2CircleShape();
shape.SetRadius(this.options.limbs.head.width / 2 / Settings.RATIO);
shape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
var shape = planck.Circle(this.options.limbs.head.width / 2 / 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 };
fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
@ -258,7 +254,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.filter.groupIndex = -this.getId();
var head = this.body.GetWorld().CreateBody(bodyDef);
head.CreateFixture(fixtureDef);
head.createFixture(fixtureDef);
this.limbs.head = head;
@ -271,7 +267,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jointDef.enableMotor = false;
var pos = this.body.GetWorldCenter().Copy();
var pos = this.body.getWorldCenter().clone();
pos.y -= this.options.limbs.chest.height / 2 / Settings.RATIO;
jointDef.Initialize(this.body, head, pos);
jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
@ -290,21 +286,20 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var x = this.options.x + this.options.limbs[name].x,
y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
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,
linearDamping: Settings.PLAYER_LINEAR_DAMPING
};
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
shape.SetAsOrientedBox(
var shape = planck.Box(
this.options.limbs[name].width / 2 / Settings.RATIO,
this.options.limbs[name].height / 2 / Settings.RATIO,
new Box2D.Common.Math.b2Vec2(0, this.options.limbs[name].height / 2 / Settings.RATIO)
planck.Vec2(0, this.options.limbs[name].height / 2 / Settings.RATIO)
);
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.density = Settings.PLAYER_DENSITY;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
@ -313,14 +308,14 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
fixtureDef.filter.groupIndex = -this.getId();
var limb = this.body.GetWorld().CreateBody(bodyDef);
limb.CreateFixture(fixtureDef);
limb.createFixture(fixtureDef);
this.limbs[name] = limb;
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jointDef.enableMotor = false;
var pos = connectTo.GetWorldCenter().Copy();
var pos = connectTo.getWorldCenter().clone();
pos.x += (xOffset / Settings.RATIO);
pos.y += (yOffset / Settings.RATIO);
jointDef.Initialize(connectTo, limb, pos);
@ -347,7 +342,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
var chestPosition = this.body.GetPosition();
var position = new Box2D.Common.Math.b2Vec2(
var position = planck.Vec2(
chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
);
@ -370,7 +365,7 @@ function (Parent, Box2D, Settings, nc, Assert, optionsHelper, ItemSettings) {
Assert.number(options.angularVelocity);
this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity);
this.body.setAngularVelocity(options.angularVelocity);
for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity);
}

View file

@ -1,6 +1,6 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Game/Config/Settings"
],
@ -24,13 +24,13 @@ function (Parent, Box2D, Settings) {
var bodies = [];
var joints = [];
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(-1.917114257812500e-01, 1.433728694915771e+00);
bodies[0] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -38,45 +38,45 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, -2.545155882835388e-01);
vs[0] = planck.Vec2(6.299880146980286e-02, -2.545155882835388e-01);
vs[1] = planck.Vec2(6.299880146980286e-02, 2.545149326324463e-01);
vs[2] = planck.Vec2(-6.299890577793121e-02, 2.545149326324463e-01);
vs[3] = planck.Vec2(-6.299890577793121e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[0].CreateFixture(fd);
bodies[0].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(-6.397294998168945e-02, 1.267420768737793e+00);
bodies[1] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.883362084627151e-01, -4.305148720741272e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.846363544464111e-01, 5.393795371055603e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(1.850083470344543e-03, 5.393795371055603e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, 4.209862351417542e-01);
vs[4] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, -4.607573151588440e-01);
vs[5] = new Box2D.Common.Math.b2Vec2(1.600667834281921e-03, -4.952520132064819e-01);
vs[0] = planck.Vec2(1.883362084627151e-01, -4.305148720741272e-01);
vs[1] = planck.Vec2(1.846363544464111e-01, 5.393795371055603e-01);
vs[2] = planck.Vec2(1.850083470344543e-03, 5.393795371055603e-01);
vs[3] = planck.Vec2(-1.883361339569092e-01, 4.209862351417542e-01);
vs[4] = planck.Vec2(-1.883361339569092e-01, -4.607573151588440e-01);
vs[5] = planck.Vec2(1.600667834281921e-03, -4.952520132064819e-01);
shape.SetAsArray(vs, 6);
fd.shape = shape;
bodies[1].CreateFixture(fd);
bodies[1].createFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -84,25 +84,25 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 4.875739216804504e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 6.762337088584900e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 6.762337088584900e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 4.875739216804504e-01);
vs[0] = planck.Vec2(1.840525716543198e-01, 4.875739216804504e-01);
vs[1] = planck.Vec2(1.840525716543198e-01, 6.762337088584900e-01);
vs[2] = planck.Vec2(-4.607129842042923e-03, 6.762337088584900e-01);
vs[3] = planck.Vec2(-4.607129842042923e-03, 4.875739216804504e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[1].CreateFixture(fd);
bodies[1].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(4.118728637695312e-02, 2.199305295944214e+00);
bodies[2] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01;
@ -114,10 +114,10 @@ function (Parent, Box2D, Settings) {
fd.shape = shape;
bodies[2].CreateFixture(fd);
bodies[2].createFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01;
@ -129,17 +129,17 @@ function (Parent, Box2D, Settings) {
fd.shape = shape;
bodies[2].CreateFixture(fd);
bodies[2].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(1.235442161560059e-01, 1.142371892929077e+00);
bodies[3] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -147,26 +147,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -1.556134223937988e-01);
vs[0] = planck.Vec2(6.299892067909241e-02, -1.556134223937988e-01);
vs[1] = planck.Vec2(6.299892067909241e-02, 1.556134223937988e-01);
vs[2] = planck.Vec2(-6.299898028373718e-02, 1.556134223937988e-01);
vs[3] = planck.Vec2(-6.299898028373718e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[3].CreateFixture(fd);
bodies[3].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(-9.663248062133789e-02, 3.554300665855408e-01);
bodies[4] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -174,18 +174,18 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -1.253567039966583e-01);
vs[0] = planck.Vec2(1.550966501235962e-01, -1.253567039966583e-01);
vs[1] = planck.Vec2(1.550966501235962e-01, -6.225190684199333e-02);
vs[2] = planck.Vec2(-9.268096834421158e-02, -6.225190684199333e-02);
vs[3] = planck.Vec2(-9.268096834421158e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[4].CreateFixture(fd);
bodies[4].createFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -193,26 +193,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, -1.247676759958267e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, 1.715210527181625e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, 1.715210527181625e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, -1.247676759958267e-01);
vs[0] = planck.Vec2(9.449840337038040e-02, -1.247676759958267e-01);
vs[1] = planck.Vec2(9.449840337038040e-02, 1.715210527181625e-01);
vs[2] = planck.Vec2(-9.449829906225204e-02, 1.715210527181625e-01);
vs[3] = planck.Vec2(-9.449829906225204e-02, -1.247676759958267e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[4].CreateFixture(fd);
bodies[4].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(-1.917138099670410e-01, 1.142371892929077e+00);
bodies[5] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -220,26 +220,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, -1.556134223937988e-01);
vs[0] = planck.Vec2(6.299891322851181e-02, -1.556134223937988e-01);
vs[1] = planck.Vec2(6.299891322851181e-02, 1.556134223937988e-01);
vs[2] = planck.Vec2(-6.299878656864166e-02, 1.556134223937988e-01);
vs[3] = planck.Vec2(-6.299878656864166e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[5].CreateFixture(fd);
bodies[5].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(1.235442161560059e-01, 1.433728694915771e+00);
bodies[6] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -247,25 +247,25 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -2.545155882835388e-01);
vs[0] = planck.Vec2(6.299892067909241e-02, -2.545155882835388e-01);
vs[1] = planck.Vec2(6.299892067909241e-02, 2.545149326324463e-01);
vs[2] = planck.Vec2(-6.299898028373718e-02, 2.545149326324463e-01);
vs[3] = planck.Vec2(-6.299898028373718e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[6].CreateFixture(fd);
bodies[6].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(2.897095680236816e-02, 6.702435612678528e-01);
bodies[7] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -273,26 +273,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -2.537839412689209e-01);
vs[0] = planck.Vec2(9.449830651283264e-02, -2.537839412689209e-01);
vs[1] = planck.Vec2(9.449830651283264e-02, 2.537844777107239e-01);
vs[2] = planck.Vec2(-9.449817240238190e-02, 2.537844777107239e-01);
vs[3] = planck.Vec2(-9.449817240238190e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[7].CreateFixture(fd);
bodies[7].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(-9.663248062133789e-02, 6.702435612678528e-01);
bodies[8] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -300,26 +300,26 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, -2.537839412689209e-01);
vs[0] = planck.Vec2(9.449842572212219e-02, -2.537839412689209e-01);
vs[1] = planck.Vec2(9.449842572212219e-02, 2.537844777107239e-01);
vs[2] = planck.Vec2(-9.449826925992966e-02, 2.537844777107239e-01);
vs[3] = planck.Vec2(-9.449826925992966e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[8].CreateFixture(fd);
bodies[8].createFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = 'dynamic';
bd.position.Set(2.897095680236816e-02, 3.554300665855408e-01);
bodies[9] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -327,18 +327,18 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -1.253567039966583e-01);
vs[0] = planck.Vec2(1.550965905189514e-01, -1.253567039966583e-01);
vs[1] = planck.Vec2(1.550965905189514e-01, -6.225190684199333e-02);
vs[2] = planck.Vec2(-9.268099069595337e-02, -6.225190684199333e-02);
vs[3] = planck.Vec2(-9.268099069595337e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[9].CreateFixture(fd);
bodies[9].createFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -346,29 +346,29 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -1.247680261731148e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 1.713046580553055e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 1.713046580553055e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -1.247680261731148e-01);
vs[0] = planck.Vec2(9.449830651283264e-02, -1.247680261731148e-01);
vs[1] = planck.Vec2(9.449830651283264e-02, 1.713046580553055e-01);
vs[2] = planck.Vec2(-9.449817240238190e-02, 1.713046580553055e-01);
vs[3] = planck.Vec2(-9.449817240238190e-02, -1.247680261731148e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[9].CreateFixture(fd);
bodies[9].createFixture(fd);
}
}
/*{
ground body
var bd = new Box2D.Dynamics.b2BodyDef();
var bd = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bd.type = b2BodyType(0);
bd.position.Set(3.118395805358887e-03, -6.553649902343750e-03);
bodies[10] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
var fd = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
@ -376,8 +376,8 @@ function (Parent, Box2D, Settings) {
fd.filter.groupIndex = int16(0);
b2ChainShape shape;
b2Vec2 vs[2];
vs[0] = new Box2D.Common.Math.b2Vec2(-4.179394245147705e+00, 0.000000000000000e+00);
vs[1] = new Box2D.Common.Math.b2Vec2(4.179394245147705e+00, 0.000000000000000e+00);
vs[0] = planck.Vec2(-4.179394245147705e+00, 0.000000000000000e+00);
vs[1] = planck.Vec2(4.179394245147705e+00, 0.000000000000000e+00);
shape.CreateChain(vs, 2);
shape.m_prevVertex.Set(-1.998532295227051e+00, -2.391039296991059e-23);
shape.m_nextVertex.Set(4.949933242915726e-38, 3.363116314379561e-44);
@ -386,7 +386,7 @@ function (Parent, Box2D, Settings) {
fd.shape = shape;
bodies[10].CreateFixture(fd);
bodies[10].createFixture(fd);
}
}*/
{
@ -548,7 +548,7 @@ function (Parent, Box2D, Settings) {
lowerRightLeg: bodies[9]
};
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(20,0));
this.body.SetPosition(planck.Vec2(20,0));
};
RagDoll.prototype.destroy = function() {

View file

@ -1,21 +1,25 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/RubeLoader",
"Lib/Vendor/Box2D",
// "Lib/Vendor/RubeLoader", // Temporarily disabled during Planck.js migration
"Lib/Vendor/Planck",
"Game/Config/Settings",
"Lib/Utilities/Assert",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Matrix",
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
"Lib/Utilities/Matrix"
// "json!Game/Asset/RubeDoll.json" // Temporarily disabled during Planck.js migration
],
function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson) {
function (Parent, /* RubeLoader, */ Box2D, Settings, Assert, nc, Matrix /* , RubeDollJson */) {
"use strict";
function RubeDoll(physicsEngine, uid, options) {
Assert.number(options.x, options.y);
// TODO: Implement RubeDoll with Planck.js
// Temporarily stubbed out during Box2D -> Planck.js migration
console.warn("RubeDoll is temporarily disabled during Planck.js migration");
this.rubeLoader = null;
this.body = null;
this.limbs = {};
@ -23,9 +27,8 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
this.limits = [];
var chest = null;
this.rubeLoader = new RubeLoader(RubeDollJson, physicsEngine.getWorldForRubeLoader());
this.loadRubeDollFromScene(options);
// this.rubeLoader = new RubeLoader(RubeDollJson, physicsEngine.getWorldForRubeLoader());
// this.loadRubeDollFromScene(options);
Parent.call(this, physicsEngine, uid, options);
physicsEngine.destroyBody(this.body);
@ -46,8 +49,8 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
for (var i in scene.bodies) {
var body = scene.bodies[i];
var position = body.GetPosition().Copy();
position.Add(new Box2D.Common.Math.b2Vec2(
var position = body.GetPosition().clone();
position.Add(planck.Vec2(
options.x / Settings.RATIO,
options.y / Settings.RATIO
));
@ -86,7 +89,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
};
RubeDoll.prototype.getFixtureDef = function() {
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
var fixtureDef = { shape: null, density: 1.0, friction: 0.3, restitution: 0.0, isSensor: false };
fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape();
return fixtureDef;
};
@ -134,7 +137,7 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
var differenceAngle = oldAngle - this.body.GetAngle();
//this.body.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
//this.body.SetLinearVelocity(planck.Vec2(0, 0));
var offset = Box2D.Common.Math.b2Math.SubtractVV(this.getPosition(), oldPosition);
var grabAngle = (this.options.grabAngle || 0.001);
@ -143,12 +146,12 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
var limb = this.limbs[key];
// Setting position offset first (floor to hand)
var position = limb.GetPosition().Copy();
var position = limb.GetPosition().clone();
position.Add(offset);
limb.SetPosition(position);
// grabing local point to "rotate" around (x, y position transform only)
var localPoint = this.body.GetLocalPoint(limb.GetPosition().Copy());
var localPoint = this.body.getLocalPoint(limb.GetPosition().clone());
// create rotation matrix from chest rotation difference
var mat = Box2D.Common.Math.b2Mat22.FromAngle(differenceAngle);
@ -157,15 +160,15 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
position = Box2D.Common.Math.b2Math.MulTMV(mat, localPoint);
// translating back to global position
var globalPoint = this.body.GetWorldPoint(position);
var globalPoint = this.body.getWorldPoint(position);
limb.SetPosition(globalPoint);
// relative limb rotating by chest rotation difference
var d = (oldDirection == direction) ? -1 : 1;
limb.SetAngle((limb.GetAngle() - differenceAngle) * d);
//limb.SetType(Box2D.Dynamics.b2Body.b2_staticBody);
//limb.SetLinearVelocity(new Box2D.Common.Math.b2Vec2(0, 0));
//limb.SetType('static');
//limb.SetLinearVelocity(planck.Vec2(0, 0));
}
};
@ -174,18 +177,18 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
Assert.number(options.angularVelocity);
this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity);
this.body.setAngularVelocity(options.angularVelocity);
for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity);
}
};
RubeDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy();
return this.body.GetPosition().clone();
};
RubeDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy();
return this.limbs.head.GetPosition().clone();
};
RubeDoll.prototype.setUpdateData = function(update) {
@ -199,11 +202,11 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, nc, Matrix, RubeDollJson)
Assert.number(update.limbs[name].lv.x, update.limbs[name].lv.y);
Assert.number(update.limbs[name].av);
this.limbs[name].SetAwake(true);
this.limbs[name].setAwake(true);
this.limbs[name].SetPosition(update.limbs[name].p);
this.limbs[name].SetAngle(update.limbs[name].a);
this.limbs[name].SetLinearVelocity(update.limbs[name].lv);
this.limbs[name].SetAngularVelocity(update.limbs[name].av);
this.limbs[name].setAngularVelocity(update.limbs[name].av);
}
*/
}

View file

@ -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);

View file

@ -1,6 +1,6 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D"
"Lib/Vendor/Planck"
],
function (Parent, Box2D) {
@ -14,8 +14,8 @@ function (Parent, Box2D) {
SpectatorDoll.prototype = Object.create(Parent.prototype);
SpectatorDoll.prototype.getBodyDef = function() {
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
var bodyDef = { type: 'static', position: planck.Vec2(0, 0), angle: 0 };
bodyDef.type = 'dynamic';
bodyDef.position.x = this.getPosition().x;
bodyDef.position.y = this.getPosition().y;
bodyDef.angle = 0;

View file

@ -1,6 +1,6 @@
define([
"Game/Config/Settings",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Abstract",
"Game/" + GLOBALS.context + "/Collision/Detector",

View file

@ -2,7 +2,7 @@ define([
"Game/" + GLOBALS.context + "/Loader/Level",
"Game/Config/Settings",
"Game/Config/ItemSettings",
"Lib/Vendor/Box2D",
"Lib/Vendor/Planck",
"Lib/Utilities/OptionsHelper",
"Lib/Utilities/Exception",
"Lib/Utilities/NotificationCenter",

View file

@ -24,7 +24,7 @@ function (Settings, planck, CollisionDetector, nc) {
Engine.prototype.setCollisionDetector = function () {
var detector = new CollisionDetector();
this.world.on('begin-contact', detector.getListener());
detector.setupWorldEvents(this.world);
}
Engine.prototype.getWorldForRubeLoader = function() {