Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i am running into problem here. I have a arraylist called rect which store all bounds for ground. i am looping though it and checking for collision between player and arraylist bounds.

tile map 2d array:

1 = player
2 = ground
0 = background

1,0,0,0
2,2,0,2

I want to print "FLAG 1" if its collisied but if its not than print "FLAG 2". I am not 100% sure but i think the problem is the loop.

if arraylist size is 10 than, if player is standing on ground than it will print "FLAG 1" but than it will print 9 times "FLAG 2"

public void collision(Player p){
this.getBounds();

for(int i = 0; i < rect.size(); i++){
    if(p.getBounds().intersects(this.rect.get(i)))
          System.out.println("FLAG 1");
    else
                 System.out.println("FLAG 2");
}

}

not sure if i made my question clear. I want to only print "Flag 1" if its touch the ground. and when its not touching than i only want to print "Flag 2"

share|improve this question
1  
This is a very localized programming question. It's not really gamedev related either. – bummzack May 9 at 10:13
What does getBounds do. What does intersects do. Have you stepped through your code with a debugger? – Tetrad May 9 at 11:14

closed as too localized by bummzack, msell, Tetrad May 9 at 11:15

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.