public static void checkIfHit() { // this is wrong if (counter >= contactTime + MIN_TIME_BETWEEN_HITS) { for (int i = 0; i < obstaclesArrayList.size(); i++) { // System.out.println("xloc: " + obstaclesArrayList.get(i).getxLocation() ); if (obstaclesArrayList.get(i).getxLocation() >= DEFAULT_X - 0.5 * DEFAULT_DIMENSION && obstaclesArrayList.get(i).getxLocation() <= DEFAULT_X + 0.5 * DEFAULT_DIMENSION) { if (obstaclesArrayList.get(i).getyLocation() == bottomObstacleY && obstaclesArrayList.get(i).getyLocation() <= g1.getyLoc() + DEFAULT_DIMENSION) { // System.out.println("bottom contact"); g1.setLives(g1.getLives() - 1); // lower lives by one contactTime = counter; // System.out.println("Number of lives: " + g1.getLives()); switch (g1.getLives()) { case 2: g1.setColor(lives2); break; case 1: g1.setColor(lives1); } return; } else if (obstaclesArrayList.get(i).getyLocation() == topObstacleY && obstaclesArrayList.get(i).getyLocation() >= g1.getyLoc() - DEFAULT_DIMENSION) { // System.out.println("top contact"); g1.setLives(g1.getLives() - 1); // lower lives by one contactTime = counter; // System.out.println("Number of lives: " + g1.getLives()); switch (g1.getLives()) { case 2: g1.setColor(lives2); break; case 1: g1.setColor(lives1); } return; } } } } }