From 3132d7007e1e6ddb9b761dfa8c18528379c87084 Mon Sep 17 00:00:00 2001 From: liabru Date: Tue, 21 Apr 2015 21:19:46 +0100 Subject: [PATCH] added Demo.terrain --- demo/js/Demo.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ demo/svg/terrain.svg | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 demo/svg/terrain.svg diff --git a/demo/js/Demo.js b/demo/js/Demo.js index 0a48479..f966d72 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -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; diff --git a/demo/svg/terrain.svg b/demo/svg/terrain.svg new file mode 100644 index 0000000..7f9d920 --- /dev/null +++ b/demo/svg/terrain.svg @@ -0,0 +1,37 @@ + + + + + + + + + image/svg+xml + + + + + + + + +