THE STUDIO
The PS1 game had distinct screen states.
Not one continuous render — a set of discrete visual configurations, each activated when the game's internal state changed. Main Menu. Studio. Is That Your Final Answer. Right Answer. Wrong Answer. Money Tree. Win. Game Over.




Each state had its own background colour, its own layout, its own content. These are not one screen modified in place — they are different screens entirely, drawn only when the state that owns them is active.


In g01a, tci_printf
was the rendering engine. Every screen state was a different pattern of
ANSI escape codes written to a file descriptor. The game logic —
questions, lifelines, safe levels — was kept separate from the display
deliberately. The display functions knew nothing about game rules; the
game loop called them.
In g01b, SDL2[1] is the rendering engine. The game logic has not
changed a line. The display layer — render.c and font.c — is
entirely new. The separation built into g01a is the reason this swap
is clean.
The c04 pattern — window, renderer, texture, event loop — applies here exactly. The difference is what fills the screen: not iteration counts, but character glyphs rendered from a TrueType font[2] via SDL2_ttf, placed over a solid-colour background loaded from a PNG.
The implementation pages rebuild the display layer on SDL2: the spec and data structures, bitmap font rendering, background loading, the render functions for each game state, and the new event-driven input loop. Start at Setup.
The Rendering Switch
In g01a, tci_printf wrote character sequences to a file descriptor.
ANSI codes coloured them. The whole game was characters at offsets in
a terminal buffer.
In g01b, the character sequences are replaced by SDL2 texture
operations. draw_string calls TTF_RenderUTF8_Solid to render a
string to a surface, uploads it as a texture with
SDL_CreateTextureFromSurface, blits it with SDL_RenderCopy, then
destroys the texture.
The game loop is now an SDL2 event loop — SDL_PollEvent replaces
read(0, &c, 1). The loop runs every frame, calls render_frame(),
and checks for keypress events. The game no longer blocks waiting for
input; it renders between keystrokes.
Platform separation still applies. load.c and the game logic inside
game.c call no SDL2 functions. Only render.c, font.c, and
main.c call into the SDL2 API. The tester compiles the logic without
testing graphical output and states this explicitly — the separation
is the lesson.
The Project
Build the graphical version of the game. Source is split across five files:
| File | Contents |
|---|---|
main.c | SDL2 init, window, renderer; game init; event loop; cleanup |
load.c | load_questions(), free_questions() — unchanged from g01a |
game.c | Game logic: game_init(), game_free(), evaluate_answer(), handle_lifeline(), next_question() |
render.c | render_frame() and all draw_* functions |
font.c | font_load(), font_free(), draw_string() |
The game takes the question file as argv[1], same as g01a:
./game questions.txtRules: identical to g01a — 15 questions per game drawn from a larger bank, safe levels at Q5 (£1,000) and Q10 (£32,000), three lifelines (50:50, Phone-a-Friend, Ask the Audience), walk-away option, win screen on Q15 correct.
Assets: the assets/ directory must contain:
| File | Description |
|---|---|
assets/font.ttf | Px437 IBM EGA 8×14 TrueType font (CC BY-SA 4.0, VileR / int10h.org[3]) |
assets/bg_studio.png | #0a0a2a dark navy — title, question, and confirm states |
assets/bg_correct.png | #0a2a0a dark green — correct answer and win states |
assets/bg_wrong.png | #2a0a0a dark red — wrong answer and game over states |
The Tester
The companion repo contains test.sh. It compiles load.c and the
SDL2-free logic subset of game.c without SDL2 headers, then tests:
question loading, safe-level advancement, lifeline bitfield operations,
and state transitions. Graphical output is not tested; the tester
states this explicitly.
git clone https://github.com/thecodingidiot-com/g01b-the-developer-graphical.git
cp g01b-the-developer-graphical/test.sh ~/g01b-practice/
bash test.shThe Companion Repo
The reference solution is at
github.com/thecodingidiot-com/g01b-the-developer-graphical.
The solution/ directory contains all five source files, a Makefile,
questions.txt (20 questions), the assets/ directory, and test.sh.