Class: UT::Tile

Inherits:
Object
  • Object
show all
Defined in:
lib/ut/tile.rb

Overview

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`._

Constant Summary collapse

DEFAULT_FOREGROUND =

The default foreground color is white

Gosu::Color::WHITE
DEFAULT_BACKGROUND =

the default background color is black

Gosu::Color::BLACK
NULL =

An empty tile wih default fore- and background color

Tile.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Tile

Returns a new instance of Tile.



27
28
29
30
31
# File 'lib/ut/tile.rb', line 27

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

Instance Attribute Details

#backgroundObject

Foreground and background color of the Tile Colors are stored as an instance of ‘Gosu::Color`



18
19
20
# File 'lib/ut/tile.rb', line 18

def background
  @background
end

#foregroundObject

Foreground and background color of the Tile Colors are stored as an instance of ‘Gosu::Color`



18
19
20
# File 'lib/ut/tile.rb', line 18

def foreground
  @foreground
end

#glyphObject

The unicode character



15
16
17
# File 'lib/ut/tile.rb', line 15

def glyph
  @glyph
end

Instance Method Details

#cloneObject

Clones the tile by copying all attributes to a new Tile. Returns the cloned tile.



35
36
37
38
39
# File 'lib/ut/tile.rb', line 35

def clone
  Tile.new :glyph      => glyph,
           :foreground => foreground,
           :background => background
end