Pharmakia: an MMORPG in a browser tab, built without a game engine
A real-time role-playing game of old fairy tales, set around Constantinople in 1019. Everyone online shares one world, or you can play the whole game alone. The opening is free, with no account and nothing to install.
The full game is $10, once. Online play is $5 a month.
, updated
I first built this as a text adventure during my very first semester as a programmer. Since then, I've gone on to build a lot of software products for a lot of companies, even though I originally got into programming to make games, and never got to realize that dream until this year.
I wanted to build historical fiction set in a rich, fascinating era: a game that values virtue, honor, and classic storytelling. The quests are adapted from timeless folklore: Grimms' fairy tales, Aesop's fables, and Andrew Lang's Fairy Books. I also love classic puzzles, deep gathering and crafting systems, pets, mounts, weather, buffs, and debuffs, alongside real multiplayer with parties, whispers, zone chat, and overhead chat.
Most of all, I've had so much fun building this for my kids. Every day they ask to play it, and I realized that for us to play comfortably together on the couch, it needed local split-screen, so now it supports up to four players at once. I wanted Pharmakia to feel classic and familiar, yet deep and modern. It's a reflection of the games, stories, and experiences I've loved over my life, and I hope you enjoy playing it.
Erik Mellum
Scrolling in from above to first person, out through the city gate, and back up on the road.
From above to first person
Scroll in and the view drops from overhead to over the shoulder to first person. Scroll out and it climbs back. You can walk and fight in any of the three. In first person you see your own hands and whatever is in them.
The Big Sentry winds up a Stunning Blow, and a Counter-cut interrupts it.
Fights you can read
Creatures show what they are about to do. A bar fills over one and a half to two and a half seconds while it winds up, and in that time you can step away, raise your guard, or land the quick blow that breaks it.
You can hold a weapon in each hand, any two of a sword, dagger, hatchet, mace and club. The pair has its own blows, guard and flourishes. Great swords, long axes, great mauls and spears are slower, reach further and hit harder. A bow shoots while you walk, and while you back away from what you are shooting at.
When a move you have never used would help, its button is ringed and a line above it names the key.
A blow can cut, crush, pierce, burn, cloud the mind or poison, and each creature shrugs off some of those. A creature's card says what it is, how strong it is and whether it will attack you. What harms it is filled in as you learn it.
Creeping up behind a wolf, then standing up and being noticed.
Seen, heard and smelled
Each creature finds you by sight, hearing and smell, and leans on them differently. Light and shade, a torch or lantern in your hand, the ground underfoot, the armour you wear, rain, and which way the wind is blowing all count. A wolf downwind of a bloody hunter knows about him long before it sees him.
The eye, the ear and the nose by the movement buttons show how far off you can be noticed by each. Select one and it lists every part of the sum.
A canter along the harbour to the Hippodrome.
Ride to the City
You can buy a donkey, a mule or a horse, choose its coat and name it. In first person you look out between the animal's ears.
A mastiff set to attack goes for a wolf on its own.
Eight kinds of companion
A dog, a hound, a mastiff, a cat, a hawk, a goose, a jackdaw or a hedgehog can come along. Some of them fight beside you.
Pets and mounts need food and water. A water-skin holds five drinks: a dog takes one and a horse three. An animal that stops beside water drinks by itself.
The whole game on a phone
On a touch screen the game switches to its own layout, upright or sideways: a movement pad under your thumb, larger buttons, and a long press where a mouse would right-click.
Play alone and the world runs on the phone itself. If frames slow down, the game draws a shorter view and fewer sparks, and puts them back when there is room. You can add it to the home screen and open it like an app.
An iron sword in four steps: three at the anvil, one at the grindstone.
Crude, sound, fine or masterwork
Making a sword takes several steps at the anvil and the grindstone, and longer jobs take up to eight. You can stop after any step and come back to it.
The panel shows the chance of each quality before you start. Your skill, the metal and your hammer all raise it. Fine and masterwork pieces carry the maker's name.
Thyme oxymel at the Spice Shop: boil in the vinegar, strain it, mix in the honey.
Remedies, step by step
Boil, strain, mix and dry herbs into remedies and poisons. Better ingredients improve the odds, some can be swapped for lesser ones, and seven recipes are found by experiment.
Lighting a fire on the shore, feeding it a log and cooking a hare on a spit.
Keep the fire steady
Light a fire, feed it and cook what you caught or picked. Food can come out burnt or underdone. Your skill, how often you have made that dish and the state of the fire decide it, and rain makes an open fire riskier.
Walk into a fire and it burns you. Stay in it and you catch light. Water puts out the flames, and the burn lasts ten minutes unless you treat it.
Two gold veins by lantern light on the Gold Level of the Deep Workings.
Deeper rock, richer ore
The Deep Workings run from copper down through iron, gold and emerald, and ruby, to crystal. A better pick works faster and sometimes brings away a second piece, and the hardest stones need a fine one. Without a light the work is slower.
Veins and trees belong to everyone in the world. A spent one comes back in anything from 15 seconds to seven and a half minutes.
Out from the Shingle at dusk: cast, wait for the tug, strike, and land a mackerel.
Twenty-three kinds of fish
There are four ways to fish and nine baits. What bites depends on the water, the season, the weather and the hour, and dawn and dusk are usually best. You can also be rowed out to deep water in a hired boat or your own skiff.
Poppies in the court of the Drowned Monastery.
Know what you are picking
There are 34 kinds of herb to pick and 37 things to forage, and most grow only in certain places. One clump of mushrooms in three is a poisonous look-alike, and until you are skilled enough to tell, you carry them home unsorted.
Harvesting wheat and sowing leeks in its place, in the gardens inside the walls.
Crops that grow while you are away
Rent a bed and sow any of 36 crops. They grow in real time: 45 minutes for lettuce, three hours for wheat, three days for olives. Rain waters them and a storm can flatten ripe grain. A dry bed stops growing until it is watered, and a ripe crop keeps for about two days.

