when i move to the left or up it doesnt fallow the player until the player is on the coordinate
Spoiler
os.loadAPI('grid')
local drawoffx = 0
local drawoffy = 0
local x, y = 10, 10
local w,h = term.getSize()
local mw, mh = math.floor(w/2), math.floor(h/2)
local setcolors = {['bg']=colors.black,['tc']=colors.white}
local biggrid = grid.create(100,100)
local pmap = grid.create(100,100)
local grass = {char="*",tc=colors.brown,bc=colors.green,solid=false}
local sand = {char='.',tc=colors.white,bc=colors.yellow,solid=false}
local wall = {char="L",tc=colors.gray,bc=colors.lightGray,solid=true}
local player = {char='@',tc=colors.blue}
local function bcolor©
setcolors['bg'] = c
term.setBackgroundColor©
end
local function tcolor©
setcolors['tc'] = c
term.setTextColor©
end
biggrid:fill(grass)
biggrid:set(10,22,sand)
pmap:set(x,y,player)
function cdraw(x,y)
bcolor(biggrid:get(x,y)['bc'])
tcolor(biggrid:get(x,y)['tc'])
term.setCursorPos(x-drawoffx,y-drawoffy)
write(biggrid:get(x,y)['char'])
end
function drawpmap(x,y)
local drx = drawoffx
local dry = drawoffy
term.setCursorPos(x-drx,y-dry)
term.setTextColor(pmap:get(x,y)['tc'])
term.setBackgroundColor(biggrid:get(x,y)['bc'])
write(pmap:get(x,y)['char'])
end
function updateView()
term.current().setVisible(false)
biggrid:loop(cdraw,drawoffx,drawoffy,w+drawoffx,h+drawoffy)
pmap:loop(drawpmap,x,y)
term.current().setVisible(true)
end
biggrid:loop(cdraw,0,0,w,h)
pmap:loop(drawpmap,x,y)
while true do
e = {os.pullEvent()}
if(x > mw+drawoffx)then
drawoffx = x-mw
updateView()
end
if(y > mh+drawoffy)then
drawoffy = y-mh
updateView()
end
if(drawoffx-mw >= 1)then
if(x < mw-drawoffx)then
drawoffx = x+mw
updateView()
end
else
if(x < drawoffy)then
drawoffy = x
updateView()
end
end
if(drawoffy-mh >= 1)then
if(y < mh-drawoffy)then
drawoffy = y+mh
updateView()
end
else
if(y < drawoffy)then
drawoffy = y
updateView()
end
end
if(e[1] == 'key')then
biggrid:loop(cdraw,x,y)
if(e[2] == keys.w and not biggrid:get(x,y-1).solid and y > 1)then
pmap:swap(x,y,x,y-1)
y=y-1
elseif(e[2] == keys.s and not biggrid:get(x,y+1).solid and y < biggrid:getHeight())then
pmap:swap(x,y,x,y+1)
y=y+1
elseif(e[2] == keys.a and not biggrid:get(x-1,y).solid and x > 1)then
pmap:swap(x,y,x-1,y)
x=x-1
elseif(e[2] == keys.d and not biggrid:get(x+1,y).solid and x < biggrid:getWidth())then
pmap:swap(x,y,x+1,y)
x=x+1
end
pmap:loop(drawpmap,x,y)
end
end
API: http://pastebin.com/QEXpahe1