in the create_enemy_forces function
local spawn_radius = (400 + (global.level * 20))
local x_offset = math.random(-spawn_radius, spawn_radius)
local y_offset = math.random(-spawn_radius, spawn_radius)
local save_zone = 100 - (global.attack_increase / 15)
if x_offset >= 0 and x_offset < save_zone then x_offset = x_offset + save_zone elseif x_offset >= (save_zone*-1) then x_offset = x_offset - save_zone end
if y_offset >= 0 and y_offset < save_zone then y_offset = y_offset + save_zone elseif y_offset >= (save_zone*-1) then y_offset = y_offset - save_zone end
Enemies can always spawn in the base, at a minimum distance of save_zone until global.attack_increase is negative enough to pass through 0,0 and start spawning them opposite to what math.random rolled
If it were instead:
local spawn_radius = (100 + (global.level * 5)) --could use balancing
local x_offset = math.random(spawn_radius, 1.5 * spawn_radius) * (math.random() < .5 and -1 or 1)
local y_offset = math.random(spawn_radius, 1.5 * spawn_radius)* (math.random() < .5 and -1 or 1)
--local save_zone = 100 - (global.attack_increase / 15)
--if x_offset >= 0 and x_offset < save_zone then x_offset = x_offset + save_zone elseif x_offset >= (save_zone*-1) then x_offset = x_offset - save_zone end
--if y_offset >= 0 and y_offset < save_zone then y_offset = y_offset + save_zone elseif y_offset >= (save_zone*-1) then y_offset = y_offset - save_zone end
or something like it, then the enemies spawn a distance out, between two squares. It's a starting point that is easier to understand, at least. (in my opinion)