Umm...Trying to update tree collisions.Help!

Blitz3D Forums/Blitz3D Beginners Area/Umm...Trying to update tree collisions.Help!

Cp(Posted 2008) [#1]
This is the code:
MakeTree(50,50)
MakeTree(128,128)

while not keydown(1);escape
;the while loop and movement code here, movements not the problem, so I dont put it here
	For tree.tree = Each tree
	DrawImage tree\image,tree\x,tree\y
	If ImagesCollide(boy\image,boy\x,boy\y,boy\frame,tree\image,tree\x,tree\y,0)
	IHitATree = 1
	EndIf
	If Not ImagesCollide(boy\image,boy\x,boy\y,boy\frame,tree\image,tree\x,tree\y,0)
	IHitATree = 0
	StopRight = 0
	StopUp = 0	
	StopDown = 0
 	StopLeft = 0
	EndIf
	Next

wend
Function MakeTree(x,y)
tree.tree = New tree
tree\x = x
tree\y = y
tree\image = pltree
End Function
Function TreeCollide()
	If IHitATree = 1
	If MoveRight = 1
	StopRight = 1
	EndIf

	If MoveLeft = 1
	StopLeft = 1
	EndIf

	If MoveUp = 1
	StopUp = 1
	EndIf

	If MoveDown = 1
	StopDown = 1
	EndIf
	IHitATree = 0
	EndIf
End Function


so, when I create two or more trees, only the latest one works for some reason.I can't collide with the old one????

stop vars are used to stop movement, I don't think thats the problem.

The boy and tree types:boy=player,tree=tree

Why does it only allow collisions with the new one???


Stevie G(Posted 2008) [#2]
You will only register a tree collision if the last tree is hit as you are reseting the I hit a tree variable to 0 for every tree which isn't hit.

Reset the IhitaTree outside the loop. I don't think your method is most efficient but I'm sure someone will some to your rescue on that front.

IHitATree = 0
StopRight = 0
StopUp = 0	
StopDown = 0
StopLeft = 0

For tree.tree = Each tree
	DrawImage tree\image,tree\x,tree\y
	If ImagesCollide(boy\image,boy\x,boy\y,boy\frame,tree\image,tree\x,tree\y,0)
		IHitATree = 1
	EndIf
Next



Cp(Posted 2008) [#3]
K. Ill try that.
EDIT:
That does the exact oppisite of what I want. now I cant collide with ANY of the trees.Thanks though.


Cp(Posted 2008) [#4]
Strange...When I use two seperate while loops it works...
Problem fixed. :)