Loopsie
Loopsie allows you to quickly build and prototype simple games, by providing both a game loop and a simple state management system.
It does not have any opinion in regards to the visual output. Instead, clients can subscribe to state changes and handle them however they see fit.
Loopsie can be used in both node and the browser.
It also is fully TypeScript typed.
Getting started
Installation
To install Loopsie, simply add it using your package manager of choice:
npm install loopsie
or
yarn add loopsie
Your first game loop
import { GameLoop, perSecond } from "loopsie";
const initialState = {
score: 0,
height: 100
}
const gameLoop = new GameLoop(intialState, {
msPerUdate: 10
maxFPS: 30
})
gameLoop.addCallback((delta, state) => {
return {
height: state.height - perSecond(10, delta),
score: state.score + perSecond(1, delta)
}
})
gameLoop.addCallback((delta, state) => {
if(state.height >= 0) {
gameLoop.stop();
}
})
window.addEventListener("click", () => {
gameLoop.addRunOnce((delta, state) => {
return {
...state,
height: state.height + 3
}
})
})
gameLoop.start();