consolidate single color sprites into one master file

This commit is contained in:
Your Name 2026-08-22 11:44:51 -04:00
parent 7d84f595e4
commit fe5a11112f
16 changed files with 90 additions and 53 deletions

View file

@ -160,11 +160,12 @@ function cellShapeFromBox(box)
return cells
end
-- Which 16x16 cells of an image are non-empty, for multi-cell collision
-- shapes. LÖVE 11 no longer exposes Image:getData(), so inspect ImageData
-- directly instead of creating a GPU Image first.
function getCellsFromSprite(spritePath)
local img = love.image.newImageData(spritePath)
-- Which 16x16 cells of an ImageData are non-empty, for multi-cell collision
-- shapes. `channel` ("red"/"green"/"blue") restricts the test to one colour
-- gun: a single full-colour master now feeds all three copies, so each copy's
-- collision shape comes from its own channel of the master (a cell with only
-- red pixels blocks the red copy but not blue). nil = "any channel lit".
local function cellsFromImageData(img, channel)
local w, h = img:getWidth(), img:getHeight()
local box = {w = w / 16, h = h / 16}
local boxCells = cellShapeFromBox(box)
@ -182,7 +183,12 @@ function getCellsFromSprite(spritePath)
for i = startPixel.x, endPixel.x do
for j = startPixel.y, endPixel.y do
local r, g, b, a = img:getPixel(i, j)
if a > 0 and (r > 0 or g > 0 or b > 0) then
local lit
if channel == "red" then lit = r > 0
elseif channel == "green" then lit = g > 0
elseif channel == "blue" then lit = b > 0
else lit = r > 0 or g > 0 or b > 0 end
if a > 0 and lit then
empty = false
end
end
@ -204,3 +210,20 @@ function getCellsFromSprite(spritePath)
return boxCells
end
-- LÖVE 11 no longer exposes Image:getData(), so inspect ImageData directly
-- instead of creating a GPU Image first.
function getCellsFromSprite(spritePath, channel)
return cellsFromImageData(love.image.newImageData(spritePath), channel)
end
-- Per-channel collision cell shapes for one full-colour master, loaded once.
-- Returns { red = cells, green = cells, blue = cells }.
function getChannelCells(spritePath)
local img = love.image.newImageData(spritePath)
return {
red = cellsFromImageData(img, "red"),
green = cellsFromImageData(img, "green"),
blue = cellsFromImageData(img, "blue"),
}
end