void fixEntityCollision(Entity e) { while (checkEntityCollision(e)) { if (x < e.getX()) { x -= 2; } else if (x > e.getX()) { x += 2; } else if (y < e.getY()) { y -= 2; } else if (y > e.getY()) { y += 2; } } }
boolean checkEntityCollision(Entity e) { Rectangle r1 = new Rectangle(getX(), getY(), WIDTH, HEIGHT); Rectangle r2 = new Rectangle(e.getX(), e.getY(), Entity.WIDTH, Entity.HEIGHT); return ((r1.intersects(r2)) || (r2.intersects(r1))); }