Exemplo n.º 1
0
 private void checkWallCollision() {
   if ((x - RADIUS <= 0)
       || (y - RADIUS <= 0)
       || (x + RADIUS >= battleRules.getBattlefieldWidth())
       || (y + RADIUS >= battleRules.getBattlefieldHeight())) {
     state = BulletState.HIT_WALL;
     frame = 0;
     owner.addEvent(new BulletMissedEvent(createBullet(false)));
   }
 }
Exemplo n.º 2
0
  private void checkBulletCollision(List<BulletPeer> bullets) {
    for (BulletPeer b : bullets) {
      if (b != null && b != this && b.isActive() && intersect(b.boundingLine)) {
        state = BulletState.HIT_BULLET;
        frame = 0;
        x = lastX;
        y = lastY;

        b.state = BulletState.HIT_BULLET;
        b.frame = 0;
        b.x = b.lastX;
        b.y = b.lastY;

        owner.addEvent(new BulletHitBulletEvent(createBullet(false), b.createBullet(true)));
        b.owner.addEvent(new BulletHitBulletEvent(b.createBullet(false), createBullet(true)));
        break;
      }
    }
  }
Exemplo n.º 3
0
  private void checkRobotCollision(List<RobotPeer> robots) {
    for (RobotPeer otherRobot : robots) {
      if (!(otherRobot == null || otherRobot == owner || otherRobot.isDead())
          && otherRobot.getBoundingBox().intersectsLine(boundingLine)) {

        state = BulletState.HIT_VICTIM;
        frame = 0;
        victim = otherRobot;

        double damage = Rules.getBulletDamage(power);
        double score = damage;

        if (score > otherRobot.getEnergy()) {
          score = otherRobot.getEnergy();
        }
        otherRobot.updateEnergy(-damage);

        boolean teamFire =
            (owner.getTeamPeer() != null && owner.getTeamPeer() == otherRobot.getTeamPeer());

        if (!teamFire) {
          owner.getRobotStatistics().scoreBulletDamage(otherRobot.getName(), score);
        }

        if (otherRobot.getEnergy() <= 0) {
          if (otherRobot.isAlive()) {
            otherRobot.kill();
            if (!teamFire) {
              final double bonus = owner.getRobotStatistics().scoreBulletKill(otherRobot.getName());

              if (bonus > 0) {
                owner.println(
                    "SYSTEM: Bonus for killing "
                        + (owner.getNameForEvent(otherRobot) + ": " + (int) (bonus + .5)));
              }
            }
          }
        }
        owner.updateEnergy(Rules.getBulletHitBonus(power));

        Bullet bullet = createBullet(false);

        otherRobot.addEvent(
            new HitByBulletEvent(
                robocode.util.Utils.normalRelativeAngle(
                    heading + Math.PI - otherRobot.getBodyHeading()),
                bullet));

        owner.addEvent(
            new BulletHitEvent(owner.getNameForEvent(otherRobot), otherRobot.getEnergy(), bullet));

        double newX, newY;

        if (otherRobot.getBoundingBox().contains(lastX, lastY)) {
          newX = lastX;
          newY = lastY;

          setX(newX);
          setY(newY);
        } else {
          newX = x;
          newY = y;
        }

        deltaX = newX - otherRobot.getX();
        deltaY = newY - otherRobot.getY();

        break;
      }
    }
  }