This demo demonstrate basic collision detection with Shaku.collision manager.
Move the shape with your mouse to test collision, press 1-4 to replace the shape, and + / - to set size.
The following shows a minimal code example for collision detection.
// create collision world
let world = Shaku.collision.createWorld(128);
// add a point to world
let point = new Shaku.collision.PointShape(new Shaku.utils.Vector2(125, 65));
world.addShape(point);
// add a rectngle to world
let rect = new Shaku.collision.RectangleShape(new Shaku.utils.Rectangle(45, 75, 100, 50));
world.addShape(rect);
// add a circle to world
let circle = new Shaku.collision.CircleShape(new Shaku.utils.Circle(new Shaku.utils.Vector2(300, 315), 150));
world.addShape(circle);
// add a line to world
let lines = new Shaku.collision.LinesShape(new Shaku.utils.Line(new Shaku.utils.Vector2(100, 100), new Shaku.utils.Vector2(150, 150)));
world.addShape(lines);
// create a circle at mouse position with radius of 100. we'll use it to check collisions
let shapeToTest = new Shaku.collision.CircleShape(new Shaku.utils.Circle(Shaku.input.mousePosition, 100));
// test a single result, sorted by distance
let collisionSingle = world.testCollision(shapeToTest, true);
if (collisionSingle) {
console.log(collisionSingle.first, collisionSingle.second);
}
// test many results, not sorted
let collisions = world.testCollisionMany(shapeToTest, false);
for (let i = 0; i < collisions.length; ++i) {
console.log(collisions[i].first, collisions[i].second);
}