12. 继续,游戏,LevelMaker
周日,继续摆烂,游戏。
LevelMaker
随机一个关卡。
lua
LevelMaker = Class {}
function LevelMaker:createMap(level)
local bricks = {}
local numRows = math.random(1, 5)
local numCols = math.random(7, 13)
for y = 1, numRows do
for x = 1, numCols do
b = Brick(
(x - 1) -- 从 1 开始的索引
* 32 -- 砖块宽度
+ 8 -- 左边距
+ (13 - numCols) * 16, -- 当列数小于 13 时,增加左边距
-- 上边距
y * 16
)
table.insert(bricks, b)
end
end
return bricks
end