implement block class

This commit is contained in:
2025-01-31 20:06:47 +08:00
parent 64c710aae7
commit d7f5e990fd
3 changed files with 65 additions and 10 deletions

View File

@@ -1,9 +1,10 @@
import random
from module import WIDTH, BLOCK_SIZE, HEIGHT
from module.block import StoneBlock, GrassBlock, DirtBlock, AirBlock, Block
# 生成地形
def generate_terrain():
def generate_terrain() -> list[list[Block]]:
world = []
ground_level = HEIGHT // BLOCK_SIZE // 2
@@ -12,13 +13,13 @@ def generate_terrain():
height = ground_level + random.randint(-3, 3)
for y in range(HEIGHT // BLOCK_SIZE):
if y > height + 2:
column.append("stone")
column.append(StoneBlock(x, y))
elif y == height:
column.append("grass")
column.append(GrassBlock(x, y))
elif y > height - 3:
column.append("dirt")
column.append(DirtBlock(x, y))
else:
column.append("air")
column.append(AirBlock(x, y))
world.append(column)
return world