[Devlog] A new enemy spawn system

Our current in-development project. Slash your way through an enemy horde in this musou-inspired action roguelike with random loot but strategic builds.
Post Reply
User avatar
celes
Posts: 51
Joined: Sun Feb 15, 2026 8:09 pm
Location: The offices at Carrot Corp
Pronouns: she/they

[Devlog] A new enemy spawn system

Post by celes »

Time for another devlog! :akko_fistup:

There was something a very insightful playtester (thanks zivi!! :blobcatheart:) brought up, and it's the kind of thing that, once I heard, it made everything click: The current enemy spawn system tries to find spots near the player to put enemies in. This worked relatively well, but while it lead to fine gameplay, the issue that had been bugging me and I couldn't point out is that it did not really matter where you went: Enemies would keep spawning near you, so you could stay in place and keep farming forever. Sure, the game was incentivising you to move around in other ways (chests, raising difficulty, having to find an exit...), but at the bottommost core gameplay loop the game was incentivising people to stay put.

Now this is fine for a "survivors" style game, a genre in which I have some experience! But Iris Blade is supposed to be the opposite from a survivors game.

So it was time to redo enemy spawn logic!

Mulling it over, and the notebook

I'll go off on a bit of a tangent. I like to avoid "the topic" in my writing because we're all very tired, especially me, but there is one thing that keeps coming up when discussing with the cultists. They all bring up the usefulness of bouncing off ideas against the proverbial deus ex wall and how effective that is at organizing one's thoughts.

And you know what, I gotta give it to the cultists. :blobcatthink: There is something truly special about being put in front of with my own thoughts, in writing form, that other forms of thinking don't quite let me reach. This will be different for different people. But I think organizing one's thoughts is truly the key to tackling larger complexity.

So, I devised a contraption that lets me do the same thing with a heavily reduced carbon footprint: The notebook. Now, I didn't invent the notebook. As far as I can tell, this was invented by YouTuber ThinMatrix, of Equilinox fame and Java gamedev extraodinaire. If only he had told us how key the notebook was to his success during the devlogs. Instead, he just hinted at us by showing quick montages of his pages upon pages of doodles every now and then.

Anyway, seriously now: The next time you're struggling with some problem and feel the urge to consult with a talking pile of tensors, try talking to your notebook instead! Oh and drink that glass of water instead, you've earned it! :akko_smile:

Alright, It seems I am incapable of seriousness, so goofiness will have to suffice for now. Now, to better illustrate my point, I'm about to let you take very blurry peek into my mind
image.png
image.png (853.2 KiB) Viewed 668 times
Those are the first two pages, to fully converge on a design for this I wrote about six pages. If you've tried reading a bit of this, you'll notice it's just me rambling. I'm literally thinking and writing it down as I go, stream-of-consciousness style. I find the act of writing helps me connect the dots and steers me away from tangents in a way that's almost impossible to do with freestyle thinking.

You'll also notice my writing style is a bit wasteful, we're lucky paper literally grows on trees, eh?

And the notebook nerds in the room may also have noticed how I like my notebooks clear: no grids or lines. That's just my style and I don't really have strong arguments for it, other than the fact that no lines gives me complete freedom to doodle things, even if this page ended up being a bit more text-y. Maybe you're also having strong opinions about the fact a grown-up is using a pencil. You can even see it in the picture, a 0.7mm Bic Velocity mechanical pencil (to save you the digging). The reason? I find it useful, and even cathartic to be able to conveniently "erase" a thought once I realize something didn't make sense.

The economics of spawning a bunch of slimes

Back to the topic, if there ever was one: The Game Director, which is what I've been calling the bit of code responsible for spawning enemies and making some other interesting gameplay decisions, has now acquired two tasks: (1) Fill up the world with enemies at the start of the level and (2) Respawn enemies as they die so you get to catch a break, but never really run out of them.

In retrospective, this was much simpler than I thought. Anytime you need to do something "procedural", the answer is always chunks and noise functions. What I did is split the game world into chunks (yet again). Each chunk stores two new properties:
  • Enemy count
  • Heat
