paulofmandown / rotLove

Roguelike Toolkit in Love. A Love2D/lua port of rot.js
http://paulofmandown.github.io/rotLove/
Other
258 stars 25 forks source link

ROT.Display:clear() not clearing last row #23

Closed Rakaneth closed 7 years ago

Rakaneth commented 7 years ago

It appears that the Display:clear() method is omitting the last row when a height is specified. I think I fixed this in the code - I will be submitting a pull request for this since the fix appears simple.

Rakaneth commented 7 years ago

Since I'm silly and don't know how to submit a pull request, I'll just state the issue here:

on line 687, for i=0,h-1 do omits the last line since h is already required to accommodate Lua's 1-based indexing. I changed this line to for i=0,h do in my copy.

paulofmandown commented 7 years ago

This changes the behavior of Display:clear and TextDisplay:clear. If, previously, you were using the width and height arguments to clear a designated area of the display, you'll have to start adding one to the height (or stop subtracting one) The height argument now designates the number of rows to be cleared (which is how width worked for columns) instead of the dumb 'clear one and then proceed clearing for h rows'.

paulofmandown commented 7 years ago

ugh, this still isn't working the way I want it to

paulofmandown commented 7 years ago

This should finally be good

paulofmandown commented 7 years ago

Here's the main.lua I finally wound up with after testing:

ROT = require 'rotLove/rotLove'
function love.load()
    -- text display requires love.graphics to be loaded
    love.window.setMode(800, 600)
    frame=ROT.Display()
    rand = math.random(1,3)
    rng = rand == 1 and ROT.RNG.Twister:new() or
          rand == 2 and ROT.RNG.LCG:new() or
          ROT.RNG.MWC:new()
    rng:randomseed()
end
function love.draw()
    frame:draw()
end

x,y,i=1,1,64

update=false
function love.update()
    for x=1,80 do for y=1,24 do
        frame:write(string.char(i), x, y, getRandomColor(), getRandomColor())
        i=i==120 and 1 or i+1
    end end
    if update then
        frame:clear(' ', 2, 2, 78, 22)
        --frame:clear()
    end
end
function love.keypressed() update=not update end
function getRandomColor()
    return { r=math.floor(rng:random(0,255)),
             g=math.floor(rng:random(0,255)),
             b=math.floor(rng:random(0,255)),
             a=255}
end