@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; }
@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); }