Now, I follow the honorable art in computer science to use the word "heat" to describe metrics I don't have a better metaphor for. By "heat" I mean, how interesting is that chunk for the purposes of spawning enemies. The higher the heat, the more enemies there will be.

With this, we can define what I called the density of a chunk. Now, hopefully you'll excuse phpbb's lack of LaTeX formulas:

Code: Select all

density = enemyCount / heat
The Game Director's goal will be to keep enemy density stable across all chunks. But what does stability mean here? Well, that took a while to figure out, it's on page 4 of the notebook! At each point in time, we have a target density we want for the chunks. At the start of the run, that target density will be low. As the game progresses, we will slowly turn up the density dial, and things will gradually get crazier as the world is filled with more and more enemies, but keeping the original balance: Hotter areas get more enemies than colder ones.

So, by stability, what we mean is that we want to achieve a constant value for... some metric? Let's call it tension, even though it's a bit of a misnomer, like all the other terms here:

Code: Select all

tension = targetDensity / density
The tension formula has some interesting properties:
  • If the chunk is at the target enemy density, it has a value of 1.
  • If the chunk has a lot more enemies than it should, its value gradually go towards zero.
  • If the chunk has less enemies than it should, its value will quickly raise

    The mathematicians are screaming into the monitor as I am explaining division to the crowd. "Look at what gamedevs need to mimick a fraction", or something :blobcatgiggle:
    image.png
    image.png (19.76 KiB) Viewed 648 times
    But tension was the main ingredient here: When it's time to spawn an enemy, the Game Director will rank chunks by tension, and favor those with higher tension. Picking an element from a list at random with weighted probabilities was a recent topic of discussion, so I won't delve into that.

    There's some twists I added to the idea, for extra chaos. Heat is typically computed by checking things in that chunk, like chests and whatnot. Each chest adds some heat, barrels add some heat too, and so on. But then I added a noise function on top, so even if two chunks have the same amount of stuff in it, some chunks will tend to be a lot more densely populated than others, just like life itself: And to you, the player, the real reason behind this variance is that I'm sure those slimes have a plan which makes them have some areas more heavily guarded than others.

    I mentioned at the start of the section the game director had two goals: It turns out, the two goals are actually one and the same. A nice property of this system is that Initial spawn and respawning are two sides of the same coin. You start with an empty map, and you keep spawning enemies until you're satisfied!

    It's hard to show this in action since the point is to feel it over the course of the run, but this was my best attempt in a short looping gif:
    enemyspawn.gif
    enemyspawn.gif (9.3 MiB) Viewed 668 times
    And then the FPS dropped

    But no tale is complete without some performance testing. :akko_fistup: What's this I see? 45 FPS in my debug build? No, that won't do.

    Spawning enemies near the player has some advantages. You get to play smoke and mirrors with them and despawn enemies once they venture too far off. When it's you against the horde, nobody will notice a missing bat. :badbat: But now that there's enemies all over, I couldn't pull off this trick anymore. It only took a quick glance at the profiler to notice the issue. Hear me out now: Invest some time into having a good profiling system!

    The solution? Simple! Every performance issue can be solved in one of two ways: (1) Do it faster, (2) Do less work. Since my enemy logic is a port from Carrot Survivors, I know it was pretty optimized already: zero-allocation, uses a fast path for the spatial partitioning logic that's specific to enemies... So (2) was the obvious choice.

    The next best thing you can do when you can't despawn faraway enemies is to freeze them. And that turned out reasonably well! I also took the chance to add culling logic to my Sprite component, which I hadn't had the need to until now (because most things in the game are tiles or grass and those are culled!).

    Closing

    Anyway, I hope you enjoyed the devlog! :blobcatheart: I tried to go for a longer one this time, but I think it was time well spent. If I get to be a little selfish, please do let me know if you enjoy these. Gamedev can feel a bit lonely sometimes and despite what it might seem, morale among the carrot ranks hasn't been the highest.
 

POSTREACT(ions) SUMMARY

User avatar
Sugui
Posts: 17
Joined: Tue Feb 17, 2026 12:50 pm
Location: Europe
Pronouns: she/her

Re: [Devlog] A new enemy spawn system

Post by Sugui »

