So now I'm wondering about what good ways there are to handle enemies as you scroll around.
So you have your 4-way scrolling map. You have enemies placed at various locations, in no particular order.
What we need is a way to tell when an enemy is about to be scrolled onto the screen, so it can wake up.
We also need a way to tell when an enemy has gotten far away enough from the screen and should deactivate.
Then we need to decide whether it deactivates in the location it left the screen, or returns to its spawn location. And if it returns to its spawn location, it should not reappear if the spawn location is on the screen. (Some games spawn enemies in visible areas on the screen! I think The Nerd mentioned Ninja Gaiden as one of them)
One approach I can think of is to have a complete object table for every single enemy in the level, then do range checks as you iterate over each enemy. This is probably not the best way to do it, as it compares every single object's position, and that's slow.
Another approach is to add objects from a passive list into the active list as you approach them. Then you still need to look at a range of objects from the passive list as you scroll. Still a lot of checks though. Maybe force the checks to occur only every 32 or 64 pixels or whatever. But then you get slowdown if you scroll left and right repeatedly on a seam.
Games which scroll in only one pair of directions have it easy, since they only need to look at one object to decide to spawn more.
Another thing to think about is that a monster may have 'buddies'. There could be three monsters behind the screen boundary waiting to attack the player. If you used an algorithm where each object activates separately, you could slowly approach the edge, wait for the first enemy to attack you, move back, then kill it. You could take out the monsters one at a time. In that kind of situation, you'd want to activate them all at once, even if the buddies are farther away from the screen. I think this also may apply for deactivating as well.
So you have your 4-way scrolling map. You have enemies placed at various locations, in no particular order.
What we need is a way to tell when an enemy is about to be scrolled onto the screen, so it can wake up.
We also need a way to tell when an enemy has gotten far away enough from the screen and should deactivate.
Then we need to decide whether it deactivates in the location it left the screen, or returns to its spawn location. And if it returns to its spawn location, it should not reappear if the spawn location is on the screen. (Some games spawn enemies in visible areas on the screen! I think The Nerd mentioned Ninja Gaiden as one of them)
One approach I can think of is to have a complete object table for every single enemy in the level, then do range checks as you iterate over each enemy. This is probably not the best way to do it, as it compares every single object's position, and that's slow.
Another approach is to add objects from a passive list into the active list as you approach them. Then you still need to look at a range of objects from the passive list as you scroll. Still a lot of checks though. Maybe force the checks to occur only every 32 or 64 pixels or whatever. But then you get slowdown if you scroll left and right repeatedly on a seam.
Games which scroll in only one pair of directions have it easy, since they only need to look at one object to decide to spawn more.
Another thing to think about is that a monster may have 'buddies'. There could be three monsters behind the screen boundary waiting to attack the player. If you used an algorithm where each object activates separately, you could slowly approach the edge, wait for the first enemy to attack you, move back, then kill it. You could take out the monsters one at a time. In that kind of situation, you'd want to activate them all at once, even if the buddies are farther away from the screen. I think this also may apply for deactivating as well.