Browser port of Hedgewars
Hi team,
I have recently tried to port Hedgewars to the browser using WebAssembly.
You can test it out right now at https://webwars.link — hotseat mode works out of the box (two teams, one keyboard, taking turns). Right-click to pick a weapon, Space to fire, Enter to jump, Arrow keys to move. First load pulls ~190MB of game assets, but after that it should be cached and loads should be near-instant (work in progress).
Multiplayer is live too, but also in 'work in progress' mode: try it at https://webwars.link/lobby.html, pick a nickname, create or join a room, and play against someone else.
On the technical side: the engine compiles to WASM through the Pascal → pas2c → C → Emscripten pipeline. I replaced the IPC (Inter Process Communication) protocol with a JavaScript message queue, changed the main loop to not block the only thread available in the browser, and added a sprite batch system to speed up the rendering. Multiplayer runs through the real Hedgewars server — a Node.js WebSocket gateway bridges browsers to the TCP protocol. Fair warning: multiplayer is still buggy, and rendering differs a bit from the original game in places. I'm actively working on fixing all of that. You can find more details on github.
Huge thanks to Wuzzy, nemo, unC0Rr, koda, sheepluva, alfadur and every developer who worked on the project. Thanks to the Hedgewars community for being great. Also, this project wouldn't exist without pas2c — thanks to unC0Rr for writing it. And of course to the team for building a solid game engine that actually survives transpilation to C and then to WASM.
FAQ:
- Does it work on mobile?
- No, I have no idea how to implement controls at the moment
- Why not a pull request to the original project?
- Never thought this would even work, by the time it did, a lot of code was changed, didn't want to break the main repo
- Why the game doesn't work in Safari?
- No idea, just found out about it after posting this message
The full source of this project is at https://github.com/apmlabs/webwars (GPL v2, same as Hedgewars).
Very cool, if only the multiplayer was compatible with the desktop version.
http://GTAMP.com
Thanks for the feedback! The multiplayer will definitely be cross-platform as I use the original Hedgewars server. The issue here is 70k+ lines of Qt code that need to be ported to JS. Work in progress
Hey again,
Quick update on the browser port. A lot has changed since the last post.
First load is way smaller. It was ~190MB before because everything was packed into one file. Now the initial download is ~7MB (core assets only — sprites, shaders, fonts, sounds, the Nature
theme). The other 29 themes and their music are fetched on demand based on what map you're playing.
Music works now. Turns out there were 4 broken SDL2_mixer declarations in SDLh.pas — Mix_LoadMUS_RW was missing a parameter, Mix_PauseMusic and Mix_ResumeMusic had wrong signatures, Mix_
PausedMusic had an extra param. Fixed those in Pascal, regenerated through pas2c, and music plays fine now. Each theme has its own music track, fetched on demand when the game starts.
Game config UI. You can now pick from all 16 built-in scheme presets (Default, Pro Mode, Shoppa, Minefield, King Mode, etc.), 13 weapon sets, and 22 game styles. Each option has a description
so you know what you're getting into. Game styles that lock the scheme or weapons (like Racer locking to Shoppa weapons, or Battalion controlling its own loadout) disable those dropdowns
automatically — same behavior as the Qt client reads from the .cfg files. Go to https://webwars.link/play.html to try it.
Cross-play with PC clients should work. Updated the protocol to PROTO 60, fixed CFG SCHEME to send values as separate protocol lines instead of one comma-separated string (the server was only
seeing 2 elements instead of 44+), and added the ! prefix on scriptparam that the Qt client sends. Haven't fully tested this with a real PC player yet — if anyone wants to try, connect to the
same server and let me know what breaks.
Post-game flow. The game used to just reload with random settings when a round ended. Now it returns to the menu so you can pick a different mode or play again with the same settings. The
config dropdowns that were sitting in the top bar during gameplay (doing nothing) are gone too — replaced with a label showing what mode you're playing.
Other stuff:
- Removed CJK fonts from the WASM build (saves 17MB, we don't need them in browser)
- Found an upstream bug: the Haskell server's schemeParams list is missing e$sentries, which shifts healthprob through worldedge by one position. It's harmless because all 16 built-in presets
have sentries=0, but worth noting.
- Looked into the Rust server as a potential replacement — it compiles after some fixes but lacks rate limiting and flood detection, so staying on Haskell for now.
What's next: single-player content (campaigns, training missions, challenges). The engine already has all 33 missions and 21 game styles in the data file, it's just a matter of building the
launcher UI and wiring up the IPC for mission variables and stats. Also want to do team customization (names, hats, colors) and post-game stats.
Same links as before:
- Play: https://webwars.link
- Custom game: https://webwars.link/play.html
- Multiplayer: https://webwars.link/lobby.html
- Source: https://github.com/apmlabs/webwars
Still doesn't work on Safari. Still no mobile controls. Working on it.
Tried multiplayer against someone else on the browser version but it just got stuck on "running" with no graphics displayed. The game was still listed as hosted long after it closed.
Singleplayer works great, I like the weapons menu being in the centre and I see it has the sentry/ducky that isn't in the 1.0 version (cool but will likely mean incompatible).
http://GTAMP.com