battlesystem: add mask system

This commit is contained in:
Kazhnuz 2019-03-31 11:52:04 +02:00
parent e2d206ff44
commit 8a09110ac8
2 changed files with 45 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

View file

@ -50,6 +50,8 @@ function BattleArena:loadRessources()
self.textures.borders = love.graphics.newImage("assets/backgrounds/borders.png") self.textures.borders = love.graphics.newImage("assets/backgrounds/borders.png")
self.textures.shadow = love.graphics.newImage("assets/sprites/shadow.png") self.textures.shadow = love.graphics.newImage("assets/sprites/shadow.png")
self.emptytile = love.graphics.newImage("assets/gui/tilemask.png")
self.quads = {} self.quads = {}
self.quads.tiles = {} self.quads.tiles = {}
self.quads.sptiles = {} self.quads.sptiles = {}
@ -207,4 +209,47 @@ function BattleArena:drawTile(x, y, type, variant)
end end
end end
function BattleArena:showMask(ox, oy, shape, size, direction)
for i=1,12 do
for j=1,7 do
if self:isInMask(i, j, ox, oy, shape, size, direction) then
local x, y = self:gridToPixel(i, j)
love.graphics.draw(self.emptytile, x, y)
end
end
end
end
function BattleArena: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
end
end
return BattleArena return BattleArena