forked from DizzyDogg/Wilderness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.pm
52 lines (45 loc) · 1.24 KB
/
World.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package World;
use strict;
use warnings;
use base qw(Object);
use Data::Dumper;
sub initialize {
my $self = shift;
$self->{'grid'}->{'0,0,0'} = 'new_world';
my $z = 0;
#populate 25 locations with forests
foreach my $x (-8 .. 8) {
foreach my $y (-8 .. 8) {
# my $even_coords = join ',', 2*$x, 2*$y, 2*$z;
# my $odd_coords = join ',', 2*$x-1, 2*$y-1, 2*$z;
my $location = $x%2 + $y%2;
my $biome;
if ( abs $x > 6 || abs $y > 6 ) {
$biome = 'Obstruction::Ocean';
}
elsif ( abs $x == 6 || abs $y == 6 ) {
$biome = 'Biome::Beach';
}
else {
$biome = $location == 0 ? $self->pick_random_biome() : next;
}
my $coords = join ',', $x, $y, $z;
$self->{'grid'}->{$coords} = Object::new(
$biome,
location => $coords,
world => $self,
);
}
}
return $self;
}
sub pick_random_biome {
my $self = shift;
my $random = rand();
my $biome = 'Biome::';
$biome .= $random < .2 ? 'Field' :
$random < .5 ? 'Desert' :
'Forest';
return $biome;
}
1;