I built a Wolfenstein-style game in one file.
It is a finished 3D shooter, not a “raycaster in 200 lines” gist. There are three levels and a boss fight, soldiers that flank you, colored lighting, iron-bar doors you can see the goal through from across the map, an animated night sky, three weapons, quality presets, positional sound, and collision that keeps the player, the soldiers and the boss from ending up inside walls. It runs at 60 FPS at 800×600 and is about 7,000 lines of GX.
The same source builds a native program for Windows, Linux and macOS, and with one flag it runs in the browser. There is no engine, no scene graph, no ECS framework, and no art for the walls. It is typed arrays, match statements, a hand-written DDA raycaster, and direct calls into raylib through GX’s C interop.
This post is the tour. The Wolfenstein Showcase doc goes through every system in detail. Here I cover the parts that surprised me, the parts I’m proud of, and the parts that I think say something about what GX is for.
Why Wolfenstein
Some personal background first, because it explains the choice.
I grew up on a Commodore 64, then a ZX Spectrum. Eventually the family got a beige PC running DOS, and that’s where it all opened up: Wolfenstein 3D, DOOM, Duke Nukem 3D, Quake. Those games were the first time I understood that software could be art, that a few people, sometimes one, could build a whole world out of integer math and a 320×200 framebuffer. I had no idea what a raycaster was. I only knew that the corridors felt real, the doors went whoosh, and somebody had worked out how to make a 486 do that.
Thirty years later I’m building a programming language. When it was time to show that the language could carry a real project, something bigger than fizzbuzz or a triangle, Wolf3D was the obvious choice, for three reasons.
It means something to me. It is the game that made me want to write games. Coming back to it felt right.
It is the right size for now. Wolf3D is a DDA raycaster with sprites, doors and AI: well-understood systems on top of a graphics library, a weekend’s worth of work. DOOM, the natural next step, is a much bigger job, with BSP trees, varying floor and ceiling heights, real level geometry and an editor pipeline. That’s a project; Wolf3D is a stress test. I’m still adding features to GX, so I needed something I could finish, not something that would take a year while the language changed underneath it.
It uses everything that matters. A raycaster touches the type system (typed pixel buffers, distinct integer widths, no implicit conversions), the C ABI (raylib does all the graphics, input and audio), control flow (match for tiles and state machines), memory layout (no malloc in the main loop, static arrays everywhere), compile-time code (#if (@os == "web") for the WASM port) and the build (one flag for native or browser). If GX could carry Wolfenstein cleanly, the design decisions I had made so far were holding up.
A DOOM remake is on the list. But I needed Wolf3D first: to test the language, to get through the engine work I already understood, and to scratch an itch I’ve had since I was ten, typing WOLF3D.EXE at a DOS prompt and watching that pixelated brick wall go by.
This post is what came out of it.
Two commands
gx projects/wolfenstein.gx -I modules -O2 -o wolf.exe # native, ~3s build with TCC
gx projects/wolfenstein.gx -I modules --target web -o wolf.html # wasm in your browser
Same source, same modules, same import "raylib". The only web-specific code in the 7,000-line file is one #if (@os == "web") block of about five lines, which clamps the mouse delta to work around a Chrome quirk. Because #if is resolved while compiling, the native binary does not contain that branch at all.
The project is wolfenstein.gx plus a data/ folder of sprite PNGs. There are no level files; the maps are string literals. There is no art for the walls; wall textures are generated at startup from a hash function. That is what “single file” means here.
The stack
| Layer | Choice |
|---|---|
| Language | GX through the C backend (default) or @backend("llvm") |
| Graphics / input / audio | raylib, called directly through extern fn |
| Native build | bundled TCC (~410 ms clean) or clang with -O2 (~425 ms) / -O3 (~445 ms) |
| Web build | --target web, then emscripten, then wasm |
| Memory | static arrays, no malloc in the main loop |
| Assets | procedural walls, sky and floor; PNG sprites for entities |
That is all of it. There is no engine layer between the game and raylib’s C ABI, because raylib’s calling convention is GX’s calling convention. When the source says DrawTexturePro(...), that is the raylib function itself, called with the same arguments and the same cost as from C.
About the backends, since I want to be clear about where the language stands. Today there are two paths: GX to C (the default, with the bundled TCC for fast iteration and clang or gcc for release builds) and GX to LLVM IR text (a .ll file that clang finishes). Both work end to end, both produce real binaries, and both build Wolfenstein. They are the right tools for now. I’m still finishing the language for 1.0 (compile-time code, modules, allocators, vectors, GPU compute), and emitting C and LLVM IR text gets me there without splitting my attention. Once the language settles, the next step is proper LLVM integration: linking the LLVM C++ API, owning the IR module and running our own pass pipeline instead of going through text. That comes after 1.0. The output will be the same; the route to it gets shorter.
Update (May 2026): The LLVM integration described above arrived before 1.0, sooner than I expected.
--backend=llvmnow links libLLVM directly, builds the module withIRBuilderinside the compiler, runs the verifier and the-O0to-O3pass pipeline itself, and emits DWARF debug info. The text path is still available as--backend=llvm-clangfor setups where you don’t want libLLVM linked into GX.
Maps are strings, and the parser is a match
Each level is a 32×32 grid of characters. Digits are walls, dots are floor, letters are entities.
const g_map_level1: str[32] = {
"11111111111111111111111111111111",
"1P....O1..r2....3...K....b3.S.A1",
"1...L..1...2.S......3.S......3A1",
// ...
}
The level editor is your text editor. Diffs are readable, and there is no binary file to fight over in a merge.
The parser is one match over each character:
match (ch) {
46: { g_map[idx] = 0 } // '.' floor
49..54: { g_map[idx] = (i32)(ch - 48) } // '1'-'6' wall texture
80: { g_map[idx] = 0; g_px = ...; g_py = ... } // 'P' player spawn
76: { /* L medium torch — set color, intensity, radius */ }
108: { /* l candle */ }
75: { /* K brazier */ }
// ... 30+ tile kinds ...
}
GX’s match has range patterns (49..54), arms with several lines, and a default arm. Next to a C switch with its case and break, or a chain of if/else, the parser reads like a table rather than a list of conditions. A new tile is one more arm.
Switching levels means copying the rows of g_map_level2 or g_map_level3 into g_map_data and running init_map again. That is the whole level system.
Lighting: three buffers and one function
Lighting is the deepest system in the game, and also the cleanest. There are three layers, and every renderer reads them through the same function.
Static lightmap. g_lightmap_r/g/b: f32[1024], one RGB value per cell, computed when the level loads. Each light adds intensity * (1 - (d/r)²) to every cell within its radius, scaled by its color.
Occlusion. Each light-to-cell contribution is checked with a DDA ray from the light to the cell. Walls block light, iron bars don’t, closed doors do and open doors don’t, so the lightmap always matches the current layout.
Dynamic lights. g_lightmap_dyn_r/g/b: f32[1024], cleared and rebuilt every frame. Exploding barrels, burning barrels, the boss (which gets a flickering fire at its feet when its health is low) and rockets in flight all write here. A rocket flying down a corridor lights the walls as it goes.
Everything reads through this:
sample_light(world_x, world_y)
// → fills g_light_r, g_light_g, g_light_b
// = bilinear blend of (static + dynamic) over 4 surrounding cells,
// with walls forced to AMBIENT to prevent bleed
The floor renderer, the wall renderer and every sprite call it, and the minimap reads the same arrays. Adding a colored light to the world means setting one array entry. Every part of the renderer depends on that one function and nothing else.
Lighting each side of a wall
A wall has two faces but its cell has one brightness. Using that value for both faces lights a wall on both sides even when the torch is only on one. The fix is one line:
// Sample the floor neighbor on the side the ray hit, not the wall itself
if (g_ray_side == 0) { lnx = lnx + (rdx > 0 ? -1 : 1) }
else { lny = lny + (rdy > 0 ? -1 : 1) }
sample_light(lnx + 0.5, lny + 0.5)
Now a wall between a lit room and a dark corridor is bright on the room side and dim on the corridor side, with no per-face data. It is a small fix, and it is the one that stopped the game looking like a raycaster demo.
Doors that open and let light through
I said the lightmap is computed once per level. That is nearly true; doors are the exception. Getting doors and light to work together took a surprisingly large part of an afternoon, and it became one of my favorite parts of the engine.
The rule is that light passes through an open door and not through a closed one. The hard part is deciding when the lightmap updates. Recomputing every frame is too much: about 30 µs each time sounds cheap, but multiplied by 60 frames and every animating door it adds up. Never recomputing leaves the corridor dark behind a wide-open door. It should be recomputed exactly when the layout changes.
That is done with a 50% threshold and an edge check:
var now_blocking = (g_door_timer[i] < 0.5)
if (was_blocking != now_blocking) { lightmap_dirty = true }
if (lightmap_dirty) { compute_lightmap() }
That gives two recomputes per door cycle: one as the door passes half open while opening, one as it passes the same point while closing. If several doors cross the mark in the same frame, the dirty flag merges them into one recompute. The whole feature is about 20 lines of GX, half in the DDA blocking check and half in the threshold check.
Why 50%, and not 0% or 100%. I settled on it by trying the alternatives:
- It matches what you see. The door slab slides from solid wall to empty doorway. At 50% it looks half open, which is when a player expects light to start coming through. At 0%, while it still looks shut, the change feels early; at 100% it feels late.
- Opening and closing behave the same. One threshold for both directions means the light changes at the same visual point each way. Two thresholds would make opening and closing feel different.
- One change per direction. The animation only moves one way at a time, so the timer crosses 0.5 once when opening and once when closing. The
was_blocking != now_blockingcheck cannot fire twice.
What light coming through looks like. When a door opens, light_blocked_by_wall() stops blocking the torch on one side from the cells on the other. The cells of the dark corridor now get light from the torch in the room, intensity * (1 - (d/r)²) over distance, like any other light. The walls next to those cells pick up the brightness in the second propagation pass, so the corridor walls brighten on the side facing the door. The floor renderer (one sample_light() per pixel) and the sprites (one sample each) see the change on the next frame. There is no door-specific lighting code anywhere downstream. Closing the door reverses it: the corridor goes dark again, and a soldier standing in it loses the torch’s tint halfway through the animation.
The threshold also limits how long light and picture can disagree. At DOOR_SPEED = 3.0 the slab takes about 150 ms to pass through the region around the threshold, so a player never sees more than that of “the door looks half open but the light still treats it as closed”, or the reverse. That is short enough to read as one moment. With slower doors the mismatch would become visible: the room would brighten before the door finished opening, and it would feel wrong to players who couldn’t say why.
The iron-bar exception is one line, if (cell_v != 14) in light_blocked_by_wall(). Changing one condition gave the game a new kind of object.
Iron bars: the see-through door
The classic Wolf3D doors are flat slabs in the middle of a cell that slide open on a timer, and the GX version handles them the usual way. There is also a fifth door type I’m proud of: iron bars.
An iron-bar door:
- opens with the red key, like a locked door;
- never blocks light, so the alcove behind it is lit properly;
- is recorded per column during
cast_ray, after which the DDA keeps going to the real wall behind; - is drawn by a separate
draw_iron_bars_overlay()after the sprites, with alpha-cut transparency.
So from across the level you can see the goal. The V badge sits in an alcove behind iron bars, lit by its own torch, and you can see it as soon as you turn the corner. The player knows where to go, and the engine needed no special case for it.
while (depth < 64) {
var wall: i32 = get_map(map_x, map_y)
// 1-6 walls: solid hit, return
// 10-13 doors: zero-thickness slab at midline
// 14 iron bars: SEE-THROUGH — record bars info, KEEP STEPPING
// ...
}
The DDA doesn’t stop at bars, it only records them, and that is the whole trick. It is five lines in the renderer, and the level designer gets a new tool.
The per-pixel floor
The floor is lit per pixel. Every visible floor pixel calls sample_light() at its world position and combines fog, base color and the light for each channel. At the highest quality preset that is 240,000 pixels per frame.
const FLOOR_TEX_W = 800
const FLOOR_TEX_H = 300
var g_floor_pixels: u32[240000] // CPU pixel buffer
var g_floor_tex: Texture // GPU side
fn draw_floor() {
for (yy = 0 : FLOOR_TEX_H - 1) {
var row_dist: f32 = posZ / p_f
var wx_step: f32 = row_dist * (cos(right) - cos(left)) / SCREEN_W
for (xx = 0 : SCREEN_W - 1) {
sample_light(wx, wy)
var packed: u32 = (u32)rr | ((u32)gg << 8) | ((u32)bb << 16) | ((u32)255 << 24)
g_floor_pixels[row_base + xx] = packed
wx += wx_step; wy += wy_step
}
}
UpdateTexture(g_floor_tex, &g_floor_pixels[0])
DrawTexturePro(g_floor_tex, ...)
}
cosf and sinf run once per frame, at the edges of the field of view. The world position changes linearly along each row, so the inner loop is a few additions, a bilinear sample and packing a u32. The pass takes about 2 ms at medium quality, roughly 432 MFLOPS, which any current machine handles easily.
This is the part of the game that shows what GX is for. There is no inline assembly, no SIMD intrinsics and no unsafe block. It is plain GX, compiled through C and optimized by clang. The pixel-packing line needs its (u32) casts because GX doesn’t promote integers silently, so no platform can come up with different values. The floor keeps its own u32[240000] buffer and hands it to the GPU in one UpdateTexture call, with no conversion, no Image copies and no allocation per frame.
Procedural textures
Every wall texture is generated at startup from a hash function:
fn gen_texture_brick:Texture() {
var img: Image = GenImageColor(TEX_SIZE, TEX_SIZE, BLACK)
for (y in 0..TEX_SIZE-1) {
for (x in 0..TEX_SIZE-1) {
var brick_id = (bx / 16) * 13 + row * 7
var brick_tone = hash(brick_id, 0, 31) % 30
// mortar lines, bevels, noise
ImageDrawPixel(&img, x, y, color)
}
}
return LoadTextureFromImage(img)
}
Stone, metal, wood and moss work the same way, as do the doors (the classic Wolf3D blue panel with a steel frame and a gold keyhole), the iron bars (alpha-cut) and the night sky (a 4096×256 panorama with about 600 stars and a moon).
The output is deterministic: the same input gives the same textures on every run, so screenshots reproduce and every tester sees the same map. There are no image files changing in source control. The art pipeline is six functions in the same file as the game.
AI in 80 lines
Soldiers have a state machine (IDLE, TARGET, SHOOT, RUN, HURT, DYING, DEAD), and when chasing they pick one of two modes each frame:
LOS clear? ──yes──▶ zigzag straight at player (no planner)
──no───▶ have we ever seen the player?
──yes──▶ BFS to last-seen, walk first step
──no───▶ drop to IDLE
If the soldier can see the player, no planner is needed: the line of sight is also a walkable path, and a sin(zigzag_phase) * 0.6 side-to-side motion makes the soldier harder to hit. When the player goes round a corner, the soldier remembers (last_x, last_y) and finds a path there with BFS.
The planner is a textbook breadth-first search over the 32×32 grid:
var g_bfs_visited: i32[1024]
var g_bfs_parent: i32[1024]
var g_bfs_queue: i32[1024]
fn bfs_next_step:bool(sx: i32, sy: i32, tx: i32, ty: i32) {
// ...zero visited, queue start...
while (head < tail) {
var cur = g_bfs_queue[head]; head = head + 1
if (cur == goal) { found = true; break }
// 4-neighbor expand: filter by pf_passable, mark, enqueue
}
// walk parents back, return the cell whose parent IS start
}
BFS rather than A*. With 1024 cells that all cost the same, computing A*‘s heuristic costs more than the expansions it saves. BFS finds the shortest path and is faster in practice on this grid.
Only the first step. A single waypoint is two integers. A full path would mean keeping an index and an array per soldier and throwing them away whenever a door changes. A fresh BFS twice a second is cheaper and never goes stale.
Cost. The three globals g_bfs_visited/parent/queue: i32[1024] are scratch space, so nothing is allocated. Each soldier plans again every 0.5 s; with a dozen enemies on a busy level that is about 30 searches per second, a few hundred microseconds in total, far inside the 16.7 ms frame.
There is also a stuck check. If a soldier moves less than 0.03 cells in 400 ms, it plans again at once, which breaks the case of two soldiers blocking each other at a corner. The planner also calls enemy_try_open_door() on each waypoint, so the door is already opening when the soldier arrives, and the chase looks smooth.
The most recent addition: soldiers and the boss now use the player’s depenetration function. Before, a soldier would sometimes clip a corner while replanning and end up half inside a wall or another soldier, frozen until the next plan. The player already had a per-frame routine that pushes its box out of walls, so I run the same routine on every living soldier and the boss before they move:
// Before integrating new pos, push the entity out of any wall it
// overlaps toward the nearest passable neighbor.
depenetrate_pos(&g_sol_x[i], &g_sol_y[i], 0.25) // soldier radius
depenetrate_pos(&g_boss_x, &g_boss_y, 0.45) // boss footprint
It uses the same test as the player’s collision, door_occupied() and pf_passable(): one box rule and one depenetration function, called from four places. Soldiers no longer get wedged in doorways, because no entity can carry an overlap from one frame to the next, however busy the fight gets.
The whole AI (seeing, planning, moving, doors, getting unstuck) is about 80 lines of GX. It runs at 60 FPS with dozens of enemies because every cost has a limit. The soldier isn’t really pathfinding in any grand sense; it looks at two pieces of state each frame and walks toward whichever target wins.
C interop without a wrapper layer
extern struct Image {
data: *void
width: c_int
height: c_int
mipmaps: c_int
format: c_int
}
extern fn UpdateTexture(texture: Texture, pixels: *void)
extern fn DrawTexturePro(texture: Texture, source: Rectangle, dest: Rectangle,
origin: Vector2, rotation: f32, tint: Color)
That is the whole binding. The game makes hundreds of raylib calls per frame with no wrapper, no conversion and no FFI cost. The compiler emits DrawTexturePro(...) as a plain C call, and the binary is the same as if the game were written in C.
raylib’s KeyboardKey is declared as an extern enum, so IsKeyDown(KEY_W) compiles to the same code as in C. The build directives (@link, @cflags, @cfile) live in the modules; the game writes import "raylib" and the build takes care of linker flags and web versus native.
I think this is the most underrated part of GX. You can write what would be C code in a nicer language and keep all of C’s interop. The C ABI isn’t an add-on; it is the ABI.
The web port
There is not much to say about the web port, and that is the point. The --target web flag does it. raylib has a web build, and the raylib module picks the right flags with #if (@os == "web"):
#if (@os == "web") {
@cflags("-DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2")
@ldflags("../lib/libraylib_web.a -s USE_GLFW=3 -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1 ...")
}
The game adds one more branch at module level to bundle the data/ folder with emscripten’s preload option, and a custom HTML page that captures the mouse on click and shows a “click to resume” overlay. Inside the game code, the only web-specific part is the 5-line #if block for the Chrome mouse quirk.
The native build is about 1 MB. The web build is about 10.5 MB (1 MB of wasm, 390 KB of JS and a 9 MB asset bundle), about 3 MB gzipped. Same source. The native binary contains none of the web branches and the web build none of the native ones, because #if keeps them out of the generated C.
If you have ever forced emscripten to build a real codebase, you know what “one flag and it works” is worth. It took a lot of work in the compiler, and it keeps paying off.
The numbers
| Metric | Value |
|---|---|
| Source file | projects/wolfenstein.gx |
| Lines | ~7,000 |
| Native exe (TCC) | ~1 MB |
| Web bundle (gzip) | ~3 MB |
| Runtime memory native | < 20 MB peak |
| Frame budget at 60 FPS | 16.7 ms |
| Floor pass (medium 600×450) | ~2 ms |
| Lightmap recompute | ~30 µs |
| Dynamic lightmap (5 lights × 50 cells) | ~2 µs |
| Native FPS (medium quality) | 60 (capped) |
| Web FPS (medium quality) | ~60 typical |
Build times
These are the numbers I like best. Clean rebuilds from start to finish: the GX frontend (lexing, parsing, resolving, type checking, code generation) plus the C or LLVM compiler producing the executable.
| # | Backend | C compiler | Opt | Build time | Exe size |
|---|---|---|---|---|---|
| 1 | C | tcc (bundled) | -O0 | 410 ms | 39,936 B |
| 2 | C | clang | -O0 | 615 ms | 160,768 B |
| 3 | C | clang | -O2 | 425 ms | 160,768 B |
| 4 | C | clang | -O3 | 445 ms | 160,768 B |
| 5 | LLVM | clang | -O0 | 455 ms | 192,000 B |
| 6 | LLVM | clang | -O2 | 565 ms | 175,104 B |
| 7 | LLVM | clang | -O3 | 575 ms | 175,616 B |
A clean rebuild takes under a second, even at -O2 and -O3. With TCC at 410 ms, you change a line, press run, and you’re playing. The slowest path, LLVM through clang at -O3, takes about 575 ms.
The GX frontend alone, everything the language itself does from lexing to emitting C or LLVM IR, is quick on this file:
| Backend | wolfenstein.gx (frontend only) |
|---|---|
C frontend (-S) | 60 ms |
LLVM frontend (-S) | 72 ms |
Sixty milliseconds to lex, parse, resolve, type-check and emit about 10,000 lines of C from a 7,000-line game. The rest of the build time belongs to the C compiler, not to GX. I read that as a sign the language design isn’t slowing anything down: the work GX does is cheap, and the heavy lifting stays with mature C and LLVM toolchains.
This is what lets me stay in flow when I open the editor. It isn’t fast for a language that compiles through C; it’s simply fast.
Lines of GX against lines of C
For the same behavior:
| Metric | GX | Transpiled C | Ratio |
|---|---|---|---|
| Lines | 7,005 | 10,163 | C is ~1.45× larger |
| Non-blank, non-comment | 5,472 | 9,150 | C is ~1.67× larger |
| Bytes | 279 KB | 358 KB | C is ~1.28× larger |
I don’t want to make too much of this. The C side is generated code written to be easy to debug: every if body in braces, every array access expanded into a bounds-checked macro, Allman style throughout. Hand-written C in K&R style would come much closer.
What I take from it is this: for about the same number of lines as careful C, GX gives you match, enums, range loops, strings that know their length, hash maps, bounds checking, and no headers or forward declarations. It isn’t fewer lines. It is more language in the same lines.
What this project says about GX
I started the game to stress-test the language, and I came out of it sure of two things.
The language held up. About 7,000 lines in one file, around 80 functions and 150 globals, and name resolution, type checking and code generation all stayed quick. Forward references work. The 240,000-pixel floor renderer is ordinary GX code with no inline assembly, no intrinsics and no escape hatch. The pixel math has to use explicit (u32) casts, and the type checker caught half a dozen sign bugs while compiling that C would have let through.
The language stayed out of the way. There is no engine layer, no framework with opinions, no DSL. Typed arrays, enums, match and direct C calls. The structure of the game (one sample_light() for everything, one box rule for occupancy and collision, static arrays, one state-machine pattern) came from me, not from rules the language imposed. GX gave me the pieces and trusted me with them.
That trust is what I want most from a language. C trusts you and gives you 1972 tooling. Rust gives you 2026 tooling and doesn’t trust you at all. GX tries to sit in between: it trusts you, and it also lets you match on a u8.
Try it
The game is on the Showcase page. Open gxlang.org/showcase/wolfenstein/ and click the canvas to capture the mouse. WASD moves, Shift sprints, the mouse looks around, Esc releases the cursor, 1/2/3 switch weapons, V stabs and F2/F3/F4 set the quality.
The source is projects/wolfenstein.gx in the GX repo. docs/23_Wolfenstein_Showcase goes through it system by system, including the reasons for each choice and the problems along the way.
If you have wondered whether a language that compiles through C is good enough for graphics work, this is my answer. It’s one file and a real game. It runs fast, builds in under a second, goes to the web with one flag, and the source reads like it was written by someone who ships things.
The kid watching that first brick wall scroll past on a beige DOS machine would not believe how fast this builds. DOOM is next, and that will be a longer post.