Boiler plate for p5.play
-
Physics Engine : We need physics engine so that in our game world, we can make the objects look like actual physical bodies.
-
We use an online available physics engine - matter.js
-
In matter.js, we have three very important things i) Engine - power source to light up the world to be created ii) World - the World that we design to add the objects iii) Bodies - The bodies that are present in our game world.
-
We can make use of the inbuilt Engine, world and Bodies from matter.js
-
Whenver we create a object in our world, to add it to the world, type World.add(world,);
-
To make the body static, we need to make use of the algorithm, isStatic: true
-
To give bounciness to the body, make use of the algorithm restitution: 1.0
(restitution varies from 0 to 1 generally);
-
Never forget to update the engine inside the draw function.