Enemies spawn is handled by tracing map by scroll position at steps 16x16.
This means, that if scroll position is changing 16x16 cell by crossing its border,
then appropriate callback is called.
If scroll position cross vertical border of the cell from left to the right,
then it will call right border callback.
All other callbacks works similarly.
Each callback does lookup in tree structure of enemies.
Lets call it "vertical callback" if it's triggered when scroll position have crossed horizontal border of cell,
and call it "horizontal callback" if it's triggered when scroll position have crossed vertical border.
So, following picture:
|-V-|
| |
H H
| |
|-V-|
V - vertical callbacks, H - horizontal callbacks.
There are two trees of enemies.
One is for vertical callbacks, another is for horizontal callbacks.
For vertical callbacks, enemies sorted vertically,
for horizontal callbacks enemies sorted horizontally.
When horizontal callback called, it'll look for exact "new" ahead x position,
and then it'll look among all y positions.
Similarly, when vertical callback called, it'll look for exact "new" ahead y position,
and then it'll look among all x positions.
Key point here is that it looks "exact" something.
It is all exciting of course, but we need to get practical results.
To achieve that, after a lot of headache I did transform that ugly ahead positions into offsets from center of screen.
So, instead of drawing spawning points of enemies, I'm drawing regions on screen where center of screen should lay to trigger corresponding callback.
Now, a bit explanation of "what we see".
Horizontal very wide green box - vertical callback if screen moves UP.
Horizontal very wide red box - vertical callback if screen moves DOWN.
Vertical very tall green box - horizontal callback if screen moves RIGHT.
Vertical very tall red box - horizontal callback if screen moves LEFT.
NOTE: it may not trigger if center of screen is inside box but 16x16 cell haven't changed.
My script also draws:
1) Aero hitbox
2) Enemies hitboxes
3) Stars hitboxes
Use iteration method as I do, because it's how game does.
Aero hitbox a bit tricky, it depends on move. (called state in the script)
Adapt it for bizhawk yourself. I'm tired.
NOTE: it's for Gens-rerecording v11
NOTE 2: it will throw error "stack overflow" if it's not in level.
https://pastebin.com/mgLLaCnV
A bit of extra notes.
Most of positions is using 4 byte fixed point arithmetic.
This includes: position of aero, enemies, speed of aero.
To utilize subpixels, check my donald tas script for example.
Aero speed is located at: FF018E, FF0192.
Sometimes is better to use calculated speed. I mean difference between positions in two consecutive frames.