A 1D pacman game, inspired by paku paku, implimented with a subset of RxJS, roughly equivalent to Conal Elliott's original FRP formulation.
The game's state is calculated as a pure function of time (animationFrames) and space presses, with the only side-effect being the actual drawing of the canvas.
The shape of the game's state:
{
playerX: number,
ghostX: number,
dots: { x: number, magic: boolean, eaten: boolean }[],
isMagicOn: boolean,
isBlinking: boolean,
score: number,
isGameOver: boolean,
text: string
}
The game is hosted at https://63r6o.github.io/frp-pacman/.
If you'd like to run it locally, clone the repository, npm install
the dependencies then run the dev server with npm run server
.
└── src/
├── index.html // the html page with the canvas
├── index.js // the observable streams calculating the state of the game
├── rxjssubset.js // the "white-listed" functions of RxJS
└── utils.js // functions related to position calculations and drawing