-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcity.py
37 lines (31 loc) · 1.17 KB
/
city.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
import random
import numpy as np
from scenery_objects import *
class City:
def __init__(self, name, desc, parts, commodities, pos, size, bgm):
self.name = name
self.desc = desc
self.parts = parts
self.commodities = commodities
self.pos = pos
self.size = size
self.bgm = bgm
self.buildings = self.generate()
def generate(self):
buildings = []
Nx = int(100 * self.size)
Nz = int(100 * self.size)
chance = 0.01
building_spacing_x = 50
building_spacing_z = 50
building_area_corner_x = Nx / 2 * building_spacing_x + self.pos[0]
building_area_corner_z = Nz / 2 * building_spacing_z + self.pos[2]
for idx_x in range(Nx):
for idx_z in range(Nz):
if random.uniform(0, 1) < chance:
c_x = -building_area_corner_x + idx_x * building_spacing_x
c_z = -building_area_corner_z + idx_z * building_spacing_z
new_pos = np.array([c_x, 0, c_z])
new_building = RandomBuilding(new_pos)
buildings.append(new_building)
return buildings