Hi lovely people! I'll do my best to describe the problem here. The problem seems simple but I've attached a GIF for better understanding anyway.
I have a character sprite, and a family of objects called Layer_Objects. What I'm trying to do is give some depth to the game, by having the character move behind or in front of these objects. So, on collision with Layer objects, I find the Y index of the player, and the layer object collided with, and move the player in front or behind the layer object depending on if the player's y-index is higher or lower than that of the collided object. Following me?
The function itself actually works, all seems fine and dandy - until two objects are collided with. As you can see in the GIF, one object is no problem, but the second layer object will always override the first, and puts both objects in front or behind of the player. I've been trying to fix this for literally days and am now having Z-Index nightmares. Please help!
Here's how it looks in action, you can see the problem at the end of the GIF when he collides with the chairs:
Here's the code I've used thus far (which seems to work the best - ignore the shadow condition):
I also tried a for loop, but this gave the same results:
Something to note: on the start of the layout I sort all the Z-Indexes of the Layer_Objects by their Y-index (so the higher they are on the layout, the further back in space they are). That's all kosher. No problems there. It just seems to be this multiple object selection that's the problem.
I've toyed with the idea of creating an array which stores all the Y-values of all the Layer_Objects, and simply checks the player's Y constantly to determine if he's 'above' or 'below' an object, but this seems like CPU overkill for a simple effect, and what I suspect might be a simple solution.
Any help would be much appreciated! Thank you in advance.