-
Notifications
You must be signed in to change notification settings - Fork 0
/
world_generator.py
84 lines (80 loc) · 2.78 KB
/
world_generator.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import tcod as libtcod
from noise import create_noise
from entity import Entity
from palette import palette
import numpy as np
def get_world():
samples = create_noise()
entities = []
for i, sample in enumerate(samples, start=0):
for j, num in enumerate(sample, start=0):
terrain_type = get_type(num)
info = terrain_type.get('info')
entity = Entity(i, j, terrain_type.get('char'), terrain_type.get('color').get('fg'), terrain_type.get('color').get('bg'), info, terrain_type.get('height'), terrain_type.get('temp'), terrain_type.get('magic'))
entities.append(entity)
return entities
def get_type(num):
if (num < -0.7):
color = palette[7]
char = '≈'
info = 'Deep Water'
height = np.random.uniform(-10.0, -3.0)
temp = 3 if height > -5.0 else 0
magic = '•' * np.random.randint(1, 4)
elif (num < -0.5 and num > -0.7):
color = palette[1]
char = '≈'
info = 'Shallow Water'
height = np.random.uniform(-2.0, -0.2)
temp = 20
magic = '•' * np.random.randint(1, 4)
elif (num > -0.5 and num < -0.3):
color = palette[6]
char = '.'
info = 'Sand'
height = np.random.uniform(0.0, 0.3)
temp = 30
magic = '•' * np.random.randint(1, 4)
elif (num > -0.2 and num < -0.1):
color = palette[2]
char = '.'
info = 'Dirt'
height = np.random.uniform(0.0, 1.0)
temp = 28
magic = '•' * np.random.randint(1, 4)
elif (num > -0.1 and num < 0.1):
color = palette[5]
char = ','
info = 'Grass'
height = np.random.uniform(0.0, 1.0)
temp = 26
magic = '•' * np.random.randint(1, 4)
elif(num > 0.1 and num < 0.4):
color = palette[0]
char = '♠'
info = 'Spring Tree'
height = np.random.randint(2, 10)
temp = 20 if height > 5 else 25
magic = '•' * np.random.randint(1, 4)
elif(num > 0.4 and num < 0.6):
color = palette[3]
char = '▲'
info = 'Mountain'
height = np.random.randint(250, 800)
temp = 18 if height < 500 else 12
magic = '•' * np.random.randint(1, 4)
elif(num > 0.6):
color = palette[4]
char = '▲'
info = 'High Mountain'
height = np.random.randint(800, 2800)
temp = 3 if height < 1500 else -2
magic = '•' * np.random.randint(1, 4)
else:
color = palette[0]
char = '♠'
info = 'Spring Tree'
height = np.random.randint(2, 10)
temp = 20 if height > 5 else 25
magic = '•' * np.random.randint(1, 4)
return {'color': color, 'char': char, 'info': info, 'height': np.round(height, 2), 'temp': temp, 'magic': magic}