AstralX: a 2004 phone game, running in the browser in 2025
We wrote AstralX for Java ME phones in 2004. In 2025 we ported it to .NET 9 and WebAssembly. The runtime changed completely; the game logic and its state machines barely changed.
The first Java source files for AstralX carry a header from November 2003 and a note that they were created in Nokia's developer suite for J2ME. The game shipped in 2004 as the first Mobstar Games title: a Galaga-style shooter for Java ME phones, with 40 levels and boss fights, published by Telcogames in MIDP1 and MIDP2 builds.
In 2025 we brought it back. Not as an emulator running the old binary, but as a fresh C# engine on .NET 9, compiled to WebAssembly and running in a browser tab at the original 176×208 screen size.
This is a story about legacy code, really. Most organisations have a system like AstralX somewhere: logic that still works and is still valued, sitting on a platform that has gone away. The port showed us, in miniature, what to keep and what to replace.
The constraint: same game, entirely different platform
The 2004 game ran on phones with tiny heaps, slow processors and no floating-point unit worth relying on. It used integer maths and lookup tables for trigonometry, fixed-point numbers for movement, and the MIDP canvas for drawing.
The 2025 target was the opposite: a browser with a garbage-collected .NET runtime compiled to WebAssembly, a JavaScript event loop, and an HTML canvas. Different language, different memory model, different timing, different input.
We set three rules for the port:
- Keep the behaviour. Enemies should fly the same curves, attack in the same patterns and feel the same to play.
- Keep the resolution. 176×208, scaled up with whole pixels, not redrawn for a modern screen.
- Replace the runtime cleanly. No compatibility shims pretending to be a phone. A small, modern engine underneath.
Architecture
browser requestAnimationFrame (JS)
-> [JSExport] RenderLoop(deltaTime, keys, mouse) (C#, WebAssembly)
-> GameManager.Update -> LevelManager.Update(sprites)
-> software blit of every sprite into a native int* buffer
<- RGBA bytes as a memory view
-> paint to <canvas>, scaled to fit - JavaScript owns the clock. A small module of under 200 lines runs
requestAnimationFrame, tracks keys and the mouse, and calls into .NET once per frame with the elapsed time. - C# owns the game. A
Spritebase class (position, velocity, bounding box, frames, layer), aSpriteManagerfor ordered drawing and collision queries, and aLevelManagerof almost 900 lines for waves, bosses and level flow. - Rendering is software. Every sprite is copied pixel by pixel into one frame buffer. The canvas only ever receives a finished frame.
- Assets are code. A small converter turns every PNG into a generated C# struct holding its pixels, so nothing is decoded at run time.
- Deployment is a container. A Dockerfile and compose file publish the release build and serve it.
The engineering
1. One native frame buffer, owned by the engine
The engine allocates its frame buffer once, outside the managed heap, and clears it each frame:
_canvasImage = (int*)NativeMemory.AllocZeroed((UIntPtr)(Width * Height), sizeof(int)); Sprites draw into it with unsafe pointer code, skipping transparent pixels:
var pixel = span[(spriteImageY + y) * SpriteImage.Width + spriteImageX + x];
if (pixel != 0)
renderBuffer[(screenY + y) * renderBufferWidth + screenX + x] = pixel; That is almost exactly how the original drew on a phone, and how we drew on handhelds before that. A small software renderer is predictable: no driver, no GPU state, and the same output on every browser.
It isn't perfect, and we'd rather say so. The exported RenderLoop still allocates a new byte array each frame and walks every pixel to set the alpha channel before handing it to JavaScript. At 176×208 that costs very little, but it is the first thing we would change: keep a reusable output buffer and write opaque pixels in the first place.
2. A port you can trace line by line
Each C# class mirrors a Java original. EnemyDroid.cs sits beside EnemyDroid.java; the same state constants, the same method names, even the original "TODO" notes where a line wasn't ported yet. Here is the start of one state in each language. First the 2004 Java:
private void DoStateLoopLeft()
{
if(CheckForBreakAway())
{
SetState(6);
if(m_difficulty < 2) { m_fireCnt = 99; }
return;
}
loop(m_loopi>>8);
...
m_loopi-=((32768*CookieJar.m_dt)>>8); And the 2025 C#:
private void DoStateLoopLeft(float deltaTime)
{
if (CheckForBreakAway())
{
SetState(ENEMY_STATE_ATTACK_RIGHT);
if (_difficulty < 2) { _fireCnt = 99; }
return;
}
Loop(_loopRadians);
...
_loopRadians -= (LOOP_SPEED * deltaTime); The structure is identical. What changed is the number representation. The Java tracks the loop angle as a fixed-point integer and shifts it down to index a sine table, because a 2004 handset couldn't afford floating point. The C# uses float radians and the elapsed time from the browser. Magic numbers like SetState(6) became named states.
Keeping the shape the same is a deliberate trade-off. It makes the port slower to modernise, but every behaviour can be checked against the original by reading two files side by side. For a game, that means it plays the same. For a business system, it means you can prove the new version does what the old one did.
3. Assets compiled into the build
The converter reads each PNG with ImageSharp and writes a C# struct:
contents.AppendLine($"public struct {className}SpriteImage : ISpriteImage");
contents.AppendLine("{");
contents.AppendLine($"\tpublic readonly int Width => {image.Width};");
contents.AppendLine($"\tpublic readonly int Height => {image.Height};");
contents.AppendLine("\tpublic readonly int[] ImageData => ["); The result is about 4,700 lines of generated pixel data beside about 2,300 lines of hand-written engine and gameplay code. It is an old console habit: when the platform is constrained, move work from run time to build time. Here the constraint was start-up time and simplicity. There's no image loading, no async asset fetches and nothing to go missing on a slow connection.
Where AI fits
AstralX's intelligence is classic game AI, and it survived the port unchanged. Each enemy is an explicit finite-state machine: entry, loop left, loop right, retreat, spot-sit and attack left or right. Difficulty parameters shape the attack curves.
The interesting state is spot-sit. An enemy in that state does nothing. It is waiting, in the original comment's words, "for a command to attack". The decision about who attacks and when sits one level up, in the level manager, which coordinates the whole wave. Individual enemies stay simple; the group behaviour comes from a coordinator. You can read more about that era's game AI in Game AI before AI.
That split still shows up in how we build AI systems now. On the Knowby platform, the step that turns a video into a draft guide doesn't hand everything to one model. It runs an explicit ladder of strategies (speech, then on-screen captions, then scene changes, then a vision-language model), records why each one ran or was skipped, and falls through to the next if one fails. Models do the perception. A plain, readable state machine decides what happens next. When something goes wrong, you can see exactly which state it was in.
What it taught us
- Separate what the system does from what it runs on. AstralX's rules and state machines were worth keeping. Its MIDP runtime wasn't. A good port protects the first and replaces the second cleanly.
- Keep traceability during a migration. Mirroring the original's structure, names and even its TODOs made the port checkable. You can modernise after you have parity.
- Write the tool. A short image converter removed a whole category of run-time work. Small tools that turn assets or data into code are often the highest-leverage part of a port.
- Be honest about the rough edges. The per-frame allocation is known, small at this resolution, and on the list. Knowing exactly where the debt is matters more than pretending there is none.
We did the same with Magic Clouds, our other 2004 phone game, which we rebuilt in Unity in 2023 with the original Java kept alongside as a reference. Same lesson: the twenty-year-old logic still held up, and having it on hand made the new version faithful.
Why it still matters
Every organisation has an AstralX: a system whose logic is sound but whose platform is ending, whether that's an old desktop app, a retired mobile framework or a server nobody wants to patch. The approach is the same at any size. Keep the behaviour, prove parity, replace the runtime and move work to build time where you can. If that's the job in front of you, our integrations and legacy page explains how we take it on, and the Mobstar Games story has the rest of the 2004 catalogue.