Kaboom.js is a JavaScript library that helps you make games fast and fun!
Start playing around with it in the Kaboom Playground
This fork shrink bundle(dist/kaboom.*js) from 18XK to 6XK(removed some images and audio), based on kaboom@2000.x
Examples
kaboom();
loadSprite("froggy", "sprites/froggy.png");
const froggy = add([
sprite("bean"),
pos(80, 40),
area(),
body(),
]);
onKeyPress("space", () => {
froggy.jump();
});
Kaboom uses a powerful component system to compose game objects and behaviors.
const player = add([
sprite("bean"),
pos(100, 200),
area(),
body(),
health(8),
"player",
"friendly",
{
dir: vec2(-1, 0),
dead: false,
speed: 240,
},
]);
Blocky imperative syntax for describing behaviors
player.onCollide("enemy", () => {
player.hurt(1)
});
player.onUpdate(() => {
if (player.pos.y >= height()) {
destroy(player);
gameOver();
}
});
player.onCollide("enemy", () => {
player.hp -= 1;
});
onUpdate("enemy", (e) => {
e.move(player.pos.sub(e.pos).unit().scale(e.speed));
});
onKeyDown("w", () => {
player.move(0, 100);
});
Usage
NPM
$ npm install kaboom
import kaboom from "kaboom";
kaboom();
add([
text("oh hi"),
pos(80, 40),
]);
also works with CommonJS
const kaboom = require("kaboom");
Note that you'll need to use a bundler like esbuild
or webpack
to use Kaboom with NPM
Browser CDN
This exports a global kaboom
function
<script src="https://unpkg.com/kaboom/dist/kaboom.js"></script>
<script>
kaboom();
</script>
or use with es modules
<script type="module">
import kaboom from "https://unpkg.com/kaboom/dist/kaboom.mjs";
kaboom();
</script>
works all CDNs that supports NPM packages, e.g. jsdelivr, skypack
Dev
npm run setup
to setup first time (installing dev packages)npm run dev
to watch & build lib and the website (the website might take some time to build for the first time)- go to http://localhost:3000/play
- edit demos in
demo/
to test - make sure not to break any existing demos
also check out CONTRIBUTION.md
Github Discussions
Discord
Twitter
Misc