Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean checkForColision(Particle p) {
- // Field to scan is the Particle's current y
- // minus particleSize and plus particleSize.
- int startRowIndex = (int) (p.getPosy() - p.getHeight() - 1);
- if (startRowIndex < 0) {
- startRowIndex = 0;
- }
- int endRowIndex = (int) (p.getPosy() + p.getHeight() - 1);
- if (endRowIndex > checkList.length - 2) {
- endRowIndex = checkList.length - 2;
- }
- for (int x = startRowIndex; x <= endRowIndex; x++) {
- // Get current list and check if it's not null.
- List<Particle> l = checkList[x];
- if (l != null) {
- // Loop through each Particle in the list.
- for (int i = 0; i < l.size(); i++) {
- // Get current Particle in the list.
- Particle cp = l.get(i);
- // If the current Particle in the list is the one
- // we are checking against (self), return.
- if (cp == p) {
- return false;
- }
- if ((cp.getPosx() + cp.getWidth()) >= (p.getPosx())
- && (cp.getPosx()) <= (p.getPosx() + p.getWidth())) {
- double collisionSize = 20;
- p.setWidth(collisionSize);
- p.setHeight(collisionSize);
- cp.setWidth(collisionSize);
- cp.setHeight(collisionSize);
- System.out
- .println("***************************************************COLLIDE********");
- return true;
- }
- }
- }
- }
- // Nothing found, return false.
- System.out.println("*****************NO COLLISION");
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment