I'm currently having a great time creating a 2D overhead Zelda esq game using C++ and Allegro 5.
However my game is more of a Beyond Oasis perspective then a Zelda Perspective and objects need to appear behind other objects when they have a higher y position and above when they have a lower y position. I have gotten it to work with one object on the other. I created and if/else depending on the y coordinate of the one object.
How would I go about creating this function using every moving object in the game. How can I define the two y variables within the class to create a correct draw order?
Right now I have all characters except the user character inherit all x,y coordinates from a base class. What do I need to do so that I can have two characters who inherit the same x,y to interact?
I got the suggestion to using an SLT container and algorithm std::sort function. I understand how to sort the values using these tools but how do I then sort the functions themselves.
For example:
I have these functions to draw:
1 2 3 4 5 6 7 8 9
|
bush[1].DrawBush(bushImage);
bush[2].DrawBush(bushImage);
rock[1].DrawRock(rockImage);
aBear[1].DrawsBear(bearImage2);
pigs[1].DrawPig(pigImage);
pigs[2].DrawPig(pigImage);
gremlin[1].DrawGremlins(gremlinImage);
toad[1].DrawToad(toadImage);
reginald->DrawVanJohnson(reginaldImage);
|
I created a variable to define where I would want them to switch order. int ysort. However, how can I connect the entire function whatever.drawwhater(); with this variable and sort them at the same time.