Question

I'm drawing a grid with Ruby Shoes for a gridlocked square player. It... kinda works. See it only draws about 3/4 ways for the grid, I suspect this is because I didn't make my map array well. But that's not the major problem. The main problem is the lag that drawing a grid is causing. Why does it make me drop to like 4 FPS? Having only one set of line was no problem.

Here's the code

Shoes.app(title:"Some Ruby [shoes] Game", width:(811), height:(601), resizable: false) {
@x = 0
@y = 0
@map = Array.new(600/30) { Array.new(800/30) } 
#using 600/30 and 800/30 because gridlock... (player is 30x30pix)
@rect = rect(left:@x, top:@y, width:30)
num = 0
@map.each { |el|
    if(num!=0)
        line(top:0,left:(num*30),width:0,height:600)
    end
    el.each { |el2|
        if(num!=0)
            line(top:(num*30),left:0,width:800,height:0)
        end
    }
    num = num + 1
}
keypress { |k|
    if(k=="w")
        @y = @y - 30
    end

    if(k=="s")
        @y = @y + 30
    end

    if(k=="a")
        @x = @x - 30
    end

    if(k=="d")
        @x = @x + 30
    end
    @rect.remove
    @rect = rect(left:@x, top:@y, width:30)
}
}

I'm not sure what's wrong. Please help?

Was it helpful?

Solution

I changed the numbers in the @map line and the program stopped lagging for me.

@map = Array.new(60) { Array.new(80) } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top