les say i want collision between two rect than i cant set up bounds on both rect:
public Rectangle getBounds(){
return new Rectangle(x, y, width, height);
}
than to check for the collision i can do this:
if(rectOne.getBounds().intersects(rectTwo.getBounds())
{ ...}
now les say what if i want 2d array:
0, 0, 2, 2, 0
1, 0, 2, 0, 2
i want to check for collision between '1'(player) and '2'(walls). i think of doing this by same idea as top of my code.
'rect' is a arraylist
minus cameraX or cameraY is to move the screen.
public void getBounds(){
for(int y = 0; y < map01.length; y++){
for(int x = 0; x < map01[y].length; x++){
if(map01[y][x] == 2) {
rect.add(new Rectangle(x * tileWidth - cameraX, y * tileHeight - cameraY, tileWidth, tileHeight));
}
}
}
}
now to check for collision:
player is '1' and arraylist should have all the bounds for walls '2'
this.getBounds();
for(int i = 0; i < rect.size(); i++)
{
if(player.getBounds().intersects(this.rect.get(i)))
System.out.println("COLLISION");
else
System.out.println("NO COLLISION");
}
the problem is this is that for some reason it is only printing "NO COLLISION". Is this bc of for loops or arraylist?