Achievements, milestones and unlockables inside a game. Event- and stat-driven definitions, counters with progress bars, hidden achievements, one-at-a-time unlock toasts, persistence, an achievements screen, unlocking cosmetics or modes, good achievement design (teach, reward mastery, encourage exploration, avoid grind), and forwarding unlocks to Newgrounds, Game Jolt or CrazyGames through bash...
Download skill (.zip) Files on GitHubAchievement system
Drop-in: assets/achievements.js (tests: counter progress, stat thresholds, unlock once, hidden names masked, persistence
across reloads). Portal integration: bash-portal-achievements (its achievements.js talks to Newgrounds medals,
Game Jolt trophies and CrazyGames). Connect them with addSink.
import { createAchievements } from "./core/achievements.js";
const ach = createAchievements({
firstWin: { name: "First steps", desc: "Finish level 1", on: "levelComplete", when: (e) => e.level === 1 },
batHunter: { name: "Bat hunter", desc: "Defeat 50 bats", on: "enemyKilled", when: (e) => e.type === "bat", count: 50 },
saver: { name: "Piggy bank", desc: "Hold 1,000 coins", stat: "coins", atLeast: 1000 },
secret: { name: "Spelunker", desc: "Find the hidden cave", on: "foundCave", hidden: true },
}, { storageKey: "mygame-ach" });
game.events.on("enemyKilled", (e) => ach.event("enemyKilled", e)); // keep game code unaware of achievements
ach.stat("coins", wallet.get("coins"), { set: true });
ach.addSink((a) => portal?.unlock(a.id)); // optional: portal medals
// HUD: const t = ach.nextToast(); if (t) showToast(`Achievement: ${t.name}`) screen: ach.list(), ach.summary()
Good achievements
| Kind | Example |
|---|---|
| Teach | “Use the dash to cross a gap” (guides players to a mechanic) |
| Progress | “Reach world 3” (marks the journey) |
| Mastery | “Finish level 5 without getting hit” |
| Explore | Hidden: “Find the secret room” |
| Fun / style | “Defeat a boss with the starter weapon” |
- 10–30 for a small game. Mix easy (first minutes) with hard ones.
- Avoid pure grind (“Kill 10,000 enemies”) and achievements for things players can’t control.
- Hidden achievements: show “???” with a vague hint.
- Unlockables (skins, modes) make achievements meaningful in a free web game.
Rules
- Driven by events, so adding one never touches gameplay code.
- One toast at a time, top of screen, 2–3 s, with a sound. Never block input.
- Persist progress immediately. Reset only from settings, with a confirm.
- Test: trigger each one via the debug handle (
__game.ach.event(...)), check toasts, the screen and the save.