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

P#42662 2017-07-20 17:04 ( Edited 2017-07-21 20:58)

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!

P#42664 2017-07-20 17:33 ( Edited 2017-07-20 21:33)

Ty very much.

P#42670 2017-07-21 04:04 ( Edited 2017-07-21 08:04)

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

P#42671 2017-07-21 04:19 ( Edited 2017-07-21 08:19)

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.

P#42672 2017-07-21 04:41 ( Edited 2017-07-21 08:41)
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

P#42674 2017-07-21 09:48 ( Edited 2017-07-21 13:48)

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

P#42689 2017-07-21 16:50 ( Edited 2017-07-21 20:50)

No problem, glad to help.

P#42691 2017-07-21 16:58 ( Edited 2017-07-21 20:58)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 12:42:30 | 0.012s | Q:24