/**
  * Create a new BackgroundPainter. The tiles used for painting will be cut non-uniformly, so that
  * the grid will be placed according to the given dimensions.
  *
  * @param image image name
  * @param leftWidth width of the left tile row
  * @param centerWidth width of the center tile row
  * @param topHeight height of the top tile row
  * @param centerHeight height of the center tile row
  */
 public BackgroundPainter(
     String image, int leftWidth, int centerWidth, int topHeight, int centerHeight) {
   tileWidth = 0;
   tileHeight = 0;
   SpriteStore store = SpriteStore.get();
   Sprite mother = store.getSprite(image);
   images = new Sprite[9];
   int[] widths = new int[3];
   widths[0] = leftWidth;
   widths[1] = centerWidth;
   widths[2] = mother.getWidth() - leftWidth - centerWidth;
   int[] heights = new int[3];
   heights[0] = topHeight;
   heights[1] = centerHeight;
   heights[2] = mother.getHeight() - topHeight - centerHeight;
   int x = 0;
   int y = 0;
   int i = 0;
   for (int yInd = 0; yInd < 3; yInd++) {
     for (int xInd = 0; xInd < 3; xInd++) {
       images[i] = store.getTile(mother, x, y, widths[xInd], heights[yInd]);
       x += widths[xInd];
       i++;
     }
     x = 0;
     y += heights[yInd];
   }
 }
 /**
  * Build the visual representation of this entity.
  *
  * @param entity entity for which to build the representation
  */
 @Override
 protected void buildRepresentation(IEntity entity) {
   final SpriteStore store = SpriteStore.get();
   ZoneInfo info = ZoneInfo.get();
   Sprite sprite =
       store.getModifiedSprite(
           translate(getClassResourcePath()), info.getZoneColor(), info.getColorMethod());
   setSprite(sprite);
 }
 /**
  * Create a new BackgroundPainter.
  *
  * @param image image name. The image dimensions should be multiples of 3. The tiles used for
  *     painting will be the image divided uniformly to three in both vertical and horizontal
  *     directions
  */
 public BackgroundPainter(String image) {
   SpriteStore store = SpriteStore.get();
   Sprite mother = store.getSprite(image);
   this.tileWidth = mother.getWidth() / 3;
   this.tileHeight = mother.getHeight() / 3;
   images = new Sprite[9];
   int i = 0;
   for (int y = 0; y < 3 * tileHeight; y += tileHeight) {
     for (int x = 0; x < 3 * tileWidth; x += tileWidth) {
       images[i] = store.getTile(mother, x, y, tileWidth, tileHeight);
       i++;
     }
   }
 }
예제 #4
0
 /**
  * Create a new ImageEffect.
  *
  * @param view the view where the effect binds itself to
  * @param image name of the image that is used for the the animation
  */
 public ImageEffect(Entity2DView view, String image) {
   this.view = view;
   SpriteStore store = SpriteStore.get();
   /*
    * TODO: get the frame delays from a configuration file. Also the file
    * should specify whether the effect must obey zone coloring.
    */
   Sprite base = store.getSprite(IMAGE_LOCATION + image + ".png");
   int width = base.getWidth();
   int height = base.getHeight();
   int count = width / height;
   Sprite[] frames = store.getTiles(base, 0, 0, count, height, height);
   sequence = new SequenceSprite(this, frames, 100);
   view.attachSprite(sequence, HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE, 0, 0);
 }
예제 #5
0
  /**
   * Create an <code>AnimatedIcon</code> from a Sprite. Each animation frame will be a rectangle of
   * the same height that the original sprite.
   *
   * @param baseSprite animation frames image
   * @param delay delay between the frames
   */
  AnimatedIcon(Sprite baseSprite, int delay) {
    setOpaque(false);

    int height = baseSprite.getHeight();
    int frames = baseSprite.getWidth() / height;

    this.sprite = new Sprite[frames];
    timer = new Timer(delay, timerTask);

    setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));

    final SpriteStore store = SpriteStore.get();

    for (int i = 0; i < frames; i++) {
      sprite[i] = store.getTile(baseSprite, i * height, 0, height, height);
    }
  }
예제 #6
0
  /**
   * Populate named state sprites.
   *
   * @param map The map to populate.
   */
  @Override
  protected void buildSprites(Door entity, final Map<Object, Sprite> map) {
    final String name = entity.getEntityClass();

    final SpriteStore store = SpriteStore.get();

    if (name == null) {
      width = IGameScreen.SIZE_UNIT_PIXELS;
      height = IGameScreen.SIZE_UNIT_PIXELS;

      final Sprite emptySprite = store.getEmptySprite(width, height);

      map.put(STATE_OPEN, emptySprite);
      map.put(STATE_CLOSED, emptySprite);
    } else {
      ZoneInfo info = ZoneInfo.get();
      final Sprite tiles =
          store.getModifiedSprite(translate(name), info.getZoneColor(), info.getColorMethod());

      width = tiles.getWidth();
      height = tiles.getHeight() / 2;

      map.put(STATE_OPEN, store.getTile(tiles, 0, 0, width, height));
      map.put(STATE_CLOSED, store.getTile(tiles, 0, height, width, height));
    }

    calculateOffset(entity, width, height);
  }