A silk robe at the loom in the Silk Workshop.
Looms, kilns and jewellers' benches
You can also make cloth, leather, bows, jewellery, pottery, medicine, traps and charms. There are 995 recipes in all, worked at 22 kinds of station around the world.

The skills panel, with gathering and crafting at the top.
Ten to gather, twelve to make
Each skill rises on its own as you use it. Its page shows what the next levels bring, where to train and who gives lessons.
Three Axes at the Bend. A charcoal burner loses his axe in a brook, and something comes up holding three.
Old tales you can change
94 quests stop and ask you to decide something, and 87 can end more than one way.
Some set a rule, such as kill nobody or say nothing, and breaking it starts that step again. 24 watch for a kindness nobody asked for. People remember a lie or a debt, and gaining favour with one faction can cost you some with its rival.
Every step has three free hints, from a nudge to exact directions.

Headman Psichas has bought a coat that only a man fit for his office can see.
Grimm, Aesop and others
61 quests start from a tale in Grimm. Others come from Aesop, Andrew Lang's fairy books, Andersen, the Arabian Nights, scripture and the lives of the saints.
The Peacock of the Well Square, jumbled again each morning.
Puzzles built into the places
18 puzzles stand about the world: sliding mosaics, rings on pegs, bells, picture locks, measuring jugs and levers. The codes and orders are written somewhere you can find them. Two of the puzzles are new each day.
Another 12 quests turn on one: a riddle contest at the well, three caskets with lying lids, a dog, a goose and a sack of barley to get over a river, a thief to name.
You can ask for a hint at the cost of part of the bonus, and after three minutes the game will show you the answer.

The board of the Muster of Therapeia. Harder jobs open with rank.
Work for thirteen guilds
Thirteen guilds keep boards with 85 jobs between them. Do the work and you rise in rank, and the harder jobs open.
Zone in orange, party in blue, whispers in pink. Theodora answers a whisper with /r, then switches tabs.
Say, zone, party and whisper
Say something aloud and it shows over your head to the players near you. Zone chat reaches everyone online, party chat reaches your companions, and a whisper reaches one player wherever they are.
Each has its own colour and its own tab in the log. Plain typing is said aloud, and /z, /p, /w and /r pick the others.
Every line goes through a word filter on the server. You can ignore or report a player from their menu, and the server never stores chat.
Ingvar invites Theodora, she joins, and the four walk north talking in party chat.
Up to five on the road
Invite a player from their menu. Your companions' health and conditions stay at the side of the screen, and F2 to F5 pick one of them to heal or help.

