Browser Port Feasibility — Pygbag vs Canvas Rewrite

Evaluating strategies for bringing Pirate Arcade games to the browser: Pygbag/WebAssembly with minimal code changes vs full TypeScript/Canvas rewrite.

The Goal

Each desktop game should eventually be playable in the browser. This post evaluates the approaches and recommends a path forward.

Approach 1: Pygbag / WebAssembly

Pygbag compiles Python + Pygame code to WebAssembly. The existing game code runs almost unchanged inside a browser tab.

Pros

Cons

Changes Needed

For Cannonball Clash (simplest game), the delta is:

# Desktop loop (current)
def run(self):
    clock = pg.time.Clock()
    while True:
        for event in pg.event.get(): ...
        dt = clock.tick(c.FPS) / 1000.0
        self._update(dt)
        self._draw(clock.get_fps())
        pg.display.flip()

# Web loop (changes underlined)
async def run(self):                          # async
    while True:
        for event in pg.event.get(): ...
        dt = clock.tick(c.FPS) / 1000.0
        self._update(dt)
        self._draw(clock.get_fps())
        pg.display.flip()
        await asyncio.sleep(0)                # yield to browser

Replace main() with asyncio.run(main()). Audio files switch extension based on sys.platform. That’s it for the core game.

Approach 2: TypeScript / Canvas Rewrite

Rewrite each game from scratch in TypeScript using the HTML Canvas API.

Pros

Cons

Recommendation: Hybrid (Pygbag for Phase 2, Rewrite for Phase 3)

Start with Pygbag for Cannonball Clash as a feasibility spike. It’s the simplest game, requires minimal code changes, and proves the web delivery pipeline works.

If Pygbag performance is acceptable (60 FPS on mid-range hardware, <10s first load on fast connection), package the remaining three games the same way.

If Pygbag is too slow or the bundle too large, switch to TypeScript/Canvas rewrites starting with Cannonball Clash. The Pygbag work is not wasted — it validates the game logic is correct and gives a reference implementation.

Next Step

Port Cannonball Clash via Pygbag as the feasibility spike. Expected bundle: ~15 MB. Target: 60 FPS, <30 MB total transfer, playable within 10 seconds on a fast connection.