main = {
k.scene("main", ()=> {
k.add([
k.text("Press space to get funky", { width: k.width() }),
k.pos(12, 12),
]);
const bean = k.add([
k.sprite("bean"),
k.pos(k.center()),
k.origin("center"),
k.scale(1),
k.color(),
k.area(),
// Use our component here
funky(),
// Tags are empty components, it's equivalent to a { id: "friend" }
"friend",
// Plain objects here are components too and work the same way, except unamed
{
coolness: 100,
friends: [],
},
]);
k.onKeyPress("space", () => {
// .coolness is from our unamed component above
if (bean.coolness >= 100) {
// We can use .getFunky() provided by the funky() component now
bean.getFunky()
}
});
k.onKeyPress("r", () => {
// .use() is on every game object, it adds a component at runtime
bean.use(k.rotate(180))
});
})
k.go("main")
}