Eight folleis for a bowl and a healing potion. Basil has agreed.
Friends, and a fair trade
The friends list shows who is online and lets you whisper or invite them. You choose whether everyone, only friends or nobody can see you.
To trade, stand near the other player and put goods or coins in the window. If either side changes the offer, both have to agree again.
Three players fight a bear at the ford while the fourth walks the shore.
Four players on one screen
Connect a laptop to a TV and hand out controllers. Each player gets a quarter of the screen with their own character, camera, map and menus, and everyone walks the same online world as the players at home.
Press A on a spare controller to join. A code on the screen lets the new player sign in from a phone, so nobody types a password with a thumbstick. One account can play several of its characters at once.
You can also play alone with a controller, on a computer or a phone. Start opens a menu of everything that has no button of its own.
The house called Poison
It is the spring of 1019, in the reign of Basil II. A ruined estate stands on the ridge above the village of Therapeia, on the European shore of the Bosphorus. People call it ta Pharmakia, the Poisons. The old man at its gate wants a water from the bottom of the house, and he is vague about the people he sent in before you.
From there the roads run to the fields, the aqueduct woods, the Long Wall, the mouth of the Black Sea and Constantinople. The places and the daily life come from the history. The creatures are the ones people of that age told of and feared, and old fairy tales are retold among them.
You choose one of 12 origins and 7 callings, then learn to fight, sneak, brew, smith, cook, farm, ride, fish and keep animals.
- places
- 173
- quests and guild tasks
- 238
- people and creatures
- 369
- kinds of creature in the bestiary
- 206
- recipes
- 995
- spells
- 72
- pieces of music
- 86
- puzzles in the world
- 18
A morning in the harbour village, at twice the speed.
Village, city and wild
The map has 173 places, from farms and city streets to a desert, a marsh, mountain passes, mines and what lies under them.
A day and a night at the Great Church in eleven seconds, with a storm in the middle.
One day there is one day here
The game's clock runs at the speed of yours, on Pacific time. The sun follows the real date at Constantinople's latitude, the moon has its true phase, shops put up their shutters at sunset, and monks keep the hours of prayer. Rain, snow, fog, wind and thunder change how far off you can be seen and heard.
Trees blossom, turn and stand bare with the season. Ships pass on the strait, dolphins come up in fair weather, starlings flock at dusk, and mist lies in the low ground at dawn. Footprints stay in snow, mud and sand until the weather covers them. At night there are 1,011 real stars from the Yale Bright Star Catalogue, and they rise and set.
The Old Burner in the Dragon's Hollow. Its breath sets you alight. 1 of 35
The game drew every picture and clip on this page. I chose the place, hour, weather and equipment for each, and turned the interface off and placed the camera for the scenery.
How it is built
The frame is an array of pixels with a depth buffer beside it. On a computer it is at least 640 by 400 and takes the shape of the window. Ground, walls, roofs and props are filled triangle by triangle, and the finished frame is scaled up in whole steps where they fit. The view from above and the view from behind your own eyes use the same code with a different camera.
There are no image files. A person or a creature is a skeleton with meshes hung on it, all made in code, and it is baked to a sprite sheet when it is first needed, in a few milliseconds of each frame. A body, a breastplate and a sword are baked separately, each with its own depth for every pixel, and the nearest pixel wins when they are stacked. One bake of a breastplate serves everyone of that build who wears it.
Colour is five bits a channel, which makes the light of the hour and the weather one table of 32,768 finished colours, rebuilt when the light changes and read once for each pixel. Lamps go into a coarse light map worked out from the depth buffer, so a fire at night lights the ground in the ground's own colour.
The slowest view is first person in thick woods. A bare tree near you has about 130 triangles, and one more than 18 tiles away is drawn with about 20.
The score is 85 pieces written as data: modes, tunes in scale degrees, drones and bass lines, played by a Web Audio synthesiser with its own lyra, lute and reed pipes. A director picks the piece for the place and the fight and changes over on the bar line.
The first version used period tuning and sounded out of tune. I had the roughness of every chord measured: 73 of the 84 pieces there were then bent their notes, some by a quarter-tone. The score was rewritten in equal temperament, which halved the average roughness, and the tests now check every strong beat for consonance.
The rules run in fixed steps of 100 ms on plain data. Play alone and that simulation runs in your browser. Play online and the same files run on the server in Node, which executes the TypeScript directly. The client talks to either through one small interface: send an intent, poll events, read a snapshot.
The map is never sent. The browser makes it with the generator and the seed the server uses, and a test holds it to one checksum. Birds, ships and dolphins are not simulated at all. The place and the time of day decide where each one is, and two players on the shore see the same sail without a message about it.
A modified client can ask to walk somewhere or swing at something, and the server applies the same checks it applies to everyone.
Five kinds of message make up most of the traffic, so those five are packed by hand into binary WebSocket frames: positions in 16 bits, a path as one nibble per step. The rest is JSON checked against a schema on both ends.
With 300 scripted players walking, fighting and talking in crowds, that took each player from 32 KiB a second to 5.8. Pets, weather and stealth came later, and on December 3 the same test sent each player 12.
Outside the sound engine, one file in the client touches the browser. Everything else runs in Node, so the tests start a session, draw a frame, find the pixel where a creature is standing, and click it. The same scripted mouse made the pictures on this page.
There are about 2,300 tests of the game and a second suite for the server, including a store contract that runs against memory and Postgres, and recorded sessions replayed message by message.
The agents started from code and designs in my earlier projects. The house, its quests and its twist come from the text adventure I wrote in 2013. The sound engine was carried over from KeyQuest, my piano game, and reshaped. The phone builds and the hosting follow homeschool.fit, which I build and run.
The client and server follow the design of Choir, my desktop window manager. Its main process holds the state of every window, and the sandboxed windows around it send requests and get changes pushed back, all through one shared contract. Its tests run the main process against a fake of the platform and replay recorded sessions. The agent that built the game server read that code first.
The layout inside the server comes from C programs I wrote with MPI for a parallel programming course. A gateway holds the connections and passes messages to a zone, and only the zone changes its world.
The engineering standards come from Rune, where homeschool.fit and the client sites share one TypeScript codebase. The game uses the same strict compiler settings and does not allow the type "any". The server checks every message against a schema before acting on it, and the database changes only through numbered migrations. Type checks, lint and the tests run before each commit, and a failure stops it.
With that to work from, Claude agents wrote most of the code, the art routines, the music data and the dialogue, often several at once on separate parts.
A large change starts as a written plan that settles the rules and says which agent owns which files. After one playtest, what we had found was split into twenty pieces of work, each with its own agent, and one more agent put the results together and got the tests passing. An agent cannot see the game as a player does, so 171 scripts each draw one part of it to a picture for the agent to look at.
My part was the design, the setting, the rules the agents work under, and playing it and sending things back. Written rulebooks cover the theme and the voice, and a content checker looks for quests, people and items that point at something missing. None of the checks caught an out-of-tune score, which I heard when I played it.
Safari had a different map. Two shuffles in the map generator were sorts with a random comparator. JavaScript engines compare in different orders, so Safari and newer versions of Chrome laid out villages and ruins differently from the server. The shuffle is now written out step by step.
The capacity figure was out of date. An early measurement said one server was comfortable with 200 players and near its limit at 500. Before the launch I had it run again, with everything added since, and at 300 players it failed its own time limit. Online play opened with 150 seats.
A saving that cost more. The obvious fix for a crowd is to tell each player about only the 40 people nearest. A prototype with 350 players in one place sent a fifth less data, and the average tick went from 59 ms to 67, because choosing the 40 was more work than sending the rest. It was dropped.
Registration would have shut on launch day. New accounts were limited to 300 an hour for each address, and behind the load balancer all visitors had the same few addresses. The three-hundredth account would have locked out everybody after it. A review of every limit before the launch found it.
Free aim was no fun. I had arrows and swings made to go wherever you look, with nothing targeted. It touched about 30 files and was not fun to play, so it was taken out the same day.
What it takes to run
There is no game engine and no WebGL. The client draws every pixel on the CPU into a 2D canvas, and the game code has three runtime packages between the browser and the server.
- of one core to run the world for 150 players in one crowd
- 53%
- of server memory with all of them online
- 284 MiB
- sent to each of them
- 70 kbps
- added to the round trip, with no corrections to a walking player
- 600 ms
- to download, about, before you can play
- 2 MB
- to draw the world in a typical frame on an M3 Max, on the CPU
- 2 to 5 ms
- graphics cards needed
- 0
- image, model or audio files in the game
- 0
The server figures were measured on December 4 on the kind of machine the game runs on, a DigitalOcean server with two shared AMD cores and 4 GB. Scripted players stood, walked and fought for a minute. The CPU figure is the time the world takes to work out each tick, and leaves out writing to the network. The memory figure includes the scripted players.
One server, one world
A single container on DigitalOcean Kubernetes serves the page and runs the world, with Postgres for accounts and characters. One process means one shared world, and adding servers would not make room for more people in it.
150 people can be online at once. With 200 scripted players in one crowd, one tick in twenty took more than 130 ms, and there is a tick every 100 ms. When the seats are full there is a line that tells you your place in it, and if your connection drops, your seat is kept for a minute. The server also stops letting people in when its own ticks run late.
| Players | CPU, one core | Memory | To each player | Total out |
|---|---|---|---|---|
| 50 | 11% | 237 MiB | 34 kbps | |
| 100 | 27% | 249 MiB | 53 kbps | |
| 150 | 53% | 284 MiB | 70 kbps | |
| 150 in six places | 34% | 252 MiB | 45 kbps | |
| 200 | 78% | 318 MiB | 79 kbps |
The server figures were measured on December 4 on the kind of machine the game runs on, a DigitalOcean server with two shared AMD cores and 4 GB. Scripted players stood, walked and fought for a minute. The CPU figure is the time the world takes to work out each tick, and leaves out writing to the network. The memory figure includes the scripted players. Each row is one crowd unless it says otherwise. The live server reserves half a core and 256 MiB, and may use up to two cores and 1 GiB. The world runs on one thread. The second core is for password hashing and the network.
Over a bad line
Your own walk is worked out in the browser with the server's map and path search, so your character moves on the frame you click. Your first swing at a creature in reach starts before the server's answer too. The server works out whether it hits and for how much, and the answer arrives a round trip later.
I had this tested with 300 ms of delay added in each direction. In that run the server never had to correct where a walking player stood. After a ten-second dropout the game reconnected by itself and was playable again about four seconds after the line came back.
Drawing a frame
On an Apple M3 Max at 640 by 400, the median time to draw the world was 2 to 5 ms in a field, in the City, in the Great Church and in a crowd of 40. Thick woods in first person are the slowest: a whole frame there, interface included, took 13 ms.
Four players on a 1920 by 1080 screen took about 22 ms between them, or 45 frames a second. All of this was measured on December 4 while the laptop was busy with other work.
What you need to play
The processor draws the picture, so a gaming graphics card makes no difference. The speed of a single core matters most.
Played alone, the game uses almost no data once it has loaded. Online, an hour in a crowd of 150 is about 30 MB, and less with fewer people near you.
- Computer
- At least: Dual-core laptop, 4 GB of memory
- Better: Quad-core from the last five or six years, 8 GB
- Phone
- At least: Mid-range Android, about 25 to 60 frames a second
- Better: Recent iPhone or flagship Android, about 60
- Browser
- At least: One that runs ES2022 JavaScript and WebSockets
- Better: Current Chrome, Edge, Safari or Firefox
- Split screen
- At least: A computer. Phones get one player
- Better: Fast laptop or desktop, connected to a TV
- Connection
- At least: About 2 MB to load, then 70 kbps online in a crowd of 150
- Better: Under 150 ms to the server for fights
Phone frame rates are estimates from a laptop slowed to phone speed. The slowest case was first person in thick woods or a crowd, at 22 to 31 frames a second. The memory figures are estimates too.
Free for the first 100 players
The launch code gives you the full game, normally $10, and six months of online play, normally $5 a month.
Without a code, the House and its grounds are free for as long as you like. The full game is a single $10 payment and includes everything you can do alone. Online play is optional and stops any month you choose.
CONSTANTINOPLE100- 1.Open the game with the button below. The code is filled in for you.
- 2.Make an account and confirm your email address.
- 3.Press Use code. Stripe shows a total of $0 and does not ask for a card.
Online play stops by itself after six months unless you add a card. The game stays yours, and your characters are kept. One copy per person. When every seat online is taken, people who pay for online play go in ahead of people playing on the code.
Have something difficult to build?
Rune builds custom software for companies in the same way: an experienced engineer directing AI agents, with tests and review on everything that ships. You get a fixed quote and own the code.
Found a bug in the game, or want to know how a part of it works? Write to me.