automatically gets bouif pull = true then
This commit is contained in:
parent
747a7b7b58
commit
214758388e
14 changed files with 143 additions and 81 deletions
112
sprite_manager.lua
Normal file
112
sprite_manager.lua
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
sprites = {
|
||||
player = love.graphics.newImage("art/player.png"),
|
||||
wall = love.graphics.newImage("art/static_wall.png"),
|
||||
box = {
|
||||
red = love.graphics.newImage("art/wall_r.png"),
|
||||
green = love.graphics.newImage("art/wall_g.png"),
|
||||
blue = love.graphics.newImage("art/wall_b.png")
|
||||
},
|
||||
door = {
|
||||
white = love.graphics.newImage("art/door_locked_w.png"),
|
||||
red = love.graphics.newImage("art/door_locked_r.png"),
|
||||
green = love.graphics.newImage("art/door_locked_g.png"),
|
||||
blue = love.graphics.newImage("art/door_locked_b.png"),
|
||||
unlocked = love.graphics.newImage("art/door_unlocked.png")
|
||||
},
|
||||
switch = {
|
||||
red = love.graphics.newImage("art/switch_r.png"),
|
||||
green = love.graphics.newImage("art/switch_g.png"),
|
||||
blue = love.graphics.newImage("art/switch_b.png")
|
||||
},
|
||||
water = {
|
||||
red = love.graphics.newImage("art/nature/processed/water_r.png"),
|
||||
green = love.graphics.newImage("art/nature/processed/water_g.png"),
|
||||
blue = love.graphics.newImage("art/nature/processed/water_b.png")
|
||||
},
|
||||
mac_smaller = love.graphics.newImage("art/tech/processed/mac_smaller_r.png"),
|
||||
test_object = love.graphics.newImage("art/test_object.png"),
|
||||
npcs = {
|
||||
|
||||
},
|
||||
artifact = love.graphics.newImage("art/process/cone.png"),
|
||||
}
|
||||
|
||||
spriteCells = {}
|
||||
|
||||
|
||||
function processSprites()
|
||||
getCellsFromSprite(sprites.player)
|
||||
|
||||
for name, spriteObj in pairs(sprites) do
|
||||
print(name)
|
||||
if type(spriteObj) == "table" then
|
||||
spriteCells[name] = {}
|
||||
--this is multicolored so...
|
||||
for color, sprite in pairs(spriteObj) do
|
||||
spriteCells[color] = getCellsFromSprite(sprite)
|
||||
end
|
||||
else
|
||||
--assume it's an image obj
|
||||
spriteCells[name] = getCellsFromSprite(spriteObj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function getCellsFromSprite(sprite)
|
||||
local w, h = sprite:getWidth(), sprite:getHeight()
|
||||
local box = {w = w / 16, h = h / 16}
|
||||
local boxCells = cellShapeFromBox(box)
|
||||
if box.w < 1 or box.h < 1 then
|
||||
return boxCells
|
||||
end
|
||||
|
||||
local img = sprite:getData()
|
||||
|
||||
local cellsToRemove = {}
|
||||
local stop
|
||||
|
||||
for _, cell in pairs(boxCells) do
|
||||
|
||||
local startPixel = {x = (cell.x - 1) * 16, y = (cell.y - 1) * 16}
|
||||
local endPixel = {x = (cell.x * 16) - 1, y = (cell.y * 16) - 1}
|
||||
|
||||
local empty = true
|
||||
|
||||
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
|
||||
--this cell has color so
|
||||
empty = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if empty then
|
||||
print("empty @ ", cell.x, cell.y)
|
||||
cellsToRemove[cell] = cell --references boxCells cell so comparison should wor_
|
||||
end
|
||||
end
|
||||
|
||||
local i = 1
|
||||
while i <= #boxCells do
|
||||
if boxCells[i] == cellsToRemove[boxCells[i]] then
|
||||
table.remove(boxCells, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
shallowTablePrint(boxCells)
|
||||
return boxCells
|
||||
end
|
||||
|
||||
function cellShapeFromBox(box)
|
||||
local cells = {}
|
||||
for i = 1, box.w do
|
||||
for j = 1, box.h do
|
||||
table.insert(cells, {x = i, y = j})
|
||||
end
|
||||
end
|
||||
return cells
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue