Dave0710
YaBB Newbies
Offline
Posts: 10
Identifying the greatest ArayList number problem.
Nov 2nd , 2009, 5:22pm
I am trying to writing something that identifies which Array number is the greatest present under a certain situation. I have this if statement that tells me when an ArrayList object is inside the radius of another object, and I'm trying to writing something so that that object can identify which of the present objects is greatest in the ArrayList. Does that make sense? --------------------------------------------------------------------------------for(int i=enemies.size()-1; i>=0; i--){ Enemy peng = (Enemy) enemies.get(i); float dis = dist(x,y, peng.x,peng.y); float addedRadii = 8+diameter/2; TowMiliSec++; if(dis <= addedRadii){ /* I tried to write something here that can tell me which ArrayList Object has the greatest 'i' under the circumstances of this if statement. For example, lets say the objects with the 'i' 8, 7, 6, 5 are inside this radius (or "if statement"). How could I write something that will spit out the number 8, seeing that it's the largest number out of those four? */ float biggestFac = max(x-peng.x,y-peng.y); float fac = biggestFac/3; float vx = x/fac; float vy = y/fac; if(peng.x<x){ vx *= -1; } if(peng.y<y){ vy *= -1; } if(TowMiliSec%60 == 0){ if(control3 == 0){ bullets.add(new Bullet(x,y, vx,vy, false, damage)); control3++; } } else{ control3 = 0; } } for(int j=bullets.size()-1; j>=0; j--){ Bullet bull = (Bullet) bullets.get(j); bull.move(); bull.impact(); if (bull.hit()) { bullets.remove(j); } } }