i want to set a collision on my tile map using getBounds function.
level class
int map[][] = {
{2, 0, 0}
{1, 1, 0}
};
2 = player
1 = ground
0 = sky
i want to set collision so player cant go though ground. so he should fall at end of map.
in player i just did this:
public Rectangle getBounds()
{ return new Rectangle(x, y, width,height);}
bc there is x and y for player.
in level class each tile is 32X32. so i can add width and height
but i am not sure x and y:
public Rectangle getBounds()
{ return new Rectangle(, , tile_size,tile_size);}
do i have to use loop and if statment in that method ex:
public Rectangle getBounds()
{
for()
{
for()
{
if(map[y][x] == 1)
{
return new Rectangle(, , tile_size,tile_size);
}
}
}
}
and to check if they are collsion
if(player_class.getBounds().intersects(level_class.getBounds()))
{
System.out.println("collsion");
}