Georgi Nikolov

Software Engineer

connect@georgi-nikolov.com
Torstraße 179 / 10115 Berlin / Germany

Snake in WebAssembly

2024
Personal Work

url - https://gnikoloff.github.io/wasm-snake/

code - https://github.com/gnikoloff/wasm-snake

Snake preview

Snake written in WebAssembly Text (WAT) format and compiled to WASM bytecode.

All graphics, game state and logic are written in WAT. Module is loaded in JS (host environment) which is responsible for game tick, user input and random number generator seeding.

The WASM memory consists of 3 virtual pages (64kb each) = 192kb total. Within those exist the pixel buffer, the snake and food positions and the character data. The memory is shared with JS, which then blits it to the screen using WebGL2.

You can refer to src/snake.wat for detailed memory break down and lots of comments.

References and readings