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.

Sebuah listener terpisah menangani pencatatan. Ia menerima event, memperbarui Meta Clock, dan memberi tahu manager untuk menyinkronkan total baru ke LocalStorage.

Pemisahan ini memberikan hasil instan. Saya bisa menulis ulang seluruh GameScene, mengganti karakter pemain, mengubah sudut kamera, atau bahkan mengubah genre dari survival ke bullet hell tanpa menyentuh sistem penyimpanan. Sistem-sistem ini bersifat independen. Mereka berkomunikasi melalui event, bukan panggilan fungsi langsung. Itu berarti lebih sedikit konflik merge, lebih sedikit bug, dan codebase yang tidak berubah menjadi spaghetti setelah enam bulan.

Upgrade yang Mengubah Permainan

Memiliki tulang punggung teknis tidak ada gunanya jika hadiahnya terasa seperti spreadsheet. Saya menghabiskan banyak waktu untuk memikirkan bagaimana rasanya memainkan upgrade tersebut.

Beberapa upgrade bersifat aman. Tambahan kecepatan gerak. Bonus nyawa. Reload lebih cepat. Ini memberi pemain lebih banyak ruang untuk melakukan kesalahan. Ini menenangkan. Mereka memperkecil tingkat kesulitan game tanpa mengubah aturannya.

Upgrade lainnya menulis ulang aturan sepenuhnya. Dalam Neon Survivor, saya menambahkan "Piercing Rounds." Sebelum upgrade ini, peluru akan berhenti pada musuh pertama yang mengenainya. Setelah upgrade, peluru tersebut menembus musuh, berpotensi membersihkan seluruh barisan dalam satu tembakan.

Perbedaannya sangat dramatis. Kecepatan dan nyawa mungkin membuat Anda bertahan lebih lama, tetapi Piercing Rounds mengubah cara Anda memposisikan diri. Anda mulai menyusun musuh dalam satu garis. Anda berhenti melakukan kiting di pinggiran dan mulai menerjang lewat tengah. Ruang pengambilan keputusan dalam game pun meluas.

Progresi yang baik harus mengubah keputusan pemain, bukan sekadar meningkatkan angka mereka. Jika setiap upgrade hanyalah kenaikan persentase, pemain akan berhenti membaca deskripsi. Mereka klik, mereka upgrade, lalu lupa. Jika sebuah upgrade membuat mereka memikirkan kembali strategi mereka, mereka akan mengingatnya. Mereka akan membicarakannya. Mereka akan kembali untuk melihat apa lagi yang bisa membalikkan keadaan dalam game.

Hasil yang Sesungguhnya

Loop "satu kali lagi" bukanlah sebuah sistem tunggal. Ini adalah hubungan antara kerugian dan keuntungan, yang dibangun di atas arsitektur yang bersih dan hadiah yang bermakna.

Bangun dua timeline yang berbeda dan lindungi Meta Clock seolah-olah ia memegang kepercayaan pemain Anda, karena memang begitulah adanya. Gunakan alat engine Anda untuk menjaga data live tetap cepat dan data persisten tetap aman. Pisahkan scene Anda dari penyimpanan agar Anda dapat melakukan iterasi tanpa rasa takut. Dan saat Anda merancang upgrade, tanyakan apakah upgrade tersebut memberi pemain lebih banyak waktu, atau pilihan yang lebih menarik.

Lakukan ini dengan benar, dan pemain Anda tidak hanya akan menoleransi kematian. Mereka akan bergantung padanya. Setiap run menjadi uang muka untuk run berikutnya. Game tersebut berhenti menjadi serangkaian restart dan menjadi satu pendakian yang berkelanjutan.