Skip to content

Commit

Permalink
changed plugins to use body.plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 26, 2017
1 parent b353393 commit 3fdf343
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
10 changes: 6 additions & 4 deletions examples/attractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ Example.attractors = function() {
radius,
{
mass: Common.random(10, 15),
gravity: G,
frictionAir: 0,
wrap: {
min: { x: 0, y: 0 },
max: { x: render.options.width, y: render.options.height }
plugin: {
gravity: G,
wrap: {
min: { x: 0, y: 0 },
max: { x: render.options.width, y: render.options.height }
}
}
}
);
Expand Down
2 changes: 2 additions & 0 deletions examples/attractorsPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo

(function() {

var MatterAttractors = {
Expand Down
2 changes: 1 addition & 1 deletion examples/avalanche.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Example.avalanche = function() {

// wrapping using matter-wrap plugin
for (var i = 0; i < stack.bodies.length; i += 1) {
stack.bodies[i].wrap = {
stack.bodies[i].plugin.wrap = {
min: { x: render.bounds.min.x, y: render.bounds.min.y },
max: { x: render.bounds.max.x, y: render.bounds.max.y }
};
Expand Down
2 changes: 1 addition & 1 deletion examples/ballPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Example.ballPool = function() {
var allBodies = Composite.allBodies(world);

for (var i = 0; i < allBodies.length; i += 1) {
allBodies[i].wrap = {
allBodies[i].plugin.wrap = {
min: { x: render.bounds.min.x - 100, y: render.bounds.min.y },
max: { x: render.bounds.max.x + 100, y: render.bounds.max.y }
};
Expand Down
6 changes: 4 additions & 2 deletions examples/gravityPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo

(function() {

var MatterGravity = {
Expand All @@ -19,7 +21,7 @@

Body: {
init: function(body) {
if (body.gravity) {
if (body.plugin.gravity) {
body.attractors.push(MatterGravity.Body.applyGravity);
}
},
Expand All @@ -28,7 +30,7 @@
var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
normal = Matter.Vector.normalise(bToA),
magnitude = -bodyA.gravity * (bodyA.mass * bodyB.mass / distanceSq),
magnitude = -bodyA.plugin.gravity * (bodyA.mass * bodyB.mass / distanceSq),
force = Matter.Vector.mult(normal, magnitude);

Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
Expand Down
6 changes: 4 additions & 2 deletions examples/wrapPlugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo

(function() {

var MatterWrap = {
Expand All @@ -21,8 +23,8 @@
for (var i = 0; i < bodies.length; i += 1) {
var body = bodies[i];

if (body.wrap) {
MatterWrap.Body.wrap(body, body.wrap);
if (body.plugin.wrap) {
MatterWrap.Body.wrap(body, body.plugin.wrap);
}
}
}
Expand Down

0 comments on commit 3fdf343

Please sign in to comment.