25 lines
766 B
Python
25 lines
766 B
Python
import random
|
|
from module import WIDTH, BLOCK_SIZE, HEIGHT
|
|
from module.block import StoneBlock, GrassBlock, DirtBlock, AirBlock, Block
|
|
|
|
|
|
# 生成地形
|
|
def generate_terrain() -> list[list[Block]]:
|
|
world = []
|
|
ground_level = HEIGHT // BLOCK_SIZE // 2
|
|
|
|
for x in range(WIDTH // BLOCK_SIZE):
|
|
column = []
|
|
height = ground_level + random.randint(-3, 3)
|
|
for y in range(HEIGHT // BLOCK_SIZE):
|
|
if y > height + 2:
|
|
column.append(StoneBlock(x, y))
|
|
elif y == height:
|
|
column.append(GrassBlock(x, y))
|
|
elif y > height - 3:
|
|
column.append(DirtBlock(x, y))
|
|
else:
|
|
column.append(AirBlock(x, y))
|
|
world.append(column)
|
|
|
|
return world |