// loop though all the doors on a wall to check if a door is clicked on DoorModel isOnDoor(WallModel wall, float x, float y) { // Temporary door variable used in for loop DoorModel door; // Loop through each door in the wall for (int i = 0; i < wall.getDoors().size(); ++i) { // Aliasing door = wall.getDoors().get(i); // If it's a horizontal wall if (wall.getWidth() > wall.getHeight()) { if (x > door.getPosition() - door.getWidth() / 2 && x < door.getPosition() + door.getWidth() / 2) { return door; } } else { // else it's a vertical wall if (y > door.getPosition() - door.getWidth() / 2 && y < door.getPosition() + door.getWidth() / 2) { return door; } } } return null; }
// Delete the wall that was clicked on from the walls ArrayList // Return true if a wall or door was deleted so that the geometry model will be updated public boolean delete(float x, float y) { WallModel wall = isOnWall(x, y); if (wall != null) { DoorModel door = isOnDoor(wall, x - wall.getStartPositionX(), y - wall.getStartPositionY()); if (door != null) { // If a door was clicked remove that door instead of the wall wall.getDoors().remove(door); } else { getWalls().remove(wall); } return true; } RoofModel roof = isOnRoof(x, y); if (roof != null) { // Remove roof from ArrayList getRoofs().remove(roof); return true; } return false; }
// Add a door to the wall that was clicked on and return true // If there is no door return false public boolean addDoor(float x, float y) { WallModel wall = isOnWall(x, y); if (wall != null) { // Get position of the door on the wall float position; if (wall.getWidth() > wall.getHeight()) { position = x - wall.getStartPositionX(); } else { position = y - wall.getStartPositionY(); } // Create a new door DoorModel door = new DoorModel(position); // Add door to wall wall.getDoors().add(door); return true; } return false; }