A Simple Game Loop Written in C & SDL1 running in the browser thanks to WebAssembly binding it to an HTML5 canvas.
Live demo: https://rafaeletc.github.io/wasm-sdl-gameloop
-
Install Emscripten:
https://emscripten.org/docs/getting_started/downloads.html -
Clone the repository:
git clone https://github.com/rafaeletc/wasm-sdl-gameloop
cd wasm-sdl-gameloop -
Run
make build-wasmor build manually:
emcc src/*.c -s WASM=1 -s USE_SDL=2 -o public/index.js -
Browsers doesn't support file XHR requests so you need to open index.html from a web server.
Runmake run-wasmor manually:
emrun public/index.html -
🕹️ Use the keys ⬅️ and ➡️ to move the paddle, key R to start again.
-
You can run on terminal too, with compiler and SDL2 dependencies on place, just hit
make build; make run
- Improve Makefile
- Better physics for the game
- Build a game interface for pontuation
- Add a game start scene
- Add a game over scene
Footnotes
-
Game design taken from Pikuma's Creating a Game Loop with C & SDL (Tutorial) ↩
