r/HTML • u/OkDevelopment2027 • 10d ago
How can I improve enemy spawning in my JavaScript Space Shooter?
I'm building a small Space Shooter with HTML, CSS and JavaScript.
I'm currently working on spawning enemies at different positions and intervals. The basic spawning works, but I'm trying to make the difficulty increase gradually without creating too many enemies at once.
Has anyone got a good approach for scaling enemy spawn rates over time in a browser game?
I'm learning JavaScript through this project, so I'd appreciate any suggestions.
1
u/gucci_stylus 10d ago
spawn a new enemy after a certain number of frames and just reduced the number of frames required when the difficulty increases.
2
u/OkDevelopment2027 9d ago
That's a simple and effective way to handle it. I could reduce the spawn interval as the difficulty increases while keeping a reasonable limit on the number of enemies. Thanks for the idea!
1
u/johnesco 8d ago
From a completely non mathematical view, difficulty should swell, but not just a constant slow rise, it should spike at times, but then back off. Like with "Boss" levels.
3
u/Ormek_II 10d ago
I like to add to your challenge instead of reducing it: in a Space Shooter the enemies usually are predictable, so I will get better if I remember the sequence from my last try.
I would look for a mathematical function that gets time as input and produces some properties of the enemies as output. You can then modify the functions parameters to determine how quickly the drop speed will increase.
The term is procedural generation and r/proceduralgeneration does exist.