Class: FloraGenerator
- Inherits:
-
Object
- Object
- FloraGenerator
- Defined in:
- lib/flora_generator.rb
Overview
Generates flora for the given tiles
Instance Attribute Summary collapse
-
#tiles ⇒ Object
readonly
Returns the value of attribute tiles.
Instance Method Summary collapse
- #generate(config) ⇒ Object
-
#initialize(tiles) ⇒ FloraGenerator
constructor
A new instance of FloraGenerator.
Constructor Details
#initialize(tiles) ⇒ FloraGenerator
Returns a new instance of FloraGenerator.
9 10 11 |
# File 'lib/flora_generator.rb', line 9 def initialize(tiles) @tiles = tiles end |
Instance Attribute Details
#tiles ⇒ Object (readonly)
Returns the value of attribute tiles.
7 8 9 |
# File 'lib/flora_generator.rb', line 7 def tiles @tiles end |
Instance Method Details
#generate(config) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flora_generator.rb', line 13 def generate(config) return unless config.generate_flora puts 'generating flora...' if config.verbose tiles.each do |row| row.each do |tile| next unless tile.biome.flora_available range_max_value = tiles[(tile.y - tile.biome.flora_range)...(tile.y + tile.biome.flora_range)]&.map do |r| r[(tile.x - tile.biome.flora_range)...(tile.x + tile.biome.flora_range)] end&.flatten&.map(&:height)&.max tile.add_flora if range_max_value == tile.height end end end |