Sha256: 6fd8d22f7fea1bed0c3d17e9cf0f390f7029af35a1d3f5ba512c75651862d6ac

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

module UT
  # A *Tile* stores all attributes required by a *Viewport* to draw it.
  # `Tile.new` takes an `args` hash as its only parameter.
  # The `args` hash respects three members:
  #
  #   * `:glyph`: The unicode character. _Defaults to `' '`._
  #
  #   * `:foreground`: The foreground color represented by a `Gosu::Color`
  #   instance. _Defaults to `DEFAULT_FOREGROUND`._
  #
  #   * `:background`: The background color represented by a `Gosu::Color`
  #   instance. _Defaults to `DEFAULT_BACKGROUND`._
  class Tile
    # The unicode character
    attr_accessor :glyph
    # Foreground and background color of the *Tile*
    # Colors are stored as an instance of `Gosu::Color`
    attr_accessor :foreground, :background

    # The default foreground color is white
    DEFAULT_FOREGROUND = Gosu::Color::WHITE
    # the default background color is black
    DEFAULT_BACKGROUND = Gosu::Color::BLACK
    # An empty tile wih default fore- and background color
    NULL = Tile.new

    def initialize args = {}
      self.glyph      = args[:glyph] || " "
      self.foreground = args[:foreground] || DEFAULT_FOREGROUND
      self.background = args[:background] || DEFAULT_BACKGROUND
    end

    # Clones the tile by copying all attributes to a new *Tile*. Returns the
    # cloned tile.
    def clone
      Tile.new :glyph      => glyph,
               :foreground => foreground,
               :background => background
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicodetiles-1.0.0 lib/ut/tile.rb