Ejemplo n.º 1
0
  @Override
  public void onBulletHitBullet(BulletHitBulletEvent event) {
    Point2D bulletPosition = new Point2D.Double(event.getBullet().getX(), event.getBullet().getY());

    GBulletFiredEvent hittedWave = null;
    for (GBulletFiredEvent wave : waves.getWaves()) {
      if (Math.abs(
              bulletPosition.distance(wave.getFiringPosition())
                  - ((getTime() - wave.getFiringTime()) * event.getBullet().getVelocity()))
          < 20) {
        hittedWave = wave;
        break;
      }
    }

    if (hittedWave == null) return;

    double firingOffset =
        org.pattern.utils.Utils.firingOffset(
            hittedWave.getFiringPosition(), hittedWave.getTargetPosition(), bulletPosition);
    double mae = firingOffset > 0 ? hittedWave.getMaxMAE() : hittedWave.getMinMAE();
    double gf = firingOffset > 0 ? firingOffset / mae : -firingOffset / mae;

    storages.get(event.getBullet().getName()).visit(gf);
    waves.getWaves().remove(hittedWave);
    return;
  }
Ejemplo n.º 2
0
  @Override
  public void onHitByBullet(HitByBulletEvent event) {
    GBulletFiredEvent wave = waves.getNearestWave();
    Point2D myPos = new Point2D.Double(getX(), getY());

    // TODO we lost a wave
    if (wave == null
        || Math.abs(
                myPos.distance(wave.getFiringPosition())
                    - (getTime() - wave.getFiringTime()) * wave.getVelocity())
            > Costants.SURFING_MAX_DISTANE_HITTED_WAVE) return;

    double firingOffset =
        org.pattern.utils.Utils.firingOffset(
            wave.getFiringPosition(), wave.getTargetPosition(), myPos);
    double gf =
        firingOffset > 0 ? firingOffset / wave.getMaxMAE() : -firingOffset / wave.getMinMAE();

    storages.get(event.getName()).visit(gf);
  }
Ejemplo n.º 3
0
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {

    info = new EnemyInfo(en, getTime());
    Enemy enemy = enemies.get(event.getName());

    if (enemy == null) {
      enemy = new Enemy(event, this);
      enemies.put(enemy.getName(), enemy);
      storages.put(enemy.getName(), new VisitCountStorage());
    }

    if (getTime() - enemy.getLastUpdated() < Costants.TIME_THRESHOLD
        && (enemy.getEnergy() - event.getEnergy()) > 0.
        && (enemy.getEnergy() - event.getEnergy()) < 3.1) {

      GBulletFiredEvent gBulletFiredEvent = new GBulletFiredEvent();
      gBulletFiredEvent.setFiringRobot(enemy);
      gBulletFiredEvent.setEnergy(enemy.getEnergy() - event.getEnergy());
      gBulletFiredEvent.setVelocity(20 - 3 * (enemy.getEnergy() - event.getEnergy()));
      gBulletFiredEvent.setFiringTime(getTime() - 1);
      gBulletFiredEvent.setFiringPosition(enemy.getPosition()); // TODO this or the updated one?
      gBulletFiredEvent.setTargetPosition(new Point2D.Double(getX(), getY()));
      org.pattern.utils.Utils.setWaveMAE(gBulletFiredEvent, getHeading(), getVelocity(), this);
      waves.addWave(gBulletFiredEvent);
    }

    enemy.updateEnemy(event, this);
    enemies.put(enemy.getName(), enemy);

    if (!meleeRadar) {
      Double radarTurn = getHeading() - getRadarHeading() + enemy.getBearing();
      setTurnRadarRight(Utils.normalRelativeAngleDegrees(radarTurn));
    }

    doShooting();
  }
Ejemplo n.º 4
0
  private void drawWaveAndMae(GBulletFiredEvent wave, Graphics2D g) {
    double maeLength = 300;
    double radius = wave.getVelocity() * (getTime() - wave.getFiringTime());
    g.drawArc(
        (int) (wave.getFiringPosition().getX() - radius),
        (int) (wave.getFiringPosition().getY() - radius),
        (int) radius * 2,
        (int) radius * 2,
        0,
        360);
    g.drawRect(
        (int) wave.getFiringPosition().getX() - 5,
        (int) wave.getFiringPosition().getY() - 5,
        10,
        10);

    double absBearing =
        org.pattern.utils.Utils.absBearing(wave.getFiringPosition(), wave.getTargetPosition());

    drawPoint(wave.getFiringPosition(), 4, g);
    drawPoint(wave.getTargetPosition(), 4, g);
    // //draw MAE
    g.drawLine(
        (int) wave.getFiringPosition().getX(),
        (int) wave.getFiringPosition().getY(),
        (int) (wave.getTargetPosition().getX()),
        (int) (wave.getTargetPosition().getY()));

    g.drawLine(
        (int) wave.getFiringPosition().getX(),
        (int) wave.getFiringPosition().getY(),
        (int)
            (wave.getFiringPosition().getX()
                + Math.sin(Math.toRadians(absBearing + wave.getMaxMAE())) * maeLength),
        (int)
            (wave.getFiringPosition().getY()
                + Math.cos(Math.toRadians(absBearing + wave.getMaxMAE())) * maeLength));

    g.drawLine(
        (int) wave.getFiringPosition().getX(),
        (int) wave.getFiringPosition().getY(),
        (int)
            (wave.getFiringPosition().getX()
                + Math.sin(Math.toRadians(absBearing + wave.getMinMAE())) * maeLength),
        (int)
            (wave.getFiringPosition().getY()
                + Math.cos(Math.toRadians(absBearing + wave.getMinMAE())) * maeLength));
  }