Instead of checking the game tick % 600 in on_event
, you should use on_nth_tick
. It'll reduce the overhead during non-active ticks.
When refreshing ore, you should add a check to make sure the amount only increases. In fact it might be better to add the value instead of replacing, so a worm hanging around in one area for a long time makes a very rich spice field.
Ore reductions should happen before ore spawns, so that the freshly spawned ore doesn't get immediately reduced.
Define a SPAWN_RADIUS_SQUARED
local, and use it to avoid doing an expensive math.sqrt
25 times in a row.
Instead of applying noise to the position, I think it would work better to apply noise to the ore amount based on distance from center, and simply skip to the next position if the ore amount comes up negative after applying noise. Something like local ore_amount_random = ORE_AMOUNT * (20 + 10*math.random() - x^2 - y^2)
Also, it would be significantly more complicated to implement, but you could consider iterating over the enemies and only spawning ore near one at a time, but on a faster cycle. This would reduce the amount of work that gets done in an individual tick.
Good luck with this project. I'm looking forward to playing with a legendary quality end result :)