This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lewisk3's profile picture

Game camera help!

Started by Lewisk3, 20 February 2016 - 05:28 AM
Lewisk3 #1
Posted 20 February 2016 - 06:28 AM
Im working on a game, and i cant get the camera to fallow the player correctly on the way back
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
Edited on 20 February 2016 - 09:14 PM
Creator #2
Posted 20 February 2016 - 10:14 AM
What exactly is it doing wrong?

Also, I uploaded it to pastebin for anyone who wants to look at the code.
Lupus590 #3
Posted 20 February 2016 - 11:37 AM
indent your code so that it's easier to read
Lewisk3 #4
Posted 20 February 2016 - 12:38 PM
indent your code so that it's easier to read
thats the computer-craft forums fault, my code is usually extremely neat and organized.
Edited on 28 September 2016 - 02:42 AM
Creator #5
Posted 20 February 2016 - 12:49 PM
Then pastebin it, please.
Luca_S #6
Posted 20 February 2016 - 03:09 PM
Could you post the used APIs so we can try out what's wrong?
Lewisk3 #7
Posted 20 February 2016 - 10:14 PM
Could you post the used APIs so we can try out what's wrong?

posted.
Luca_S #8
Posted 20 February 2016 - 11:23 PM
Ok what exactly do you want to do if you wait until a certain x/y and then start scrolling the camera the player will think he isn't moving anymore.
Lewisk3 #9
Posted 21 February 2016 - 12:11 AM
Ok what exactly do you want to do if you wait until a certain x/y and then start scrolling the camera the player will think he isn't moving anymore.
i am just looking to get this same camera effect that minicraft has.

What exactly is it doing wrong?

Also, I uploaded it to pastebin for anyone who wants to look at the code.
just for the clarity, MultMine and i fixed the game of life i was making and also i made it so you can pan the screen arround xD
prob will be posting it later today.
Edited on 20 February 2016 - 11:13 PM