import random from module import WIDTH, BLOCK_SIZE, HEIGHT from module.block import StoneBlock, GrassBlock, DirtBlock, AirBlock, Block, BedrockBlock # 生成地形 def generate_terrain() -> list[list[Block]]: world = [] ground_level = HEIGHT // BLOCK_SIZE // 2 for x in range(WIDTH // BLOCK_SIZE): # # AIR BLOCK # height ============================= GRASS BLOCK # 4 DIRT BLOCK # +5 ============================= # STONE BLOCK # max ============================= BEDROCK BLOCK # column = [] height = ground_level + random.randint(-3, 3) for y in range(HEIGHT // BLOCK_SIZE): if y < height: block = AirBlock(x, y) elif y == height: block = GrassBlock(x, y) elif height < y < height + 5: block = DirtBlock(x, y) elif y == HEIGHT // BLOCK_SIZE - 1: block = BedrockBlock(x, y) else: block = StoneBlock(x, y) column.append(block) world.append(column) return world