-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.py
More file actions
40 lines (32 loc) · 1.22 KB
/
World.py
File metadata and controls
40 lines (32 loc) · 1.22 KB
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
from Constants import *
from Chunk import Chunk
from Interact import BlockHandler
class World:
def __init__(self, app):
self.app = app
self.chunks = [None for _ in range(WORLD_VOL)]
self.blocks = np.empty([WORLD_VOL, CHUNK_VOL], dtype='uint8')
self.build_chunks()
self.build_chunk_mesh()
self.block_handler = BlockHandler(self)
def build_chunks(self):
for x in range(WORLD_W):
for y in range(WORLD_H):
for z in range(WORLD_D):
chunk = Chunk(self, position=(x, y, z))
chunk_index = x + WORLD_W * z + WORLD_AREA * y
self.chunks[chunk_index] = chunk
# put the chunk blocks in a separate array
self.blocks[chunk_index] = chunk.build_blocks()
# get pointer to blocks
chunk.blocks = self.blocks[chunk_index]
def build_chunk_mesh(self):
for chunk in self.chunks:
chunk.build_mesh()
def update(self):
self.block_handler.update()
def render(self):
for chunk in self.chunks:
chunk.render()
for chunk in self.chunks:
chunk.render_transparent()