kill dead code
This commit is contained in:
parent
a8b469876d
commit
7fa9171ba1
9 changed files with 72 additions and 187 deletions
64
_helpers.lua
64
_helpers.lua
|
|
@ -45,3 +45,67 @@ function readFromSource(relPath)
|
|||
end
|
||||
return love.filesystem.read(relPath)
|
||||
end
|
||||
|
||||
-- Cached image loader. The filesystem is the source of truth for art, so every
|
||||
-- sprite is loaded on demand by path (deduped here) rather than from a
|
||||
-- hand-maintained central table.
|
||||
local spriteCache = {}
|
||||
function loadSprite(path)
|
||||
if not spriteCache[path] then
|
||||
spriteCache[path] = love.graphics.newImage(path)
|
||||
end
|
||||
return spriteCache[path]
|
||||
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
|
||||
|
||||
-- Which 16x16 cells of a sprite are non-empty, for multi-cell collision shapes.
|
||||
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 = {}
|
||||
|
||||
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
|
||||
empty = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if empty then
|
||||
cellsToRemove[cell] = cell
|
||||
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
|
||||
|
||||
return boxCells
|
||||
end
|
||||
|
|
|
|||
21
box.lua
21
box.lua
|
|
@ -1,21 +0,0 @@
|
|||
require "entity"
|
||||
|
||||
Box = class("Box", Entity)
|
||||
|
||||
function Box:initialize(x, y, color)
|
||||
Entity.initialize(self, {
|
||||
x = x,
|
||||
y = y,
|
||||
color = color,
|
||||
collision = "moveable",
|
||||
sprite = sprites.box[color]
|
||||
})
|
||||
end
|
||||
|
||||
function Box:update()
|
||||
|
||||
end
|
||||
|
||||
function Box:tick()
|
||||
|
||||
end
|
||||
10
door.lua
10
door.lua
|
|
@ -9,9 +9,9 @@ function Door:initialize(x, y)
|
|||
color = "white",
|
||||
collision = "unmoveable",
|
||||
sprites = {
|
||||
red = sprites.door.red,
|
||||
green = sprites.door.green,
|
||||
blue = sprites.door.blue,
|
||||
red = loadSprite("art/game/door_r.png"),
|
||||
green = loadSprite("art/game/door_g.png"),
|
||||
blue = loadSprite("art/game/door_b.png"),
|
||||
},
|
||||
})
|
||||
self.locked = true
|
||||
|
|
@ -29,9 +29,9 @@ function Door:refreshSprites()
|
|||
self.sprites = {}
|
||||
for _, c in ipairs({"red", "green", "blue"}) do
|
||||
if self.locked then
|
||||
if self.colors[c] then self.sprites[c] = sprites.door[c] end
|
||||
if self.colors[c] then self.sprites[c] = loadSprite("art/game/door_" .. c:sub(1, 1) .. ".png") end
|
||||
else
|
||||
self.sprites[c] = sprites.door.unlocked
|
||||
self.sprites[c] = loadSprite("art/game/door_unlocked.png")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
4
main.lua
4
main.lua
|
|
@ -11,7 +11,6 @@ require "input"
|
|||
require "color"
|
||||
require "room"
|
||||
require "shaders"
|
||||
require "sprite_manager"
|
||||
require "level_editor/editor"
|
||||
|
||||
function love.load()
|
||||
|
|
@ -23,9 +22,6 @@ function love.load()
|
|||
_initGlobalColors()
|
||||
_initLevelEditor()
|
||||
|
||||
|
||||
processSprites()
|
||||
|
||||
gameCanvas = love.graphics.newCanvas()
|
||||
sideBarCanvas = love.graphics.newCanvas(sideBarBox.w, sideBarBox.h)
|
||||
finalCanvas = love.graphics.newCanvas()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function Player:initialize(x, y, color)
|
|||
y = y,
|
||||
color = color,
|
||||
collision = "none", --player can't push other player
|
||||
sprite = sprites.player
|
||||
sprite = loadSprite("art/game/player.png")
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
13
room.lua
13
room.lua
|
|
@ -2,8 +2,6 @@ Room = class("Room")
|
|||
|
||||
require "libs/TSerial"
|
||||
require "player"
|
||||
require "box"
|
||||
require "wall"
|
||||
require "artifact"
|
||||
require "npc"
|
||||
require "art"
|
||||
|
|
@ -14,15 +12,6 @@ require "dialogue_manager"
|
|||
require "generic_moveable"
|
||||
require "generic_unmoveable"
|
||||
|
||||
-- cache loaded images so repeated placing/loading doesn't re-decode PNGs
|
||||
local placeImageCache = {}
|
||||
local function loadPlaceImage(path)
|
||||
if not placeImageCache[path] then
|
||||
placeImageCache[path] = love.graphics.newImage(path)
|
||||
end
|
||||
return placeImageCache[path]
|
||||
end
|
||||
|
||||
function Room:initialize(t)
|
||||
self.player = {}
|
||||
self.switches = { red = {}, green = {}, blue = {} }
|
||||
|
|
@ -558,7 +547,7 @@ function Room:createEntity(class, color, x, y)
|
|||
self:registerPlayer(entity, color)
|
||||
self:setActiveColor(color, true)
|
||||
elseif props and props.sprites and props.sprites[color] then
|
||||
local sprite = loadPlaceImage(props.sprites[color])
|
||||
local sprite = loadSprite(props.sprites[color])
|
||||
if behavior == "moveable" then
|
||||
entity = GenericMoveable:new(x, y, color, sprite, class)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
sprites = {
|
||||
player = love.graphics.newImage("art/game/player.png"),
|
||||
wall = love.graphics.newImage("art/game/static_wall.png"),
|
||||
box = {
|
||||
red = love.graphics.newImage("art/game/box_r.png"),
|
||||
green = love.graphics.newImage("art/game/box_g.png"),
|
||||
blue = love.graphics.newImage("art/game/box_b.png")
|
||||
},
|
||||
door = {
|
||||
white = love.graphics.newImage("art/game/door_locked_w.png"),
|
||||
red = love.graphics.newImage("art/game/door_r.png"),
|
||||
green = love.graphics.newImage("art/game/door_g.png"),
|
||||
blue = love.graphics.newImage("art/game/door_b.png"),
|
||||
unlocked = love.graphics.newImage("art/game/door_unlocked.png")
|
||||
},
|
||||
switch = {
|
||||
red = love.graphics.newImage("art/game/switch_r.png"),
|
||||
green = love.graphics.newImage("art/game/switch_g.png"),
|
||||
blue = love.graphics.newImage("art/game/switch_b.png")
|
||||
},
|
||||
water = {
|
||||
red = love.graphics.newImage("art/nature/water_r.png"),
|
||||
green = love.graphics.newImage("art/nature/water_g.png"),
|
||||
blue = love.graphics.newImage("art/nature/water_b.png")
|
||||
},
|
||||
mac_smaller = love.graphics.newImage("art/tech/mac_smaller_r.png"),
|
||||
tree = {
|
||||
red = love.graphics.newImage("art/nature/palm_scaled_r.png"),
|
||||
green = love.graphics.newImage("art/nature/palm_scaled_g.png"),
|
||||
blue = love.graphics.newImage("art/nature/palm_scaled_b.png")
|
||||
},
|
||||
npcs = {
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
spriteCells = {}
|
||||
|
||||
function processSprites()
|
||||
getCellsFromSprite(sprites.player)
|
||||
|
||||
for name, spriteObj in pairs(sprites) do
|
||||
if type(spriteObj) == "table" then
|
||||
spriteCells[name] = {}
|
||||
--this is multicolored so...
|
||||
for color, sprite in pairs(spriteObj) do
|
||||
spriteCells[name][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
|
||||
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
|
||||
|
|
@ -2,13 +2,6 @@ require "entity"
|
|||
|
||||
Switch = class("Switch", Entity)
|
||||
|
||||
Switch.static.sprites = {
|
||||
red = love.graphics.newImage("art/game/switch_r.png"),
|
||||
green = love.graphics.newImage("art/game/switch_g.png"),
|
||||
blue = love.graphics.newImage("art/game/switch_b.png"),
|
||||
pressed = love.graphics.newImage("art/game/switch_pressed.png")
|
||||
}
|
||||
|
||||
function Switch:initialize(x, y, color)
|
||||
Entity.initialize(self, {
|
||||
x = x,
|
||||
|
|
@ -16,7 +9,7 @@ function Switch:initialize(x, y, color)
|
|||
color = color,
|
||||
collision = "none", --switches are floor elements that can't be pushed or bloc movement!!
|
||||
cellShape = {{x = 1, y = 1}},
|
||||
sprite = sprites.switch[color]
|
||||
sprite = loadSprite("art/game/switch_" .. color:sub(1, 1) .. ".png")
|
||||
})
|
||||
|
||||
self.activated = false
|
||||
|
|
|
|||
24
wall.lua
24
wall.lua
|
|
@ -1,24 +0,0 @@
|
|||
require "entity"
|
||||
|
||||
Wall = class("Wall", Entity)
|
||||
|
||||
function Wall:initialize(x, y, color)
|
||||
Entity.initialize(self, {
|
||||
x = x,
|
||||
y = y,
|
||||
sizeX = 1,
|
||||
sizeY = 1,
|
||||
color = color,
|
||||
cellShape = spriteCells.wall,
|
||||
collision = "unmoveable",
|
||||
sprite = sprites.wall
|
||||
})
|
||||
end
|
||||
|
||||
function Wall:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function Wall:tick()
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue