JavaScript 游戏库
Replit no longer maintains Kaboom. You may be interested in the community fork KaPlay.
Kaboom is a JavaScript library that helps you make games fast and fun!
Start playing around with it in the Kaboom Playground
// initialize context
kaboom()
// define gravity
setGravity(2400)
// load a sprite called "bean"
loadSprite("bean", "sprites/bean.png")
// compose the player game object from multiple components and add it to the game
const bean = add([
sprite("bean"),
pos(80, 40),
area(),
body(),
])
// press space to jump
onKeyPress("space", () => {
// this method is provided by the "body" component above
bean.jump()
})
Kaboom uses a powerful component system to compose game objects and behaviors.
// add a game obj to the scene from a list of component
const player = add([
// it renders as a sprite
sprite("bean"),
// it has a position
pos(100, 200),
// it has a collider
area(),
// it is a physical body which will respond to physics
body(),
// it has 8 of health
health(8),
// or give it tags for easier group behaviors
"player",
"friendly",
// plain objects fields are directly assigned to the game obj
{
dir: vec2(-1, 0),
dead: false,
speed: 240,
},
])
Blocky imperative syntax for describing behaviors
…
create-kaboomThe fastest way to start a Kaboom game is with create-kaboom
$ npm init kaboom mygame
This will create a directory called mygame for you, containing all the files we need
$ cd mygame
$ npm run dev
Then open http://localhost:5173 and edit src/game.js
$ 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
This exports a global kaboom function
<script src="https://unpkg.com/kaboom@3000/dist/kaboom.js"></script>
<script>
kaboom()
</script>
or use with es modules
<script type="module">
import kaboom from "https://unpkg.com/kaboom@3000/dist/kaboom.mjs"
kaboom()
</script>
works all CDNs that supports NPM packages, e.g. jsdelivr, skypack
npm install to install dev packagesnpm run dev to start dev serverexamples/ to testCheck out CONTRIBUTION.md for full info.
Collection of games made with Kaboom, selected by Kaboom, here.
暂无开放 Issues,或尚未同步最近议题。