simple, quick, AABB framework-independent, collision system.
npm install bopitBopit only does axis-aligned bounding-box (AABB) collisions. If you need anythingBopit is _gameistic_ instead of realistic.``
import {World, Body} from 'bopit'
const world = new World()
const body = new Body(0, 0, 10, 10)
body.add(world)
`
Creates a new virtual space for tracking physical interactions split into cells.
Parameters
- cellSize Is an optional number. It defaults to 64. It represents the size of
the sides of the (squared) cells that will be used internally to provide the data.
In tile based games, it's usually a multiple of the tile side size. So in a game
where tiles are 32x32, cellSize will be 32, 64 or 128. In more sparse games,
it can be higher.
Returns
- World
Parameters
- x x coordinate, Numbery
- y coordinate, Numberwidth
- width of the rectangle, Numberheight
- height of the rectangle, Number
Returns
- [Body] an array of Bodies, will return an empty array if none found
Parameters
- x x coordinate, Numbery
- y coordinate, Number
Returns
- [Body] an array of Bodies, will return an empty array if none found
Parameters
- x x coordinate, Numbery
- y coordinate, Number
Returns
- [Body] an array of Bodies, will return an empty array if none found
---
Parameters
- x x coordinate, Numbery
- y coordinate, Numberwidth
- width of the rectangle, Numberheight
- height of the rectangle, Number
Returns
- Body
Parameters
- x x coordinate, Numbery
- y coordinate, Numberfilter
- Function(body, collision, goalX, goalY)body
- the body that the check has been run on.collision
- the collision currently in progressgoalX
- x position of where the body is headedgoalY
- y position of where the body is headed
Returns
- finalX the final x resting spot after collisionsfinalY
- the final y resting spot after collisionscollisions
- all of the collision data from collisions that happened along the way
but without changing the body. This is good for checking before moving.$3
Returns the distance from one body to another---
Example
Try out the example by running npm i && npm start in the example directory and
then opening http://localhost:8080`
import {World, Body} from 'bopit'
const world = new World(32)
const body = new Body(120, 120, 20, 20)
body.add(world)
const wall1 = new Body(100, 100, 400, 10, true)
wall1.add(world)const [finalX, finalY, collisions] = body.move(body.x - 10, body.y - 10)
`Thanks to
-
kikito` https://github.com/kikito/bump.lua for writing such an awesome library