@justcoding123/kacomps
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

KaComps

A utility library for making type-safe KAPLAY components.

Installation

npm i @justcoding123/kacomps

Examples

Basic

const Person = defineComp("person", (_, name: string) => {
    return { name };
});

const Greeter = defineComp("greeter", ({ require }) => {
    const person = require(Person);
    debug.log(`Hello, ${person.name}!`);
});

add([Person("World"), Greeter()]);

A bit more complex

const Entity = defineComp("entity", ({ self }, _static?: boolean) => {
    self.use(k.body({ isStatic: _static ?? false }));
    self.use(k.area());
});

const Patrol = defineComp("guard", ({ require, on }, speed: number, patrolArea: number) => {
    require(Entity);
    const body = require(k.body);
    const position = require(k.pos);
    const start = position.pos.clone();
    let direction = 1;

    on("update", () => {
        if (body.isFalling()) return;

        if (direction === 1 && position.pos.x > start.x + patrolArea) direction = -1;
        if (direction === -1 && position.pos.x < start.x) direction = 1;

        position.pos.x += speed * direction * k.dt();
    });
});

Readme

Keywords

none

Package Sidebar

Install

npm i @justcoding123/kacomps

Weekly Downloads

0

Version

0.0.4

License

ISC

Unpacked Size

5.04 kB

Total Files

4

Last publish

Collaborators

  • justcoding123