From 95bd36b9b45cc7591293ed5c2acdb538b84e18d7 Mon Sep 17 00:00:00 2001 From: wassname Date: Mon, 26 Nov 2018 06:42:56 +0800 Subject: [PATCH] walls on floor, more randomness --- js/floor.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/floor.js b/js/floor.js index dfff2af..ef4fd76 100644 --- a/js/floor.js +++ b/js/floor.js @@ -7,15 +7,20 @@ function createFloor() { // start with flat floor var edges = [ + new b2.Vec2(-3.5, 4), // back wall new b2.Vec2(-3.5, -0.16), new b2.Vec2(2.5, -0.16) ]; for(var k = 2; k < config.max_floor_tiles; k++) { - var ratio = k/config.max_floor_tiles; - edges.push(new b2.Vec2(edges[edges.length-1].x + (1 + ratio * Math.random() - ratio/2), edges[edges.length-1].y + (ratio * Math.random() - ratio/2 ))); + var ratio = k / config.max_floor_tiles; + // add uneven floor by continuing from the last point, plus some random jittering + edges.push(new b2.Vec2( + edges[edges.length - 1].x + (1 + ratio * Math.random() - ratio / 2), + edges[edges.length - 1].y + (ratio * Math.random() - ratio / 2)* 2)); // edges.push(new b2.Vec2(edges[edges.length-1].x + 1,-0.16)); } + edges.push(new b2.Vec2(edges[edges.length-1].x, edges[edges.length-1].y + 8)); // front wall fix_def.shape.CreateChain(edges, edges.length); body.CreateFixture(fix_def); return body;