boundires help

BlitzMax Forums/BlitzMax Beginners Area/boundires help

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

tryin to make the ball bounce of the paddles and walls and go in a random direction as long as it is in bounds..
thats where i need help . my bounds checking dos'nt seem to work..
help
(replace media with your own)

Type player
Field image:TImage
Field x#
Field y#
Field speed
End Type
Type ball
Field image:TImage
Field x#
Field y#
Field speed
Field dir
End Type

Global PList:TList= CreateList()
Global BList:TList= CreateList()


Graphics 400,400,0,60
SeedRnd MilliSecs()

SetMaskColor 0,0,0

Create_Player()
Create_Ball()

While Not KeyHit(Key_Escape)

Update_Player()
Update_Ball()


Flip
Cls
Wend

Function Create_Player()
p:player=New player
p.image=LoadImage("paddle1.bmp")
p.x=200
p.y=380
p.speed=3
PList.AddLast(p)
End Function
Function Update_Player()
For p:Player= EachIn PList
DrawImage(p.image,p.x,p.y)
If KeyDown(Key_Left) And p.x>0 Then p.x:-p.speed
If KeyDown(Key_Right) And p.x+ImageWidth(p.image)<400 Then p.x:+p.speed
Next
End Function
Function Create_Ball()
b:ball=New ball
b.image=LoadImage("ball1.bmp")
b.x=200
b.y=20
b.speed=2
b.dir=1
BList.AddLast(b)
End Function
Function Update_Ball()
For b:Ball=EachIn BList
DrawImage(b.image,b.x,b.y)
Select b.dir
Case 1
b.x=b.x
b.y:+b.speed
Case 2
b.x=b.x
b.y:-b.speed
Case 3 'downright
b.x:-b.speed
b.y:+b.speed
Case 4 'downleft
b.x:+b.speed
b.y:+b.speed
Case 5 'upleft
b.x:-b.speed
b.y:-b.speed
Case 6 'upright
b.x:+b.speed
b.y:-b.speed
End Select

For p:player=EachIn PList
If ImagesCollide(p.image,p.x,p.y,0,b.image,b.x,b.y,0)
b.dir=Rnd(2,6)
End If
If b.y<=3 b.dir=Rnd(1,6) <-- Bounds check
If b.x<=3 b.dir=Rnd(2,6) Help
If b.x>=598 b.dir=Rnd(2,6)
Next
Next
End Function