initial commit

This commit is contained in:
Ayo 2023-02-03 21:21:18 +01:00
commit ca5fcaef03
5 changed files with 121 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
node_modules
*~
*swo
*swp

21
index.html Normal file
View file

@ -0,0 +1,21 @@
<html>
<head>
<title>Twists and Shapes and Turns</title>
<style>
html,
body {
background: black;
color: white;
}
</style>
<script src="./node_modules/matter-js/build/matter.min.js"></script>
</head>
<body>
<h1>Hello Kahel!</h1>
<button onclick="kaboom()">Kaboom!</button>
<button onclick="addShape()">Add Shape!</button>
<hr />
<br />
<script src="index.js"></script>
</body>
</html>

52
index.js Normal file
View file

@ -0,0 +1,52 @@
// module aliases
let Engine = Matter.Engine,
Render = Matter.Render,
Runner = Matter.Runner,
Bodies = Matter.Bodies,
Composite = Matter.Composite;
// create an engine
let engine = Engine.create();
// create a renderer
let render = Render.create({
element: document.body,
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() {
let manyShapes = new Array(300)
.fill({})
.map((item) =>
Bodies.polygon(
Math.random() * 450 + 1,
Math.random() * 450 + 1,
Math.random() * 16 + 1,
Math.random() * 80 + 1
)
);
console.log(manyShapes);
generateWorld(manyShapes);
}
function generateWorld(shapes) {
// add all of the bodies to the world
// Composite.add(engine.world, [boxA, boxB, triangle, ground]);
Composite.add(engine.world, [...shapes, ground]);
// run the renderer
Render.run(render);
// create runner
let runner = Runner.create();
// run the engine
Runner.run(runner, engine);
}

28
package-lock.json generated Normal file
View file

@ -0,0 +1,28 @@
{
"name": "twists-and-shapes-and-turns",
"version": "0.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "twists-and-shapes-and-turns",
"version": "0.0.1",
"license": "ISC",
"dependencies": {
"matter-js": "^0.18.0"
}
},
"node_modules/matter-js": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/matter-js/-/matter-js-0.18.0.tgz",
"integrity": "sha512-/ZVem4WygUnbmo/iE4oHZpZS97btfBtYy5Iwn1396vUZU7YhgVEN8J4UWwfZwY1ZqoTYlPgjvSw9WXauuXL0mg=="
}
},
"dependencies": {
"matter-js": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/matter-js/-/matter-js-0.18.0.tgz",
"integrity": "sha512-/ZVem4WygUnbmo/iE4oHZpZS97btfBtYy5Iwn1396vUZU7YhgVEN8J4UWwfZwY1ZqoTYlPgjvSw9WXauuXL0mg=="
}
}
}

14
package.json Normal file
View file

@ -0,0 +1,14 @@
{
"name": "twists-and-shapes-and-turns",
"version": "0.0.1",
"description": "This is a game about crazy inventions",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ayo and Kahel",
"license": "ISC",
"dependencies": {
"matter-js": "^0.18.0"
}
}