Where Puffin Bay came from, and how a few bits of it work.
Why this exists
Puffin Bay is an island of rooms to wander round, people to chat to, minigames to earn gold in, and clothes and furniture to spend it on.
It follows on from Paddlebrook, my game about ducks and a pond, and shares its foundations: the same server set-up, the same way of drawing everything in code, and the same rule that the server is always in charge.
Market Street, where the clothes shops are.
Drawn in code
There isn't a single image in the game itself. Every puffin, building, lava lamp and pizza topping is a little piece of code that draws it, so any hat can be worn with any dye, and the whole island can fade into evening without anyone painting a night-time version.
The island keeps one clock for everyone. As the day goes on outdoors gets darker, the stars come out, the windows light up and the lighthouse starts sweeping its beam across the sea.
The lighthouse after dark.
The server's in charge
The server runs the island in small steps, about eight a second. Your browser only ever asks: to walk somewhere, buy a hat, or put a sofa down. The server decides what happens and sends back only what changed, packed into small binary messages.
Instant minigames
The minigames need to feel instant, but they also pay out gold, so they have to be fair. Each one is written as a set of rules both sides can run. You play your own copy in the browser, sixty frames a second, so your puffin and your fishing hook go exactly where you point.
Twice a second your browser sends the server what you did. The server plays it all through again on its own copy, never faster than real time, and pays you from that. A fingerprint of the game travels along too, so if the two copies ever disagree, it gets noticed.
Pizza PanicRock Pools
Every pool can be done
In Rock Pools every stone sinks once you've hopped off it, and sinking all of them pays a bonus. So every pool has to be possible. Each one is designed by drawing a route first, and the tests run a little solver over every pool to prove it can be finished with every stone sunk.
Four packages, and that's it
The whole game leans on just four outside packages: Express for the web pages, ws for the live connection, EJS for the page templates, and one to compress what gets sent. The database and the password hashing are both built into Node itself.