Skip to content

Commit

Permalink
added Demo.terrain
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 21, 2015
1 parent 87fbf51 commit 3132d70
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
44 changes: 44 additions & 0 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,50 @@
});
};

Demo.terrain = function() {
var _world = _engine.world;

Demo.reset();
_world.bodies = [];

var terrain;

$.get('./svg/terrain.svg').done(function(data) {
var vertexSets = [],
color = Common.choose(['#556270', '#4ECDC4', '#C7F464', '#FF6B6B', '#C44D58']);

$(data).find('path').each(function(i, path) {
vertexSets.push(Svg.pathToVertices(path, 30));
});

terrain = Bodies.fromVertices(400, 350, vertexSets, {
isStatic: true,
render: {
fillStyle: color,
strokeStyle: color
}
}, true);

World.add(_world, terrain);

var bodyOptions = {
frictionAir: 0,
friction: 0.0001,
restitution: 0.6
};

World.add(_world, Composites.stack(80, 100, 20, 20, 10, 10, function(x, y, column, row) {
if (Query.point([terrain], { x: x, y: y }).length === 0) {
return Bodies.polygon(x, y, 5, 12, bodyOptions);
}
}));
});

var renderOptions = _engine.render.options;
renderOptions.showAngleIndicator = false;
renderOptions.showVelocity = true;
};

Demo.slingshot = function() {
var _world = _engine.world;

Expand Down
37 changes: 37 additions & 0 deletions demo/svg/terrain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3132d70

Please sign in to comment.