示例#1
0
  private Bullet createBullet(boolean hideOwnerName) {
    String ownerName =
        (owner == null) ? null : (hideOwnerName ? getNameForEvent(owner) : owner.getName());
    String victimName =
        (victim == null) ? null : (hideOwnerName ? victim.getName() : getNameForEvent(victim));

    return new Bullet(heading, x, y, power, ownerName, victimName, isActive(), bulletId);
  }
示例#2
0
 public BulletPeer(RobotPeer owner, BattleRules battleRules, int bulletId) {
   super();
   this.owner = owner;
   this.battleRules = battleRules;
   this.bulletId = bulletId;
   state = BulletState.FIRED;
   color = owner.getBulletColor(); // Store current bullet color set on robot
 }
示例#3
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)));
   }
 }
示例#4
0
 public void update(List<RobotPeer> robots, List<BulletPeer> bullets) {
   frame++;
   if (isActive()) {
     updateMovement();
     checkWallCollision();
     if (isActive()) {
       checkRobotCollision(robots);
     }
     if (isActive() && bullets != null) {
       checkBulletCollision(bullets);
     }
   }
   updateBulletState();
   owner.addBulletStatus(createStatus());
 }
示例#5
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;
      }
    }
  }
示例#6
0
 public double getPaintY() {
   return (state == BulletState.HIT_VICTIM && victim != null) ? victim.getY() + deltaY : y;
 }
示例#7
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;
      }
    }
  }
示例#8
0
 private String getNameForEvent(RobotPeer otherRobot) {
   if (battleRules.getHideEnemyNames() && !owner.isTeamMate(otherRobot)) {
     return otherRobot.getAnnonymousName();
   }
   return otherRobot.getName();
 }