Skip to content

Commit 3132d70

Browse files
committed
added Demo.terrain
1 parent 87fbf51 commit 3132d70

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

demo/js/Demo.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,50 @@
255255
});
256256
};
257257

258+
Demo.terrain = function() {
259+
var _world = _engine.world;
260+
261+
Demo.reset();
262+
_world.bodies = [];
263+
264+
var terrain;
265+
266+
$.get('./svg/terrain.svg').done(function(data) {
267+
var vertexSets = [],
268+
color = Common.choose(['#556270', '#4ECDC4', '#C7F464', '#FF6B6B', '#C44D58']);
269+
270+
$(data).find('path').each(function(i, path) {
271+
vertexSets.push(Svg.pathToVertices(path, 30));
272+
});
273+
274+
terrain = Bodies.fromVertices(400, 350, vertexSets, {
275+
isStatic: true,
276+
render: {
277+
fillStyle: color,
278+
strokeStyle: color
279+
}
280+
}, true);
281+
282+
World.add(_world, terrain);
283+
284+
var bodyOptions = {
285+
frictionAir: 0,
286+
friction: 0.0001,
287+
restitution: 0.6
288+
};
289+
290+
World.add(_world, Composites.stack(80, 100, 20, 20, 10, 10, function(x, y, column, row) {
291+
if (Query.point([terrain], { x: x, y: y }).length === 0) {
292+
return Bodies.polygon(x, y, 5, 12, bodyOptions);
293+
}
294+
}));
295+
});
296+
297+
var renderOptions = _engine.render.options;
298+
renderOptions.showAngleIndicator = false;
299+
renderOptions.showVelocity = true;
300+
};
301+
258302
Demo.slingshot = function() {
259303
var _world = _engine.world;
260304

demo/svg/terrain.svg

Lines changed: 37 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)