RectsOverlap problem

Blitz3D Forums/Blitz3D Beginners Area/RectsOverlap problem

crash_master25(Posted 2003) [#1]
Hi!!

I'm working in a Snake like game in 2D... This is my first game in Blitz and I'm learning the language...
I have
Type worm
Field X, Y, H, W
end type
and the same for Walls, and food
now.. the localization for the walls is readed from Data wich have Level, #of walls, #of food, and the coods for each wall
thats ok, and works fine... I can draw each wall without problem, but the problem is that in the food the X, Y cords are Random and sometimes the food is behind the walls... then I use this:

For I = 1 To TotalC ;which is the total of food
F.Food = New Food ;Create a Food
Repeat
Ok = False
XF = Rnd(530) ;X cord of the food
YF = Rnd(470) ;Y Cord of the food
HF = 10 ;constant
WF = 10 ;Constant
For W.Wall = Each Wall ;all wall coords are here
XW = W\X ;X coord of wall
YW = W\Y ;Y coord of wall
HW = W\A ;Height of wall
WW = W\G ;Width coord of wall
If RectsOverlap(XF,YF,HF,WF,XP,YP,AP,GP) Then
OK = False
else
OK = True
End If
Next
Until OK = True
F\X = XF ; new coord without wall
F\Y = YF
Next

But the problem is that the food still behind the wall...

and really I don't know why

Can you help me???

Thanks
Bruno Chavez


DJWoodgate(Posted 2003) [#2]
The problem might be you do not bail out of your For loop if not OK. Try OK=False : Exit


Neo Genesis10(Posted 2003) [#3]
You dont state what the arguments are in RectsOverlap. The variables YP, AP and GP arent mentioned in your code. Try replacing this line:
If RectsOverlap(XF,YF,HF,WF,XP,YP,AP,GP)
With this one:
If RectsOverlap(XF,YF,HF,WF,XW,YW,WW,HW)
If I've read your code correctly, you're checking to see if there is an overlap between the food item and the current wall in the loop, but you dont check the wall variables.


crash_master25(Posted 2003) [#4]
Sorry... Was an error while posting the code here, I'm useing

If RectsOverlap(XF,YF,HF,WF,XW,YW,WW,HW)

Thanks
Bruno Chavez


crash_master25(Posted 2003) [#5]
I update with the

OK=False : Exit

but still the problem...

That is strange...

Thanks
Bruno chavez


Rottbott(Posted 2003) [#6]
Edit: Nevermind.


crash_master25(Posted 2003) [#7]
Yep...

Thanks a lot...

was OK : False : exit

Thanks
Bruno Chavez