Class: Core::Tileset

Inherits:
Object show all
Defined in:
lib/tileset.rb

Constant Summary collapse

@@tilesets =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fgid, name, filename, props) ⇒ Tileset

Returns a new instance of Tileset.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tileset.rb', line 8

def initialize(fgid, name, filename, props)
  @first = fgid
  @name = name
  if !@@tilesets[filename]
    @@tilesets[filename] = Gosu::Image.load_tiles(Core.window, "#{Core::LIBRARY_PATH}/#{filename}", 32, 32, true)
  end
  @tiles = @@tilesets[filename].dup
  @props = props
  @props.default = {}
  @filename = filename
  @filled = []
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/tileset.rb', line 7

def filename
  @filename
end

#firstObject (readonly)

Returns the value of attribute first.



7
8
9
# File 'lib/tileset.rb', line 7

def first
  @first
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/tileset.rb', line 7

def name
  @name
end

#propsObject (readonly)

Returns the value of attribute props.



7
8
9
# File 'lib/tileset.rb', line 7

def props
  @props
end

#tilesObject (readonly)

Returns the value of attribute tiles.



7
8
9
# File 'lib/tileset.rb', line 7

def tiles
  @tiles
end

Instance Method Details

#create_tilesObject



20
21
22
23
24
25
26
27
28
# File 'lib/tileset.rb', line 20

def create_tiles
  @filled = []
  i = 0
  @tiles.each { |tile|
    @filled.push(Core::Game::Tile.new(tile, 0, 0, 0, @props[i]))
    i += 1
  }
  return @filled
end

#tile(gid, x, y, z) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tileset.rb', line 29

def tile(gid, x, y, z)
  if gid < 0
    return nil
  end
  if @filled.empty?
    create_tiles
  end
  tile = @filled[gid].dup
  tile.x, tile.y = x, y
  tile.z = z
  return tile
end