It is by no means perfect, and not at all documented, but I want feedback from more than just one person. It is also not distributable via a .love file because of the way love.filesystem works, which means you have to download the file's with "good ol' copy 'n paste", running the game using a folder.
Ask questions, give corrections/optimisations and everything else you guys generally do.
Here is main.lua:
Code: Select all
local coloursTable, tileTable = {}
function love.load()
pixelLoad()
end
function love.draw()
drawPixels()
end
function love.keyreleased(k)
if k == "r" then pixelLoad()
elseif k == "s" then saveImage()
elseif k == "escape" then love.event.push("q") end
end
function saveImage()
love.filesystem.write("image.bmp", love.graphics.newScreenshot():encode("bmp"))
end
function pixelLoad()
pixelSize = 25
love.filesystem.load("pixels.txt")()
generatePixels(pixels)
local width = #tileTable
local height = #tileTable[1]
love.graphics.setMode(width*pixelSize, height*pixelSize)
love.graphics.setCaption(title or "Pixel Art")
end
function generatePixels(tileString)
tileTable = {}
local rowIndex = 0
for row in tileString:gmatch("[^\n]+") do
rowIndex=rowIndex+1
local columnIndex = 1
for character in row:gmatch(".") do
if not tileTable[columnIndex] then
tileTable[columnIndex] = {}
end
tileTable[columnIndex][rowIndex] = character
columnIndex = columnIndex + 1
end
end
for _,info in ipairs(colours) do
coloursTable[info[1]] = {info[2], info[3], info[4], info[5] or 255}
end
end
function drawPixels()
for columnIndex,column in ipairs(tileTable) do
for rowIndex,char in ipairs(column) do
local x,y = (columnIndex-1)*pixelSize, (rowIndex-1)*pixelSize
local col = coloursTable[char]
love.graphics.setColor(col[1], col[2], col[3], col[4])
love.graphics.rectangle("fill", x, y, pixelSize, pixelSize)
end
end
end
Code: Select all
pixels = [[
wwwwwwwww
wbbbbbbbw
wwwwbwwww
wwbbbbbww
wbwwwwwbw
wbwrwrwbw
wbwwwwwbw
wbwrrrwbw
wbwwwwwbw
wwbbbbbww
wbbwwwbbw
bwbwrwbwb
bwbwwwbwb
bwbbbbbwb
wwwbwbwww
wwwbwbwww
wwwbwbwww
wwbbwbbww
]]
colours = {
{"y", 0, 255, 255},
{"r", 255, 0, 0},
{"b", 0, 0, 255},
{"w", 255, 255, 255}
}
pixelSize = 40
title = "Pixel Art!!!"