@jdbc I don't use box2d as it's the kiss of death as far as speed is concerned. The game has to run at 60hz... Box2d has it's place though and I'd use it for something like Angry Birds - but not for a platformer or this type of game.
@pie Thanks. You can't see it from the video - but it isn't a single player game - up to 8 people can play and it scales out to show everyone/every enemy in the map. No slowdown at 60hz. I'm using LuaJIT, but I don't know how much that is making a difference - I suspect a lot...
How the sprites know where to go:|
Everything (EVERYTHING!) can collide with everything else. it does a dx*dx + dy*dy check on every sprite with every player (up to 8 on screen at once) to find the nearest player to itself. It then check to see if it can collide with the something in the nearest space, if not then if it's a diagonal then it also checks the position on either side of the diagonal. If all is ok then it moves towards that position. If not then it then checks the block to the next rotation (either left or right), does the same diagonal check, and if all ok moves there. If it is blocked then it stops doing anything for 30 frames - then it tries again. It does this for map blocks and for all other sprites.
Every sprite also check for the player moving on every turn too, it the re-adjusts to see if there is a nearer player or if it needs to change direction.
One thing I did to speed things up is never add or remove children to the parent sprite - I just hide them, mark them as hidden in a table, then re-use them as needed. Adding and removing children would kill the game.
The sprite class also isn't modified - only the frame event gets the events. I suspect the enhancing the sprite class would slow things down (but simplify the programming). Events are a killer - get rid of them.
All sprites are also draw order sorted by their Y position. I do one pass per frame and hope no-one spots an overlap.