Class: Beefdump::Map::Base
- Inherits:
-
Object
- Object
- Beefdump::Map::Base
- Defined in:
- lib/beefdump/map/map.rb
Constant Summary collapse
- MAP_FORMAT_VERSION =
"1.0"
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#tile_height ⇒ Object
readonly
Returns the value of attribute tile_height.
-
#tile_width ⇒ Object
readonly
Returns the value of attribute tile_width.
-
#tilesets ⇒ Object
readonly
Returns the value of attribute tilesets.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #background_at(x, y, width = 1, height = 1) ⇒ Object
- #get_initial_state ⇒ Object
-
#initialize(map_name, map_data) ⇒ Base
constructor
A new instance of Base.
- #objects_at(x, y) ⇒ Object
- #tileset_for(gid) ⇒ Object
Constructor Details
#initialize(map_name, map_data) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/beefdump/map/map.rb', line 15 def initialize(map_name, map_data) @name = map_name check_compatibility!(map_data) load_map_attributes!(map_data) load_layers!(map_data) load_tilesets!(map_data) load_objects!(map_data) @raw_data = map_data end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def height @height end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def layers @layers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def name @name end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def objects @objects end |
#tile_height ⇒ Object (readonly)
Returns the value of attribute tile_height.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def tile_height @tile_height end |
#tile_width ⇒ Object (readonly)
Returns the value of attribute tile_width.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def tile_width @tile_width end |
#tilesets ⇒ Object (readonly)
Returns the value of attribute tilesets.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def tilesets @tilesets end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/beefdump/map/map.rb', line 13 def width @width end |
Instance Method Details
#background_at(x, y, width = 1, height = 1) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/beefdump/map/map.rb', line 28 def background_at(x, y, width = 1, height = 1) tiles = [] @layers.each do |layer| field = Array.new(width).map {|e| Array.new(height).map {|e| nil}} for diff_x in 0..(width - 1) for diff_y in 0..(height - 1) field[diff_x][diff_y] = layer.field[y + diff_y] ? layer.field[y + diff_y][x + diff_x] : nil end end tiles << field end tiles end |
#get_initial_state ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/beefdump/map/map.rb', line 58 def get_initial_state Logger.info("Loading initial state for map '#{@name}'.") initial_state_file = "#{MAP_PATH}/#{@name}.isx" raise "Initial state file for map '#{@name}' not found!" unless File.exist?(initial_state_file) XmlSimple.xml_in(initial_state_file) end |
#objects_at(x, y) ⇒ Object
43 44 45 |
# File 'lib/beefdump/map/map.rb', line 43 def objects_at(x, y) objects = @objects.select {|o| o.is_at?(x, y)} end |
#tileset_for(gid) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/beefdump/map/map.rb', line 47 def tileset_for(gid) return unless gid chosen = nil @tilesets.each do |tileset| break if chosen && gid < tileset.first_gid chosen = tileset if gid >= tileset.first_gid end chosen end |