Log In  


function _init()
p={n=16,x=64,y=64,hb={x1=1,y1=1,x2=7,y2=7}}
tree = flr(rnd(9)+1)
treepos = {}
for i=1,tree do
add(treepos,flr(rnd(220)))
end
end

function _update()
if btn(0,0) then
p.x-=1
p.n=17
end
if btn(1,0) then
p.x+=1
p.n=16
end
if btn(2,0) then
p.y-=1
end
if btn(3,0) then
p.y+=1
end
end

function _draw()
cls()
for i=1,16 do
for j=1,16 do
local x,y = 8i,8j
spr(1,x-8,y-8)
end
end
rndtree()
spr(p.n,p.x,p.y)
camera=p.x,p.y
//error-----------------
//for i=1,tree do
//if treepos[i]!=0 then
//rect(treepos[i]-2,treepos[i+1]-2,treepos[i]+10,treepos[i+1]+10,8)
//end
//if p.x==treepos[i] and p.y==treepos[i+1] then
//print(i,treepos[i],treepos[i+1],8)
//end
//end
//error-----------------
print(treepos,0,y)
end

function rndtree()
for i=1,tree do
spr(2,treepos[i],treepos[i+1])
end
end

nill error

1


Hopefully this helps:

Cart #42663 | 2017-07-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Basically your draw code expected the tree position table to be structured differently than it was.

Let me know if you have questions!


Ty very much.


How it is possible to carry out cutting of a tree? Or they preliminary it is necessary to write down in an array?


I had the idea to draw a rectangle painting area with a tree and over the top to draw a stub. But I do not know how to keep it.


1

An easy way would be to store a 'state' for the tree. Right now, you're storing 2 pieces of information per tree:

-x value
-y value

If you add a third value for its state, then you can do something like this:

Cart #42673 | 2017-07-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1


I had this idea,but I couldn't do it.Ty)


No problem, glad to help.



[Please log in to post a comment]