My previous method has been to maintain everything as a list of game objects that derive from a common base, then high up in the hierachy add some general code for collision detection that all game objects inherit.
While it is nice and simple and means that leaf classes require very little of their own code, it does not seem to be sufficient for a platformer. Everything needs to be handled differently.
Enemies should only collide with the map and the player, for example. I also want to have the ability to have objects or map blocks behave like those Mario-style ones that you can walk in front of and jump onto so you only collide when you land on them. I can't see any feasible way to implement this with the current system.
So a bit of a back to the drawing board when I get home tonight. I still think a class hierachy and a factory unit that generates instances from the level file is a nice solution, since the engine only gets to see the base CItem and is insulated from the details of actual specific types of item, but I think a lot of the physics needs to move down the hierachy (or do I mean up? Towards the leaves) a bit so that different items can handle their collisions differently.
I still don't think it is feasible to move everything, then handle collisions as a second step. My problem with that is that say I move items A, B and C, then find A collides with B. If I align A and B along their edges, what happens if I then discover that both A and B then collide with C?
The current system of move along the X, test collisions and pick a final X co-ord, then do the same for the Y, for each item before moving on to the next one is the only way I've ever found of getting rock solid collision detection to work properly in a 2D game. Guess it wouldn't hurt to have a google for some other approaches.
I'm wondering if for the blocks you can jump in front of but land on top of, I could test to see if the players feet intersect with a narrow band at the top of the block and if so, and the player has a positive Y velocity, anchor them on top of the block. Problem is that if the band is too narrow, the player could fall through it when falling very fast, but if it is too wide, the player could incorrectly end up landing on the block when just moving in front of it.
Perhaps I'll need to check collisions along a sequence of steps between the old position and the new one, but since checking collisions involves doing co-ord based map collisions AND running through every other object on the map, this would not be very efficient.
Then again, I don't need accurate collisions for enemies, since they are just killed or kill you on touch. Perhaps I need to have a seperate list of items that actually need to be block-collided, like moving platforms and static blocks, and objects that I can examine the collisions in one go after all the movements are completed, like enemies, pickups and so on. Trouble there is that even non-accuracy-critical collisions like enemies still require some information about the previous move since we need to know whether the player landed on them or not. Maybe storing each objects previous position would be a solution to this.
As you can probably tell, I'm thinking myself in circles at the moment. I'd really love to have a sit down for a couple of hours with someone who wrote like original Super Mario or something and pick their brains. I just can't seem to find much on the internet beyond the very basics of creating platformers.
How difficult can it be? And don't even talk to me about moving platforms. Nightmare.
Still push on. If anyone does have any good links for 2D platform physics, please feel free to post.