Game Development Reference
In-Depth Information
Perlin :: Curve :: CUBIC , 2 )
trees = 0
target_trees = rand ( 300. . 500 )
while trees < target_trees do
x = rand ( 0. . MAP_WIDTH * TILE_SIZE )
y = rand ( 0. . MAP_HEIGHT * TILE_SIZE )
n = noises [ x * 0.001 , y * 0.001]
n = contrast . call(n)
if tile_at(x, y) == @grass && n > 0.5
Tree . new( @object_pool , x, y, n * 2 - 1 )
trees += 1
end
end
end
# ...
end
Perlin noise is used in similar fashion as it was when we generated map tiles. We allow
creating trees only if noise level is above 0.5 , and use noise level as seed value - n * 2
- 1 will be a number between 0 and 1 when n is in 0.5..1 range. And we only allow
creating trees on grass tiles.
Now our map looks a little better:
Hiding among procedurally generated trees
Generating Random Objects
Trees are great, but we want more detail. Let's spice things up with explosive boxes and
barrels. They will be using the same class with single sprite sheet, so while the sprite will
be chosen randomly, behavior will be the same. This new class will be called Box :
09-polishing/entities/box.rb
Search WWH ::




Custom Search