modify world generation rule

This commit is contained in:
2025-02-01 12:30:21 +08:00
parent 40fa44f936
commit 1a210382ae
4 changed files with 29 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import random
from module import WIDTH, BLOCK_SIZE, HEIGHT
from module.block import StoneBlock, GrassBlock, DirtBlock, AirBlock, Block
from module.block import StoneBlock, GrassBlock, DirtBlock, AirBlock, Block, BedrockBlock
# 生成地形
@@ -9,17 +9,29 @@ def generate_terrain() -> list[list[Block]]:
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 + 2:
column.append(StoneBlock(x, y))
if y < height:
block = AirBlock(x, y)
elif y == height:
column.append(GrassBlock(x, y))
elif y > height - 3:
column.append(DirtBlock(x, y))
block = GrassBlock(x, y)
elif height < y < height + 5:
block = DirtBlock(x, y)
elif y == HEIGHT // BLOCK_SIZE - 1:
block = BedrockBlock(x, y)
else:
column.append(AirBlock(x, y))
block = StoneBlock(x, y)
column.append(block)
world.append(column)
return world