The best roguelikes do not just kill you. They make you want to die.
That sounds strange, but anyone who has lost a run at midnight and started another at 12:03 knows the feeling. Death stings. Your health drops to zero. The screen floods with failure. Yet your finger is already hovering over the play button. Something about the last twenty minutes mattered enough that you cannot leave the game where it ended.
This is the "one more run" loop, and it is not accidental. It is designed. If you are building a roguelike or any game with permadeath, your entire job is to balance two opposing forces. The player must lose enough to feel tension. They must keep enough to feel hope.
The Currency of Failure
In my latest project, Neon Survivor, I wanted that exact tension. When the player dies, everything gathered during the run disappears except for one thing: gold. That gold gets banked automatically. Back at the menu, they spend it on permanent upgrades. Then they jump in again, slightly stronger than before.
This simple loop carries the whole game. Without it, death is a full stop. The player walks away because the last run got them nothing. With it, death is a comma. The run became a farming trip. The loss hurts, but it also paid for tomorrow.
The trick is simple. You keep something even when you lose everything else. The difficulty is making sure the thing you keep matters without destroying the challenge. If the upgrades are too weak, the player stops caring. If they are too strong, the game plays itself. The loop collapses either way.
Two Clocks, Zero Confusion
To build this properly, I had to manage two separate timelines.
The Run Clock resets every time you hit play. It tracks health, current score, enemy wave count, and any temporary power-ups picked up during the session. When the character dies, this clock winds back to zero.
The Meta Clock never resets. It holds total gold earned across every attempt, the highest wave ever reached, and every permanent upgrade purchased. This clock keeps ticking no matter how many times the browser refreshes.
Mix these two together and you get bugs that are hard to track and painful to fix. I have seen developers accidentally wipe player progress during a routine scene reset because a cleanup function touched the wrong data store. The Meta Clock data evaporates. The player returns to zero gold and zero upgrades. At that point, the relationship between you and your player is broken. They are not starting a new run; they are starting a new grudge.
Keeping the clocks separate is not just a style choice. It is a survival strategy.
How Phaser v4 Handles the Split
I built Neon Survivor in Phaser v4, which offers two specific tools for this problem.
The Registry holds live data in memory for the current session. It is fast. It is simple. It also evaporates the moment the player refreshes the page.
LocalStorage saves data to the browser itself. It survives tab closures, browser restarts, and power outages. It is also slower and less reliable. Browsers can block it, throttle it, or wipe it if storage quotas fill up.
My design choice was strict. The Registry is the only source of truth during gameplay. The game reads from it, writes to it, and trusts it completely. LocalStorage does not act as a co-author. It acts as a mirror.
Here is how the flow works. The game writes an upgrade purchase to the Registry. A single manager class watches the Registry. When appropriate, that manager mirrors the Registry data to LocalStorage. If the browser blocks the write, the game does not stutter. If storage fails, the current session still runs perfectly. The player might lose progress only if they close the tab in the exact same second, but the session itself never crashes.
This pattern prevents a subtle disaster. If you let every system write directly to LocalStorage, you create dependencies on a fragile API. A player with privacy settings cranked up or a device low on storage could see the game slow down or freeze during combat because some background function tried to save stats. By making the Registry the sole source of truth, you keep the action fast and the risk contained.
Let the Code Breathe
I also used events to decouple the systems. When a run ends, the GameScene does not handle its own funeral. It does not call a save function. It does not import a storage utility. It simply emits a "run-ended" event with a payload of the relevant data.
Satu listener berasingan mengendalikan urusan perekodan. Ia menerima acara tersebut, mengemas kini Meta Clock, dan memberitahu pengurus untuk menyalin jumlah baharu ke LocalStorage.
Pemisahan ini memberikan hasil yang ketara dengan segera. Saya boleh menulis semula keseluruhan GameScene, menukar watak pemain, mengubah sudut kamera, atau malah menukar genre daripada survival kepada bullet hell tanpa menyentuh sistem simpanan. Sistem-sistem ini adalah bebas. Ia berkomunikasi melalui acara (events), bukan melalui panggilan fungsi secara langsung. Ini bermakna kurang konflik penggabungan (merge conflicts), kurang pepijat (bugs), dan kod asas yang tidak menjadi berselirat seperti spaghetti selepas enam bulan.
Naik Taraf yang Mengubah Permainan
Mempunyai tulang belakang teknikal adalah sia-sia jika ganjaran yang diberikan terasa seperti hamparan (spreadsheet). Saya meluangkan banyak masa untuk memikirkan bagaimana rasa sebenar bermain dengan naik taraf tersebut.
Sesetengah naik taraf adalah selamat. Kelajuan pergerakan tambahan. Bonus nyawa. Isi semula peluru lebih pantas. Ini memberikan pemain lebih ruang untuk melakukan kesilapan. Ia memberikan keselesaan. Ia mengecilkan tahap kesukaran permainan tanpa mengubah peraturannya.
Naik taraf lain mengubah peraturan sepenuhnya. Dalam Neon Survivor, saya menambah "Piercing Rounds." Sebelum naik taraf ini, peluru akan terhenti pada musuh pertama yang dihentamnya. Selepas naik taraf, ia akan menembusi musuh, berpotensi membersihkan seluruh barisan dalam satu tembakan.
Perbezaannya sangat drastik. Kelajuan dan nyawa mungkin membolehkan anda bertahan lebih lama, tetapi Piercing Rounds mengubah cara anda memposisikan diri. Anda mula menyusun musuh dalam barisan. Anda berhenti bermain secara kiting di bahagian tepi dan mula membelah melalui bahagian tengah. Ruang membuat keputusan dalam permainan ini semakin luas.
Kemajuan (progression) yang baik sepatutnya mengubah keputusan pemain, bukan sekadar meningkatkan angka mereka. Jika setiap naik taraf hanyalah peningkatan peratusan, pemain akan berhenti membaca deskripsi. Mereka klik, mereka naik taraf, dan mereka lupa. Jika sesuatu naik taraf membuatkan mereka memikirkan semula strategi mereka, mereka akan mengingatinya. Mereka akan membicarakannya. Mereka akan kembali untuk melihat apa lagi yang mungkin mengubah landskap permainan secara drastik.
Hasil Sebenar
Gelung "satu lagi pusingan" (one more run) bukanlah satu sistem tunggal. Ia adalah hubungan antara kerugian dan keuntungan, yang dibina berasaskan seni bina yang bersih dan ganjaran yang bermakna.
Bina dua garis masa yang berbeza dan lindungi Meta Clock seolah-olah ia memegang kepercayaan pemain anda, kerana memang begitulah hakikatnya. Gunakan alatan enjin anda untuk memastikan data langsung (live data) kekal pantas dan data persisten (persistent data) kekal selamat. Pisahkan (decouple) babak (scenes) anda daripada storan supaya anda boleh melakukan iterasi tanpa rasa takut. Dan apabila anda mereka bentuk naik taraf, tanyalah sama ada ia memberikan pemain lebih masa, atau pilihan yang lebih menarik.
Lakukan ini dengan betul, dan pemain anda bukan sekadar akan menerima kematian. Mereka akan bergantung kepadanya. Setiap pusingan menjadi bayaran pendahuluan untuk pusingan seterusnya. Permainan tersebut tidak lagi menjadi siri permulaan semula, sebaliknya menjadi satu pendakian yang tunggal dan berterusan.
