Okay, so this piece of code is to my new project. I’m trying to get things to draw behind other things if they’re above it, and in front of things if they’re below it.
Player, Projectile, and Enemy all extend Thing.
if p1 has a projectile activated with y > enemy[i].y everything draws, but if p1 walks above enemy[i] or p1 fires a projectile while above enemy[i] than enemy[i] won’t draw and it says that drawOrder’s size is -1 of things.size()
also, if p1 fires a projectile above enemy[i] and than walks below enemy[i] everything draws, but the projectile is in front of enemy[i].
Here is the code that fills “things”
things = new Vector<Thing>();
things.add(p1);
for(int i = 0; i < p1.maxProjectiles; i++){
if(p1.projectile[i].state != p1.projectile[i].STATE_DEAD){
things.add(p1.projectile[i]);
}
}
for(int i = 0; i < MAX_ENEMIES; i++){
things.add(enemy[i]);
for(int j = 0; j < enemy[i].maxProjectiles; j++){
if(enemy[i].projectile[j].state != enemy[i].projectile[j].STATE_DEAD){
things.add(enemy[i].projectile[j]);
}
}
}
drawOrder = new Vector<Integer>();
minY(things, drawOrder);
and here is minY:
public static void minY(Vector<Thing> t, Vector<Integer> order) {
int min = t.get(0).y;
int max = t.get(0).y;
for (int i = 0; i < t.size(); i++) {
if (t.get(i).y <= min) {
min = t.get(i).y;
order.add(0, i);
}
else if(t.get(i).y > min && t.get(i).y < max){
int tempsize = order.size();
for (int j = 0; j < tempsize; j++){
if(t.get(i).y <= order.get(j)){
order.add(j, i);
}
else if(t.get(i).y > max){
max = t.get(i).y;
order.add(i);
}
}
}
else if (t.get(i).y >= max) {
max = t.get(i).y;
order.add(i);
}
}
}//end method max