-
-
Save MSylvia/bdcd71127289b2fdd7c7129ee7e27718 to your computer and use it in GitHub Desktop.
roguelike ascii tile display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local data = love.image.newImageData("Alloy_curses_12x12.png") | |
| data:mapPixel(function(x,y,r,g,b,a) | |
| if r == 255 and b == 255 and g ~= 255 then | |
| r,g,b,a = 0,0,0,0 | |
| end | |
| return r,g,b,a | |
| end) | |
| local img = love.graphics.newImage(data) | |
| local spritebatch = love.graphics.newSpriteBatch(img, 87*25, "stream") | |
| local quads = {} | |
| for x = 0, 255 do | |
| local i,j = 1+(x%16), math.floor(x/16) | |
| quads[x] = love.graphics.newQuad(i*12, j*12, 12, 12, img:getWidth(), img:getHeight()) | |
| end | |
| local random = math.random | |
| local map = {} | |
| local smap = {} | |
| local old = {} | |
| spritebatch:bind() | |
| for i=0,86 do | |
| map[i] = {} | |
| smap[i] = {} | |
| old[i] = {} | |
| for j=0,24 do | |
| map[i][j] = random(255) | |
| old[i][j] = random(255) | |
| spritebatch:setColor(255,255,255) | |
| smap[i][j] = spritebatch:add(quads[map[i][j]], i*12, j*12) | |
| end | |
| end | |
| spritebatch:unbind() | |
| love.draw = function() | |
| spritebatch:bind() | |
| for i=0,86 do | |
| for j=0,24 do | |
| if map[i][j] ~= old[i][j] then | |
| old[i][j] = map[i][j] | |
| spritebatch:setColor(255,255,255) | |
| spritebatch:set(smap[i][j], quads[map[i][j]], i*12, j*12) | |
| end | |
| end | |
| end | |
| spritebatch:unbind() | |
| love.graphics.setColor(255,255,255,255) | |
| love.graphics.draw(spritebatch) | |
| love.graphics.print("FPS:"..love.timer.getFPS(),0,love.graphics.getHeight()-16) | |
| end | |
| love.update = function() | |
| if love.keyboard.isDown(" ") then | |
| for i=0,86 do | |
| for j=0,24 do | |
| map[i][j] = math.random(255) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment