Exemplo n.º 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);
        }
      }
    }
  }
Exemplo n.º 2
0
  private void onRocketLifecycle(Room room, Rocket rocket, Integer rocketBatchId) {
    updatePosition(rocket);

    Circle rocketCircle =
        new Circle(rocket.getxStart(), rocket.getyStart(), PersonWebSocketEndpoint.ROCKET_RADIUS);
    Explosion explosion = null;
    if (rocket.getxStart() <= 0
        || rocket.getxStart() >= room.getMap().getX()
        || rocket.getyStart() <= 0
        || rocket.getyStart() >= room.getMap().getY()) {
      explosion = new Explosion((int) rocket.getxStart(), (int) rocket.getyStart());
    }
    if (explosion == null) {
      for (AbstractZone zone : room.getMap().getZones()) {
        if (!zone.isShootable()) {
          Point[] point =
              CircleService.circleBoundsIntersection(
                  rocketCircle,
                  new Bounds(zone.getX(), zone.getY(), zone.getWidth(), zone.getHeight()));
          if (point.length > 0) {
            explosion = new Explosion((int) point[0].getX(), (int) point[0].getY());
            break;
          }
        }
      }
    }
    if (explosion == null) {
      for (Person person : room.getPersons().values()) {
        if (person.getId() != rocket.getPersonId()) {
          Circle personCircle =
              new Circle(person.getX(), person.getY(), PersonWebSocketEndpoint.PERSON_RADIUS);
          Point[] point = CircleService.circleCircleIntersection(rocketCircle, personCircle);
          if (point.length > 0) {
            explosion = new Explosion((int) point[0].getX(), (int) point[0].getY());
            onDamage(room.getPersons().get(rocket.getPersonId()), rocket.getDamage(), person, room);
            break;
          }
        }
      }
    }

    if (explosion != null) {
      explosion.setxEnd((int) explosion.getxStart());
      explosion.setyEnd((int) explosion.getyStart());
      int id = gameContext.getProjectilesIds().getAndIncrement();
      room.getProjectiles().put(id, new Projectile[] {explosion});

      Circle explosionCircle =
          new Circle(explosion.getxStart(), explosion.getyStart(), explosion.getRadius());
      Person shooter = room.getPersons().get(rocket.getPersonId());

      for (Person person : room.getPersons().values()) {
        double damageFactor =
            PointService.pointBelongToCircle(
                new Point(person.getX(), person.getY()), explosionCircle);
        if (damageFactor > -1) {
          double damage = explosion.getDamage() + damageFactor * explosion.getDamageFactor();
          onDamage(shooter, (int) damage, person, room);
        }
      }
      room.getProjectiles().remove(rocketBatchId);
    }
  }