Ejemplo n.º 1
0
 public void enemyPosition(ScannedRobotEvent e, double x, double y) {
   // poll subtargetters for their opinions
   virtualBulletTick++;
   lastEnemyScanTime = owner.getTime();
   // only log it when we actually fire: the enemy may respond to that
   if (owner.shouldFireShot(e)) {
     double bulletPower = e.getDistance() > 500.0 ? 2.0 : 3.0;
     for (int i = 0; i < numVirtualGuns; i++) {
       double angle = targetters[i].target(e, bulletPower);
       VirtualBullet bullet = new VirtualBullet();
       bullet.targetter = i;
       bullet.x = owner.getX();
       bullet.y = owner.getY();
       bullet.velX = Targetting.bulletSpeed(bulletPower) * Math.sin(angle);
       bullet.velY = Targetting.bulletSpeed(bulletPower) * Math.cos(angle);
       bullet.lastUpdateTime = lastEnemyScanTime;
       virtualBullets.add(bullet);
     }
   }
   for (int i = 0; i < numVirtualGuns; i++) {
     targetters[i].enemyPosition(e, x, y);
   }
   enemyX = x;
   enemyY = y;
 }
Ejemplo n.º 2
0
 public void update() {
   // update all the virtual bullets
   double battleFieldX = owner.getBattleFieldWidth();
   double battleFieldY = owner.getBattleFieldHeight();
   for (int i = 0; i < virtualBullets.size(); i++) {
     VirtualBullet bullet = virtualBullets.get(i);
     long dt = lastEnemyScanTime - bullet.lastUpdateTime;
     if (dt <= 0) continue;
     bullet.x += bullet.velX * dt;
     bullet.y += bullet.velY * dt;
     bullet.lastUpdateTime = lastEnemyScanTime;
     if (bullet.x > battleFieldX || bullet.y > battleFieldY || bullet.x < 0.0 || bullet.y < 0.0) {
       // missed
       virtualBullets.remove(i);
       i--;
     } else if (Point2D.Double.distance(bullet.x, bullet.y, enemyX, enemyY) < 30.0) {
       // log in array
       successes[bullet.targetter]++;
       // hit!
       virtualBullets.remove(i);
       i--;
     }
   }
   owner.setDebugProperty("VGVBCount", "" + virtualBullets.size());
   owner.setDebugProperty(
       "VGHits",
       "circ="
           + successes[0]
           + " naive="
           + successes[1]
           + " linear="
           + successes[2]
           + " rc="
           + successes[3]
           + " rN="
           + successes[4]
           + " rW="
           + successes[5]);
   for (int i = 0; i < numVirtualGuns; i++) {
     targetters[i].update();
   }
 }