Example #1
0
  private void onFlameLifecycle(Room room, Flame flame, Integer flameBathcId) {
    if (!flame.isStoped()) {
      updatePosition(flame);
    }

    if (!flame.isStoped()) {
      if (flame.getxStart() <= 0
          || flame.getxStart() >= room.getMap().getX()
          || flame.getyStart() <= 0
          || flame.getyStart() >= room.getMap().getY()) {
        flame.setStoped(true);
      }
    }
    Circle flameCircle =
        new Circle(flame.getxStart(), flame.getyStart(), PersonWebSocketEndpoint.FIRE_RADIUS);
    if (!flame.isStoped()) {
      for (AbstractZone zone : room.getMap().getZones()) {
        if (!zone.isShootable()) {
          Point[] point =
              CircleService.circleBoundsIntersection(
                  flameCircle,
                  new Bounds(zone.getX(), zone.getY(), zone.getWidth(), zone.getHeight()));
          if (point.length > 0) {
            flame.setStoped(true);
            break;
          }
        }
      }
    }
    for (Person person : room.getPersons().values()) {
      if (person.getId() != flame.getPersonId()) {
        Circle personCircle =
            new Circle(person.getX(), person.getY(), PersonWebSocketEndpoint.PERSON_RADIUS);
        Point[] point = CircleService.circleCircleIntersection(flameCircle, personCircle);
        if (point.length > 0) {
          onDamage(room.getPersons().get(flame.getPersonId()), flame.getDamage(), person, room);
          room.getProjectiles().remove(flameBathcId);
        }
      }
    }
  }