/**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
 /** Checks if the player collides with a blip, power blip, or a ghost. */
 public void checkCollision() {
   Rectangle playerRect =
       new Rectangle(player.getCenter().x - 8, player.getCenter().y - 8, 13, 13);
   for (Enemy enemy : enemies) {
     Rectangle enemyRect = new Rectangle(enemy.getCenter().x - 8, enemy.getCenter().y - 8, 13, 13);
     if (playerRect.intersects(enemyRect)) {
       if (!enemy.isAlive()) {
         continue;
       }
       if (Globals.state == ENEMY_HUNTER_STATE) {
         Globals.game.playerKilled();
         player.loseALife();
         // player is dead, so we paint the dead player screen
         paintDeadPlayer();
         try {
           // sleep to make it stay on screen
           Thread.sleep(1500);
         } catch (InterruptedException e) {
           // DO nothing
         }
         resetCanvas();
         // we return because only one enemy should be able to make a player lose a life
         return;
       } else if (Globals.state == ENEMY_HUNTED_STATE) {
         if (enemy.isAlive()) {
           enemy.setAlive(false);
           player.addPoints(POINTS_FOR_KILLING_ENEMY);
         }
       }
     } else {
       continue;
     }
   }
 }
Example #3
0
  @Override
  public ScreenImage capture(Rectangle rect) {
    Debug.log(5, "capture: " + rect);

    BufferedImage ret = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = ret.createGraphics();
    for (int i = 0; i < Screen.getNumberScreens(); i++) {
      Rectangle scrBound = Screen.getBounds(i);
      if (scrBound.intersects(rect)) {
        Rectangle inter = scrBound.intersection(rect);
        Debug.log(5, "scrBound: " + scrBound + ", inter: " + inter);
        int ix = inter.x, iy = inter.y;
        inter.x -= scrBound.x;
        inter.y -= scrBound.y;
        ScreenImage img = robots[i].captureScreen(inter);
        g2d.drawImage(img.getImage(), ix - rect.x, iy - rect.y, null);
      }
    }
    g2d.dispose();
    return new ScreenImage(rect, ret);
  }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }