You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
858 B

2 years ago
from block import Block, BlockAir, BlockStone
import perlin
from chunk import Chunk, CHUNK_HEIGHT, CHUNK_WIDTH
class World:
def __init__(self, x: int, y: int):
self.chunks = {}
self.old_x = -1
self.old_y = -1
self.update_chunks(x, y)
pass
def update_chunks(self, x: int, y: int):
x //= CHUNK_WIDTH
y //= CHUNK_HEIGHT
if self.old_x == x and self.old_y == y: return
print("Refresh chunks")
self.chunks = {}
for i in range(x - 1, x + 2):
for j in range(y - 1, y + 2):
self.chunks[f"{i}:{j}"] = Chunk(i, j)
self.old_x = x
self.old_y = y
def get_block(self, x: int, y: int) -> Block:
return self.chunks[f"{x // CHUNK_WIDTH}:{y // CHUNK_HEIGHT}"].get(x % CHUNK_WIDTH, y % CHUNK_HEIGHT)