示例#1
0
/**
 * @brief Displays the tile image on a surface.
 * @param destination the destination surface
 * @param dst_position position of the tile pattern on the destination surface
 * @param tileset the tileset of this tile
 */
void ParallaxTilePattern::display(Surface *destination, const Rectangle &dst_position, Tileset &tileset) {

  Rectangle src = position_in_tileset;
  Rectangle dst = dst_position;

  int offset_x, offset_y; // display the tile with an offset that depends on its position modulo its size

  if (dst.get_x() >= 0) {
    offset_x = dst.get_x() % src.get_width();
  }
  else { // the modulo operation does not like negative numbers
    offset_x = src.get_width() - (-dst.get_x() % src.get_width());
  }

  if (dst.get_y() >= 0) {
    offset_y = dst.get_y() % src.get_height();
  }
  else {
    offset_y = src.get_height() - (-dst.get_y() % src.get_height());
  }

  // apply a scrolling ratio
  offset_x /= 2;
  offset_y /= 2;

  src.add_x(offset_x);
  src.add_width(-offset_x);
  src.add_y(offset_y);
  src.add_height(-offset_y);
  tileset.get_tiles_image()->blit(src, destination, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_y(offset_y);
  src.add_height(-offset_y);
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  tileset.get_tiles_image()->blit(src, destination, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_x(offset_x);
  src.add_width(-offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset.get_tiles_image()->blit(src, destination, dst);

  src = position_in_tileset;
  dst = dst_position;
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset.get_tiles_image()->blit(src, destination, dst);
}
示例#2
0
/**
 * \brief Draws the tile image on a surface.
 * \param dst_surface the surface to draw
 * \param dst_position position where tile pattern should be drawn on dst_surface
 * \param tileset the tileset of this tile
 * \param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void SimpleTilePattern::draw(
    const SurfacePtr& dst_surface,
    const Point& dst_position,
    Tileset& tileset,
    const Point& /* viewport */
) {
  const SurfacePtr& tileset_image = tileset.get_tiles_image();
  tileset_image->draw_region(position_in_tileset, dst_surface, dst_position);
}
/**
 * \brief Draws the tile image on a surface.
 * \param dst_surface the surface to draw
 * \param dst_position position where tile pattern should be drawn on dst_surface
 * \param tileset the tileset of this tile
 * \param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void TimeScrollingTilePattern::draw(
    const SurfacePtr& dst_surface,
    const Point& dst_position,
    Tileset& tileset,
    const Point& /* viewport */
) {
  Rectangle src = position_in_tileset;
  Point dst = dst_position;

  Point offset; // draw the tile with an offset that depends on the time

  offset.x = src.get_width() - (shift % src.get_width());
  offset.y = shift % src.get_height();

  src.add_x(offset.x);
  src.add_width(-offset.x);
  src.add_y(offset.y);
  src.add_height(-offset.y);
  tileset.get_tiles_image()->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_y(offset.y);
  src.add_height(-offset.y);
  dst.x += src.get_width() - offset.x;
  src.set_width(offset.x);
  tileset.get_tiles_image()->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_x(offset.x);
  src.add_width(-offset.x);
  dst.y += src.get_height() - offset.y;
  src.set_height(offset.y);
  tileset.get_tiles_image()->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  dst.x += src.get_width() - offset.x;
  src.set_width(offset.x);
  dst.y += src.get_height() - offset.y;
  src.set_height(offset.y);
  tileset.get_tiles_image()->draw_region(src, dst_surface, dst);
}
/**
 * @brief Draws the tile image on a surface.
 * @param dst_surface the surface to draw
 * @param dst_position position where tile pattern should be drawn on dst_surface
 * @param tileset the tileset of this tile
 * @param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void ParallaxScrollingTilePattern::draw(Surface& dst_surface,
    const Rectangle& dst_position, Tileset& tileset,
    const Rectangle& viewport) {

  Surface& tileset_image = tileset.get_tiles_image();
  Rectangle dst(dst_position);
  dst.add_xy(viewport.get_x() / ratio, viewport.get_y() / ratio);
  tileset_image.draw_region(position_in_tileset, dst_surface, dst);

  // one day, we can implement several scrolling layers just by changing the ratio
}
/**
 * @brief Displays the tile image on a surface.
 * @param dst_surface the surface to draw
 * @param dst_position position where tile pattern should be displayed on dst_surface
 * @param tileset the tileset of this tile
 * @param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void TimeScrollingTilePattern::display(Surface* dst_surface, const Rectangle& dst_position,
    Tileset& tileset, const Rectangle& viewport) {

  Rectangle src = position_in_tileset;
  Rectangle dst = dst_position;

  int offset_x, offset_y; // display the tile with an offset that depends on the time

  offset_x = src.get_width() - (shift % src.get_width());
  offset_y = shift % src.get_height();

  src.add_x(offset_x);
  src.add_width(-offset_x);
  src.add_y(offset_y);
  src.add_height(-offset_y);
  tileset.get_tiles_image()->blit(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_y(offset_y);
  src.add_height(-offset_y);
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  tileset.get_tiles_image()->blit(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_x(offset_x);
  src.add_width(-offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset.get_tiles_image()->blit(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset.get_tiles_image()->blit(src, dst_surface, dst);
}
示例#6
0
/**
 * @brief Displays the tile image on a surface.
 * @param dst_surface the surface to draw
 * @param dst_position position where tile pattern should be displayed on dst_surface
 * @param tileset the tileset of this tile
 * @param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void AnimatedTilePattern::display(Surface* dst_surface, const Rectangle& dst_position,
    Tileset& tileset, const Rectangle& viewport) {

  Surface* tileset_image = tileset.get_tiles_image();
  const Rectangle& src = position_in_tileset[current_frames[sequence]];
  Rectangle dst(dst_position);

  if (parallax) {
    dst.add_xy(viewport.get_x() / ParallaxScrollingTilePattern::ratio,
        viewport.get_y() / ParallaxScrollingTilePattern::ratio);
  }

  tileset_image->blit(src, dst_surface, dst);
}
示例#7
0
/**
 * \brief Draws the tile image on a surface.
 * \param dst_surface the surface to draw
 * \param dst_position position where tile pattern should be drawn on dst_surface
 * \param tileset the tileset of this tile
 * \param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void AnimatedTilePattern::draw(
    const SurfacePtr& dst_surface,
    const Point& dst_position,
    Tileset& tileset,
    const Point& viewport
) {
  const SurfacePtr& tileset_image = tileset.get_tiles_image();
  const Rectangle& src = position_in_tileset[current_frames[sequence]];
  Point dst = dst_position;

  if (parallax) {
    dst += viewport / ParallaxScrollingTilePattern::ratio;
  }

  tileset_image->draw_region(src, dst_surface, dst);
}
/**
 * \brief Draws the tile image on a surface.
 * \param dst_surface the surface to draw
 * \param dst_position position where tile pattern should be drawn on dst_surface
 * \param tileset the tileset of this tile
 * \param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void SelfScrollingTilePattern::draw(
    const SurfacePtr& dst_surface,
    const Point& dst_position, Tileset& tileset,
    const Point& /* viewport */) {

  Rectangle src = position_in_tileset;
  Point dst = dst_position;

  // draw the tile with an offset that depends on its position modulo its size
  Point offset;

  if (dst.x >= 0) {
    offset.x = dst.x % src.get_width();
  }
  else { // the modulo operation does not like negative numbers
    offset.x = src.get_width() - (-dst.x % src.get_width());
  }

  if (dst.y >= 0) {
    offset.y = dst.y % src.get_height();
  }
  else {
    offset.y = src.get_height() - (-dst.y % src.get_height());
  }

  // apply a scrolling ratio
  offset /= 2;

  // draw the pattern in four steps
  const SurfacePtr& tileset_image = tileset.get_tiles_image();

  src.add_x(offset.x);
  src.add_width(-offset.x);
  src.add_y(offset.y);
  src.add_height(-offset.y);
  tileset_image->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_y(offset.y);
  src.add_height(-offset.y);
  dst.x += src.get_width() - offset.x;
  src.set_width(offset.x);
  tileset_image->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_x(offset.x);
  src.add_width(-offset.x);
  dst.y += src.get_height() - offset.y;
  src.set_height(offset.y);
  tileset_image->draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  dst.x += src.get_width() - offset.x;
  src.set_width(offset.x);
  dst.y += src.get_height() - offset.y;
  src.set_height(offset.y);
  tileset_image->draw_region(src, dst_surface, dst);
}
/**
 * @brief Draws the tile image on a surface.
 * @param dst_surface the surface to draw
 * @param dst_position position where tile pattern should be drawn on dst_surface
 * @param tileset the tileset of this tile
 * @param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void SelfScrollingTilePattern::draw(Surface& dst_surface,
    const Rectangle& dst_position, Tileset& tileset,
    const Rectangle& viewport) {

  Rectangle src = position_in_tileset;
  Rectangle dst = dst_position;

  // draw the tile with an offset that depends on its position modulo its size
  int offset_x, offset_y;

  if (dst.get_x() >= 0) {
    offset_x = dst.get_x() % src.get_width();
  }
  else { // the modulo operation does not like negative numbers
    offset_x = src.get_width() - (-dst.get_x() % src.get_width());
  }

  if (dst.get_y() >= 0) {
    offset_y = dst.get_y() % src.get_height();
  }
  else {
    offset_y = src.get_height() - (-dst.get_y() % src.get_height());
  }

  // apply a scrolling ratio
  offset_x /= 2;
  offset_y /= 2;

  // draw the pattern in four steps
  Surface& tileset_image = tileset.get_tiles_image();

  src.add_x(offset_x);
  src.add_width(-offset_x);
  src.add_y(offset_y);
  src.add_height(-offset_y);
  tileset_image.draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_y(offset_y);
  src.add_height(-offset_y);
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  tileset_image.draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  src.add_x(offset_x);
  src.add_width(-offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset_image.draw_region(src, dst_surface, dst);

  src = position_in_tileset;
  dst = dst_position;
  dst.add_x(src.get_width() - offset_x);
  src.set_width(offset_x);
  dst.add_y(src.get_height() - offset_y);
  src.set_height(offset_y);
  tileset_image.draw_region(src, dst_surface, dst);
}
示例#10
0
/**
 * @brief Draws the tile image on a surface.
 * @param dst_surface the surface to draw
 * @param dst_position position where tile pattern should be drawn on dst_surface
 * @param tileset the tileset of this tile
 * @param viewport coordinates of the top-left corner of dst_surface relative
 * to the map (may be used for scrolling tiles)
 */
void SimpleTilePattern::draw(Surface& dst_surface, const Rectangle& dst_position,
    Tileset& tileset, const Rectangle& viewport) {

  Surface& tileset_image = tileset.get_tiles_image();
  tileset_image.draw_region(position_in_tileset, dst_surface, dst_position);
}
示例#11
0
/**
 * @brief Displays the tile on a surface.
 * @param destination the destination surface
 * @param dst_position position of the tile pattern on the destination surface
 * @param tileset the tileset of this tile pattern
 */
void AnimatedTilePattern::display(Surface *destination, const Rectangle &dst_position, Tileset &tileset) {

  Surface *tileset_image = tileset.get_tiles_image();
  tileset_image->blit(position_in_tileset[current_frames[sequence]], destination, dst_position);
}