initial addShape

This commit is contained in:
Ayo 2023-02-03 21:34:06 +01:00
parent 79db880eb4
commit 94ce67d1b4

View file

@ -14,16 +14,10 @@ let render = Render.create({
engine: engine, engine: engine,
}); });
// create two boxes and a ground
let boxA = Bodies.rectangle(400, 200, 80, 200);
let boxB = Bodies.rectangle(450, 50, 80, 80);
let triangle = Bodies.polygon(350, 200, 5, 80);
let ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
function kaboom() { function kaboom() {
let manyShapes = new Array(300) let manyShapes = new Array(300)
.fill({}) .fill()
.map((item) => .map(() =>
Bodies.polygon( Bodies.polygon(
Math.random() * 450 + 1, Math.random() * 450 + 1,
Math.random() * 450 + 1, Math.random() * 450 + 1,
@ -32,14 +26,16 @@ function kaboom() {
) )
); );
console.log(manyShapes);
generateWorld(manyShapes); generateWorld(manyShapes);
} }
function addShape() {
// to be continued
}
function generateWorld(shapes) { function generateWorld(shapes) {
// add all of the bodies to the world // add all of the bodies to the world
// Composite.add(engine.world, [boxA, boxB, triangle, ground]); let ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });
Composite.add(engine.world, [...shapes, ground]); Composite.add(engine.world, [...shapes, ground]);
// run the renderer // run the renderer