- C 98.7%
- CMake 1.2%
|
All checks were successful
Build and Release WebAssembly Games / build-and-release (push) Successful in 35s
|
||
|---|---|---|
| .forgejo/workflows | ||
| cmake | ||
| src | ||
| .gitignore | ||
| CMakeLists.txt | ||
| LICENSE | ||
| README.md | ||
retro-game-dev
A collection of retro video games I want to make, developed using the Banjo API.
This project also serves as a playground to drive Banjo’s ongoing development and test its features across different targets.
Table of contents
Build for Web
Web builds are powered by the Emscripten WebAssembly framework.
Requirements:
- CMake >= 3.21
- Emscripten SDK
Create a folder for building the project, and change to that directory.
The rest of this guide will assume you are using a .build_web/ folder directly under the root of this project.
For example:
mkdir .build_web && cd .build_web
First, make sure you installed and activated Emscripten:
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd -
Run CMake with Emscripten enabled and build the project:
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release -DBANJO_CONFIG_EMSCRIPTEN_BACKEND=ON
cmake --build . -j
When the build completes, index.html, the .js, and .wasm game files will be in your build directory.
Testing with a local server
Option 1 – emrun (recommended for Emscripten testing):
emrun is included with the Emscripten SDK and automatically sets the correct MIME types for .wasm and .js files.
From your build directory, run:
emrun --port 8000 index.html
Add --no_browser flag to avoid auto-opening of your default browser.
Then visit:
http://localhost:8000/index.html
Option 2 – Python HTTP server (simple, works without Emscripten active):
python3 -m http.server 8000
Then open http://localhost:8000/index.html in your browser.
Build for Linux
To build native Linux executables with ALSA and X11 enabled (always on for Linux builds):
Requirements:
- CMake >= 3.21
- GCC or Clang toolchain
- Development packages for ALSA and X11
From the project root:
mkdir .build_linux && cd .build_linux
cmake .. -DCMAKE_BUILD_TYPE=Release -DBJ_FEATURE_X11=ON -DBJ_FEATURE_ALSA=ON
cmake --build . -j
The compiled game binaries will be in the .build_linux/ folder.
Build for Windows
To build native Windows executables with Win32 and MME enabled (always on for Windows builds):
Requirements:
- CMake >= 3.21
- Visual Studio (MSVC) or MinGW-w64 toolchain
Using Visual Studio (MSVC):
mkdir .build_win
cd .build_win
cmake .. -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DBJ_FEATURE_WIN32=ON -DBJ_FEATURE_MME=ON
cmake --build . --config Release
Using MinGW-w64 (from MSYS2 shell):
mkdir .build_win && cd .build_win
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DBJ_FEATURE_WIN32=ON -DBJ_FEATURE_MME=ON
cmake --build . -j
Binaries will be placed in the .build_win/ folder.
Selecting which games to build
Each discovered game has a GAME_<name> CMake option (default: ON).
To disable building a specific game:
cmake .. -DGAME_pong=OFF
Only enabled games will be built and appear in the index.html game list for Web builds.
Checks
tests/ holds console programs that include a game whole and drive it
without opening a window: the screens are drawn into an offscreen bitmap and
read back pixel by pixel, and the state machine is driven by synthetic
keystrokes. They are not games and do not appear in the index.html list.
They are built by default on native targets and skipped for Web builds:
cmake --build . --target corn_hat_check && ./corn_hat_check
It prints one line per check and exits non-zero if any of them failed. Pass
-v to also print the screens as coarse ASCII and the tables the numbers
came from, which is what to reach for when a check fails and the reason is
not obvious.
Pass -DBUILD_CHECKS=OFF to leave them out.
Drawings
Nothing is loaded from disk. Both kinds of art live in the game source, in
the Data block at the foot of the file.
The four full screens — home, tomb, tavern, win — are lineset tables of
deduplicated endpoints and an index list. They come out of convert.py,
which reads the <line> tags of an SVG and prints the C:
python3 convert.py tavern.svg
The knight and the hundred monsters are sketch tables instead: a flat
array of bytes, four to a stroke, x0, y0, x1, y1, on the sixteen units
draw_sketch scales into whichever cell the figure is standing in. They are
written by hand. bestiary_sketches is indexed by monster kind, so its
order and the order of bestiary have to stay the same.
To see the art without playing, run the game with --show-assets. It walks
every drawing in the game a screen at a time: the four full screens one to a
page, then the adventurer and the hundred monsters in a labelled grid.
ENTER turns the page, LEFT goes back, and ENTER on the last page quits.
./1975_corn_hat --show-assets
The grid draws each sketch at a fair size for editing coordinates, so it is also the way to check that every monster has a drawing of its own, that none is still the placeholder, and that each one sits inside its cell.
Cheats
Corn Hat has a cheat screen, reached with the C key from inside the
dungeon. It hands over any object, moves a floor up or down, gains a level,
refills hits and spell units, reveals the floor, empties it of monsters, or
drops everything carried. O from it opens a list of things, one letter
each.
It exists in a debug build and nowhere else: the code is behind NDEBUG,
which CMake defines for every build type except Debug. A release build
does not contain it, so there is nothing to switch off and nothing to find
in the binary.
cmake .. -DCMAKE_BUILD_TYPE=Debug # cheats
cmake .. -DCMAKE_BUILD_TYPE=Release # no cheats