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/wall_r.png"),
		green = love.graphics.newImage("art/game/wall_g.png"),
		blue = love.graphics.newImage("art/game/wall_b.png")
	},
	door = {
		white = love.graphics.newImage("art/game/door_locked_w.png"),
		red = love.graphics.newImage("art/game/door_locked_r.png"),
		green = love.graphics.newImage("art/game/door_locked_g.png"),
		blue = love.graphics.newImage("art/game/door_locked_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
