-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld.py
More file actions
26 lines (21 loc) · 863 Bytes
/
world.py
File metadata and controls
26 lines (21 loc) · 863 Bytes
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
import os
import random
import numpy as np
from cities import Cities
import pregenerator
import worldgen
class World:
world_elevation: np.ndarray
world_color: np.ndarray
cities: Cities
def __init__(self):
if os.path.exists("pregen/world_0.pkl"): # If the pregenerator has been run, use a pregenerated world.
world_num = random.randint(0, 99)
print(f"Loading pregenerated world #{world_num}")
self.world_elevation, self.world_color = pregenerator.load_world(world_num)
else: # otherwise, generate a new one
print(f"Generating a new world...")
self.world_elevation = worldgen.get_elevation((640, 480))
self.world_color = worldgen.elevation_to_rgba(self.world_elevation)
# generate 10 random cities
self.cities = Cities(self.world_elevation)