Consider having an ArrayList<Rectangle> rectangles = new ArrayList();
and a Player Class that has a rectangle variable, Character c = new Character(new Rectangle(x,y,w,h));
. The Character class has an update()
like so :
public void update(){
rectangle.x = rectangle.x + xSpeed;
rectangle.y = rectangle.y + ySpeed;
}
Where xSpeed
& ySpeed
are constantly changing and update()
is constantly called.
How do I correctly check if character rectangle and any rectangle in the ArrayList are intersecting and if so prevent the character rectangle from moving?