sonic-radiance/sonic-radiance.love/scenes/battlesystem/utils.lua

105 lines
2.8 KiB
Lua

local maputils = {}
maputils.CONST = {}
maputils.CONST.STARTX = -8
maputils.CONST.STARTY = 90
function maputils.newEmptyMap()
return {
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
}
end
function maputils.newFullMap()
return {
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
}
end
function maputils.isInMask(x, y, ox, oy, shape, size, direction)
local direction = direction or 1
local shape = shape or "point"
if shape == "point" then
return ((x == ox) and (y == oy))
elseif shape == "square" then
local x1 = ox - math.floor(size/2)
local x2 = ox + math.ceil(size/2)
local y1 = oy - math.floor(size/2)
local y2 = oy + math.ceil(size/2)
return ((x >= x1) and (x <= x2) and (y >= y1) and (y <= y2))
elseif shape == "circle" then
local lenght = utils.math.pointDistance(x, y, ox, oy)
return (lenght <= size)
elseif shape == "fullheight" then
local x2 = ox + (size*direction)
return ((x >= ox) and (x <= x2))
elseif shape == "fullwidth" then
local y2 = oy + (size*direction)
return ((y >= oy) and (y <= y2))
elseif shape == "line" then
local x2 = ox + (size*direction)
return ((y == oy) and (x >= ox) and (x <= x2))
elseif shape == "column" then
local y2 = oy + (size*direction)
return ((x == ox) and (y >= oy) and (y <= y2))
elseif shape == "everything" then
return true
else
if shape == nil then
shape = "nil"
end
core.debug:warning("maputils", "shape " .. shape .. " doesn't exist")
end
end
function maputils.maskToMap(ox, oy, shape, size, direction)
local map = maputils.newEmptyMap()
for i, line in ipairs(map) do
for j, case in ipairs(line) do
local isInMask = maputils.isInMask(j, i, ox, oy, shape, size, direction)
if (isInMask) then
map[i][j] = 1
else
map[i][j] = 0
end
end
end
return map
end
function maputils.sortBattlers(a, b)
local astats = a.fighter:getStats()
local bstats = b.fighter:getStats()
local aspeed = astats.speed / 1.5 * a.number
local bspeed = bstats.speed / 1.5 * b.number
if (aspeed == bspeed) then
if (a.fighter.isHero == b.fighter.isHero) then
return (a.fighter.id > b.fighter.id)
else
return a.fighter.isHero
end
else
return (aspeed > bspeed)
end
end
return maputils