示例#1
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));
  }
示例#2
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;
  }
示例#3
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);
  }