92 lines
1.9 KiB
Lua
92 lines
1.9 KiB
Lua
local board = {
|
|
route_length = 40,
|
|
finish_progress = 40,
|
|
start = {
|
|
red = 1,
|
|
yellow = 11,
|
|
blue = 21,
|
|
green = 31
|
|
},
|
|
homes = {
|
|
red = {
|
|
{ x = 92, y = 132 },
|
|
{ x = 142, y = 132 }
|
|
},
|
|
yellow = {
|
|
{ x = 518, y = 132 },
|
|
{ x = 568, y = 132 }
|
|
},
|
|
blue = {
|
|
{ x = 518, y = 548 },
|
|
{ x = 568, y = 548 }
|
|
},
|
|
green = {
|
|
{ x = 92, y = 548 },
|
|
{ x = 142, y = 548 }
|
|
}
|
|
},
|
|
finish = {
|
|
red = {
|
|
{ x = 290, y = 330 },
|
|
{ x = 250, y = 330 }
|
|
},
|
|
yellow = {
|
|
{ x = 350, y = 330 },
|
|
{ x = 390, y = 330 }
|
|
},
|
|
blue = {
|
|
{ x = 350, y = 390 },
|
|
{ x = 390, y = 390 }
|
|
},
|
|
green = {
|
|
{ x = 290, y = 390 },
|
|
{ x = 250, y = 390 }
|
|
}
|
|
},
|
|
route = {}
|
|
}
|
|
|
|
local function add(x, y)
|
|
table.insert(board.route, { x = x, y = y })
|
|
end
|
|
|
|
for i = 0, 9 do add(200 + i * 32, 104) end
|
|
for i = 0, 9 do add(520, 136 + i * 32) end
|
|
for i = 0, 9 do add(488 - i * 32, 456) end
|
|
for i = 0, 9 do add(168, 424 - i * 32) end
|
|
|
|
function board.home_position(piece)
|
|
local index = piece.id:sub(-1) == "2" and 2 or 1
|
|
return board.homes[piece.owner][index]
|
|
end
|
|
|
|
function board.finish_position(piece)
|
|
local index = piece.id:sub(-1) == "2" and 2 or 1
|
|
return board.finish[piece.owner][index]
|
|
end
|
|
|
|
function board.route_index(owner, progress)
|
|
local start = board.start[owner]
|
|
local index = start + progress - 1
|
|
while index > board.route_length do
|
|
index = index - board.route_length
|
|
end
|
|
return index
|
|
end
|
|
|
|
function board.route_position(owner, progress)
|
|
return board.route[board.route_index(owner, progress)]
|
|
end
|
|
|
|
function board.position(piece)
|
|
if piece.status == "home" then
|
|
return board.home_position(piece)
|
|
end
|
|
if piece.status == "finished" then
|
|
return board.finish_position(piece)
|
|
end
|
|
return board.route_position(piece.owner, piece.progress)
|
|
end
|
|
|
|
return board
|