npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kaplay-beta

v3001.0.0-alpha.20-b1

Published

KAPLAY is a JavaScript library that helps you make games fast and fun!

Downloads

4

Readme

KAPLAY

KAPLAY

KAPLAY is a JavaScript library that helps you make games fast and fun!

Start playing around with it in the KAPLAYGROUND

Examples

// initialize context
kaplay();

// 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();
});

KAPLAY 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

// .onCollide() comes from "area" component
player.onCollide("enemy", () => {
    // .hurt() comes from "health" component
    player.hurt(1);
});

// check fall death
player.onUpdate(() => {
    if (player.pos.y >= height()) {
        destroy(player);
        gameOver();
    }
});

// if 'player' onCollide with any object with tag "enemy", run the callback
player.onCollide("enemy", () => {
    player.hp -= 1;
});

// all objects with tag "enemy" will move towards 'player' every frame
onUpdate("enemy", (e) => {
    e.move(player.pos.sub(e.pos).unit().scale(e.speed));
});

// move up 100 pixels per second every frame when "w" key is held down
onKeyDown("w", () => {
    player.move(0, 100);
});

Usage

Start a Project With create-kaplay

The fastest way to start a KAPLAY game is with create-kaplay

$ create-kaplay 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

Install as NPM Package

$ npm install kaplay
import kaplay from "kaplay";

kaplay();

add([
    text("oh hi"),
    pos(80, 40),
]);

also works with CommonJS

const kaboom = require("kaplay");

Note that you'll need to use a bundler like esbuild or webpack to use KAPLAY with NPM

Browser CDN

This exports a global kaplay function

<script src="https://unpkg.com/[email protected]/dist/kaboom.js"></script>
<script>
kaplay()
</script>

or use with es modules

<script type="module">
import kaplay from "https://unpkg.com/[email protected]/dist/kaboom.mjs"
kaplay()
</script>

works all CDNs that supports NPM packages, e.g. jsdelivr, skypack

Documentation

  • v3001: https://kaplayjs.com/
  • v3000: https://kaboomjs.com/
  • v2000: https://2000.kaboomjs.com/
  • v0.5.0: https://legacy.kaboomjs.com/

Community

Games

Collections of games made with KAPLAY (and Kaboom), selected by KAPLAY:

Credits