I've never done any sorting before and I've reached the point in
my game's development that I need to sort the units based on
their current map Y coordinate (a long) for proper blitting order.
I played around with my pen and notepad and came up with a
very simple algorithm to sort them.
I've tested it in the game and it works out fine. The only problem
(and it may not even be a problem) is that it just seems too
easy). I know that may sound crazy but I just wanted to get
some input to see if anyone sees any possible problems I may
have missed.
Thanks in advance!Code://sample code// //CBot is an object (class) that represents units in the game ////global declaration// CBot cbot[12], *pcbot[12], *pcbottemp; int i, j; ////at game/level start, initialize the pcbot array with the values ////contained in their cbot array counterparts for(i=0;i<12;i++) { pcbot[i]=&cbot[i]; } ////right before the main game loop, sort based on map Y value for(i=0;i<12;i++) { for(j=0;j<12;j++) { if(pcbot[i]->ptMap.y<pcbot[j]->ptMap.y) { pcbottemp=pcbot[i]; pcbot[i]=pcbot[j]; pcbot[j]=pcbottemp; } } }
Jason



LinkBack URL
About LinkBacks
. I know that may sound crazy but I just wanted to get 


