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.
 

20 lines
666 B

import block, perlin
CHUNK_WIDTH = 32
CHUNK_HEIGHT = 32
class Chunk:
def gen_block(self, x: int, y: int):
height = int(100 + perlin.noise2d(x, 0.1) * 10)
if y < height: return block.BlockAir()
if y == height: return block.BlockGrass()
if y > height and y < height + 4: return block.BlockDirt()
return block.BlockStone()
def get(self, x: int, y: int) -> block.Block(id):
return self.blocks[x + CHUNK_WIDTH * y]
def __init__(self, x: int, y: int):
self.blocks = [self.gen_block(i % CHUNK_WIDTH + x * CHUNK_WIDTH, i // CHUNK_WIDTH + y * CHUNK_HEIGHT) for i in range(CHUNK_WIDTH * CHUNK_HEIGHT)]