refactor code structure
This commit is contained in:
24
module/utils.py
Normal file
24
module/utils.py
Normal 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
|
||||
Reference in New Issue
Block a user