I love how you use the notebook! :heart_purple:. It makes me remember those days when I was bored in classroom at the highschool, and I started to draw abstract patterns and figures. All my attention went towards there, and for some reason, I felt creativity peaked while doing that.

Sure, every person can be different, but I think having a white notebook where you don't have distractions or restrictions about how you can express yourself, helps a lot for activating creativity. And also, using a paper notebook fits so well here as it can be seen "old school" as phpbb too :blobcatgiggle:. Anyways I think the term "old-school" is becoming more and more a synonym of "better" than "bleeding edge" is, sadly. :pensivecat:

About the algorithm, it seems cool and something that would make players more prone to explore in general. Also, I'm impressed how you got to think about it using your notebook, it really seems like magic a bit. :blobPikaAww:

Also, about being selfish *proceeds to headbutt her*. This is literally your space and you can talk about everything you want. This devlog is a new topic in the forum that is not conflicting with others. I think it's important that you talk about in the way you want about the gamedev, so you don't limit your creativity or expresivity. I'm sure there will always be people that read and listen to what you want to say. :blobcatheart:

In my case, I found this devlog very interesting, I'm always happy to read your gamedev ramblings. :blobpika:

(I'm now thinking about bringing in my notebook for a trip I'll have to do soon so I can think game ideas :blobcatthink: )
 

POSTREACT(ions) SUMMARY

User avatar
Kampffrosch
Posts: 6
Joined: Fri Feb 20, 2026 12:56 pm

Re: [Devlog] A new enemy spawn system

Post by Kampffrosch »

I love notes :nkoAww:
There are so many forms of them, all of them useful.
I try to always carry a cheap a6 notebook in my pocket, so I can just jot down some thoughts or tasks for later and free up my mind in the moment.

I also draft up my ideas on printer paper for more complex projects, but I throw those away once I implemented them. I don't want to use that as a reference since it "bitrots" instantly.

Notes that I actually want to retrieve in the future I store digitally.
 

POSTREACT(ions) SUMMARY

User avatar
celes
Posts: 51
Joined: Sun Feb 15, 2026 8:09 pm
Location: The offices at Carrot Corp
Pronouns: she/they

Re: [Devlog] A new enemy spawn system

Post by celes »

Sugui wrote: Tue Mar 10, 2026 7:33 pm I'm now thinking about bringing in my notebook for a trip I'll have to do soon so I can think game ideas
Yay! Glad to have inspired this!! :heart_purple:
Kampffrosch wrote: Wed Mar 11, 2026 6:48 am I try to always carry a cheap a6 notebook in my pocket, so I can just jot down some thoughts or tasks for later and free up my mind in the moment.
I should do this too! I rely on my phone for that when there's no need, besides writing on my comically small 3.5" phone screen is uncomfortable (that's the point of having such a tiny phone, so that I don't use it more than it's necessary). What do you use for writing? I'm a bit wary of keeping pens in my pocket as they easily break.

That reminds me, another very useful thing I've rescued for my notebook sessions is a scientific calculator. I have one I kept all the way through my high school and uni years and it's been a very refreshing to bring it back into my daily workflow. Come to think of it I've never even replaced the battery to this thing?

Anyway I realized having a physical calculator is a lot more effective than anything on my phone or my computer. When coming up with formulas like the above, quickly plugging in some numbers without the distraction of having to go back to the computer really helps.
 

POSTREACT(ions) SUMMARY

User avatar
Kampffrosch
Posts: 6
Joined: Fri Feb 20, 2026 12:56 pm

Re: [Devlog] A new enemy spawn system

Post by Kampffrosch »

celes wrote: Wed Mar 11, 2026 12:09 pm What do you use for writing? I'm a bit wary of keeping pens in my pocket as they easily break.
I use gel pens. (uniball signo dx 0.38)
I like them because I can write pretty small and readable with them and the gel doesn't smear.
celes wrote: Wed Mar 11, 2026 12:09 pm physical calculator
Anything I would do with a calculator I rather do in my head or on paper.
It helps me build/maintain that mathematical intuition.
That's just me though, I don't think calculators are bad I just never warmed up to them.
 

POSTREACT(ions) SUMMARY

Post Reply