Flight! We have Flight!
25-08-2026
So, about that Pascal compiler...
A few days ago I introduced wasmpascal: a Pascal compiler that runs entirely in the browser and compiles your source to WebAssembly. I said it was early days, that there was a lot of Pascal functionality still missing, and that I'd keep updating the compiler as I tried out old programs. I did not, however, realise that I'd spend the weekend writing a basic flight simulator.
Because that's what happened. wasmpascal is now at v0.3.0, and the examples folder has a new addition: Flight Leader, an arcade-style space-combat game written in Pascal, compiled by wasmpascal, with you flying around in your browser. There's also a brand new export pipeline that turns any compiled Pascal program into a standalone web app you can host anywhere.
Flight Leader
Flight Leader is a keyboard-only space combat sim in the tradition of games like Elite and Star Raiders, except, you know, written in Pascal. You get a first-person view of space, and it's your job to defend the sector against three waves of increasingly hostile company:
- Wave 1: a squadron of nimble fighters, inbound and eager to ruin your day.
- Wave 2: a gunboat with a lot more hull and a lot more firepower.
- Wave 3: a capital ship. Big. Slow. Angry. Bring missiles.
The controls are about as old-school as it gets. Arrow keys yaw and pitch, W/S work
the throttle with Shift for the afterburner, hold Space for the twin lasers, and
Tab fires homing missiles, once you've acquired a lock, that is, and the lock goes beep.
Your enemies aren't just sitting ducks either: their AI runs the full gamut from inbound to attack, with
evasive manoeuvres, tactical retreats, and capital-ship escort behaviour. You've got shields that recharge
(after a decent delay, of course), hull integrity, a radar so you can find the enemy, and a debrief at the
end of the mission that rates your performance. Rookie, Officer, Captain... Ace, if you're very, very good.
It's a neat little flight model, written in good old Pascal! The simulation has position, velocity, rotation and a camera transform (player position, yaw, pitch) projects everything to the screen with perspective. The starfield has 320 stars across three parallax layers, ships are drawn as projected polygon shapes with the player's ship sporting an engine glow, laser and missile streaks trace across the void, and when something explodes you get the classic DOS treatment: 2D screen-space particles, debris shards, expanding shockwave rings, and camera shake.
The game consists of six units: fldefs (shared state and host imports),
flmath (3D vector math, a xorshift RNG, world-to-screen projection), flbatch
(the batch command buffer and canvas wrappers), flfx (explosion effects), flsim
(flight model, weapons, enemy AI, waves, scoring), and flrender (starfield, ships, HUD,
radar, overlays).
Writing a game in your own compiler is the fastest way to find out what the compiler sucks at, and I found so much, sigh. But that's also the fun part, right? The compiler gets better, sometimes, and other times, there's git revert! Hopefully you'll enjoy the next feature - downloading your game in a compiled state.
Take it with you: export features
The other big change is that wasmpascal is no longer just a playground. The Download...
menu in the toolbar now has four options, and they cover the full journey from "I just compiled this"
to "I'm hosting this on my own site":
- Compiled .wasm: just the WebAssembly module, if that's all you need.
- Project .zip: the entire project: the root program plus every
usesunit, all your source, in one archive. - Standalone app (.zip): a complete, ready-to-host folder: a runner
index.html, the runtime (runtime.js,worker.js, and thepascaldom.js/batchiness.jsbridges), your compiled.wasm, and a README. Upload the folder to any static web server and it just works. No build step, no dependencies, no wasmpascal required. - Standalone app (.html): the same thing as a single self-contained HTML file with everything inlined. This one opens straight from disk, no server at all.
Canvas and game programs (pascaldom, batchiness, basic_canvas ABIs) run on any static host, no special
headers needed: keyboard, mouse, audio, and canvas all work. Console programs get the full Pascal
experience: inline readln input bar, Delay game pacing, ReadKey,
infinite game loops, when the page is served with cross-origin isolation headers (that unlocks a
SharedArrayBuffer worker); the README has nginx and Netlify examples. There's also an
Upload .pas files button now, so you can grab Pascal source from your own hard drive,
drop it in, and rebuild the project, the file that declares program automatically becomes
the root. You can change this, because, yeah, sometimes it gets it wrong.
So the workflow is now: write Pascal, compile it in the browser, and export your own little web app, perhaps a game you can send to a friend, a tool you can drop on your site, a console program you can host for your own nostalgia. All generated by a compiler that runs in the browser. Bonkers!
Go fly something
Point your browser at https://wasmpascal.com/,
open the examples dropdown, load flightleader.pas, and hit Run. Do the tutorial waves first...
The title screen tells you the controls, then take on all three waves and see what rank you walk away with.
Return to the blog index