You can get some ideas on how to implement this from some spatial data structures, such as range trees or kd.
However, the answer to this question will vary greatly depending on how your game works.
We are talking about a two-dimensional platformer with 10 enemies on the screen, another 20 off-screen, but “active”, and an unknown number is more “inactive”? If so, you can save your entire level as an array of “screens”, where you will manipulate those closest to you.
Or do you mean a real 2D game with a lot of up / down movement? You may need to be more careful.
The platform is also important. If you're using a simple desktop platformer, you probably won't have to worry about performance as much as you would on an embedded device. This is no reason to be naive about this, but you may not need to be terribly smart.
This is a somewhat interesting question that I think. Presumably, someone smarter than me, who has experience with platforming, was already thinking about it.
McPherrinM
source share