What it does
You make a game of a level with game.pullPin.create(level), step it in a fixed step, and pull the pin the player
taps: pinAt(point) finds a pin by its handle or its bar, and pull(pin) slides it out along its length at its own
speed, pushing whatever touches it as it goes. Behind the pins are balls of different stuff, from coloured and grey
balls to bombs, lava, water, stone, heavy rocks and gold, which fall and pile on a physics-2d world that belongs to
the level, so a restart is clean.
Two sets of rules come built in. In the classic game a grey ball takes the colour of a coloured ball it touches, the cup wins when it holds enough coloured balls, and a grey ball or a bomb in the cup loses. In the hero game lava and water harden into stone where they meet, rocks and stone falling fast enough crush enemies, lava burns them, enemies walk at the hero when they can see it, and the hero walks to treasure it can see on its level. A level with every pin out and nothing moving for a moment, and not won, is lost as stuck.
The game reports everything as events (a pull, a pin out of the glass, a ball coloured, lava hardened, a ball in the
cup, a crush, a burn, the loot, and won or lost with the cause), and view() says where every wall, pin, ball, cup,
hero and enemy is, so your game draws them in any 2D style.
Features
- Pins that slide — any length, at any angle, pulled either way, pushing what they touch as they go.
- Balls of many kinds — coloured and grey balls, bombs, lava, water, stone, heavy rocks and gold, with friction and spin.
- Fills — a box close-packed with balls, so a chamber full of them is one line of data.
- Classic rules — colour spreading from ball to ball, a cup that needs a count, and grey balls and bombs that lose.
- Hero rules — lava, water and stone, crushing rocks, enemies that walk at the hero, and a hero that walks to treasure.
- Rule options — whether a grey ball or a bomb in the cup loses or is ignored, the crushing speed, and how long a settled board waits before it is lost.
- Any glass — walls of boxes, circles, convex polygons and rounded chains along a polyline, at any size.
- Elements of your own — register a kind, such as a fan, with its own state, step and view.
- Saves and validation —
snapshotandrestorereplay the moves, andvalidatelists a level's problems. - Preset levels — four classic and four hero levels for a portrait screen, each won by a tested solution and lost by the wrong order.
Good for
- Ball-drop colour puzzles in the style of Pull the Pin, filling a cup by pulling pins in the right order.
- Hero-rescue puzzles in the style of Hero Rescue, with lava, water, rocks, enemies and treasure.
- Mobile puzzle ladders — many small levels as data, each with a clean restart and a save.
- Pin puzzles of your own — the same glass, pins and balls with new elements, such as fans.
Make it yours
A level is data: its size, gravity, walls, any number of pins at any angle, balls and fills of any kind, the cup and
the count it needs, a hero and enemies with their sizes and speeds, and rules for grey balls, bombs, crushing and
settling. Every element falls back on defaults you can read from game.pullPin.defaults. create's options register
element kinds and set the fixed step, 1/120 second by default.
Two different uses: a classic level where two pins hold a chamber of red balls above a chamber of grey ones, and the
order the player pulls them decides whether every ball is coloured before it reaches the cup; and a hero level where a
pin holds lava above water and another holds a rock above an enemy, and the hero waits for a clear path to the gold.
With rules: { grey: 'ignore' } the classic game turns gentler, a grey ball in the cup simply not counting.
A quick look
A preset level played by tapping pins:
const play = game.pullPin.create(game.pullPin.levels.classic[1]!);
game.step('pins', dt => {
const p = game.input.pointer;
if (p?.pressed) {
const pin = play.pinAt(game.camera.toWorld(p.x, p.y)); // the handle, or the bar itself
if (pin) play.pull(pin);
}
play.step(dt);
for (const e of play.drain()) if (e.kind === 'won') showWin();
});
Works with
physics-2d— the rigid-body world each level plays on, and the pack for rigid bodies under rules of your own.cut-rope— a physics puzzle of ropes cut rather than pins pulled.screw-sortandscrew-relocate— physics puzzles of screws and plates to free.
Good to know
- Lava and water are balls, not fluid: they pour and pile, and harden where a lava ball touches a water ball.
- Heroes and enemies walk on the level they stand on, see what is within 70 units up or down with nothing between, and do not climb or jump.
- Colour spreads through a pile as it settles, so give it a moment before the pile falls.
- Saves replay the moves from the start, which is quick for a level of a few seconds.






