Game Development Reference
In-Depth Information
Perlin noise
Now, we could implement the algorithm ourselves, but there is
perlin_noise
gem already
available, it looks pretty solid, so we will use it.
The following program generates
100x100
map with 30% chance of water, 15% chance
of sand and 55% chance of grass:
02-warmup/perlin_noise_map.rb
1
require
'gosu'
2
require
'gosu_texture_packer'
3
require
'perlin_noise'
4
5
def
media_path
(file)
6
File
.
join(
File
.
dirname(
File
.
dirname(
7
__FILE__
)),
'media'
, file)
8
end
9
10
class
GameWindow
<
Gosu
::
Window
11
MAP_WIDTH
= 100
12
MAP_HEIGHT
= 100
13
WIDTH
= 800
14
HEIGHT
= 600
15
TILE_SIZE
= 128
16
17
def
initialize
18
super
(
WIDTH
,
HEIGHT
,
false
)