refactor code structure

This commit is contained in:
2025-01-31 19:35:09 +08:00
parent d74c866caf
commit 823158a8eb
4 changed files with 69 additions and 66 deletions

24
module/utils.py Normal file
View File

@@ -0,0 +1,24 @@
import random
from module import WIDTH, BLOCK_SIZE, HEIGHT
# 生成地形
def generate_terrain():
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("stone")
elif y == height:
column.append("grass")
elif y > height - 3:
column.append("dirt")
else:
column.append("air")
world.append(column)
return world