I am working through the new book and am working with one of the tutorials called Bouncing Balls. Below is my code, my question is. I have about 6 balls that are stationary, 2 in the middle and 3 hovering on the right side.
Also, when I disable BugMode, run the program and try to escape out of the program, it does not work. Any ideas? Thanks!
AppTitle "Bouncing Balls"
Const BALL_COUNT=100
Const KEY_ESCAPE=1
Const WIDTH=640
Const HEIGHT=480
Type Ball
Field x,y
Field xspeed,yspeed
End Type
Function CreateBall()
b.Ball=New ball
b\x=Rnd(WIDTH)
b\y=Rnd(HEIGHT)
b\xspeed=Rnd(-3,3)
b\yspeed=Rnd(-3,3)
End Function
Function UpdateBall (b.ball)
If b\x<0 b\xspeed=-b\xspeed
If b\y<0 b\yspeed=-b\yspeed
If b\x>WIDTH b\xspeed=-b\xspeed
If b\y>HEIGHT b\yspeed=-b\yspeed
b\x=b\x+b\xspeed
b\y=b\y+b\yspeed
Oval b\x,b\y,10,10
End Function
Graphics WIDTH,HEIGHT
SetBuffer BackBuffer()
For i=1 To BALL_COUNT
CreateBall
Next
While Not KeyHit(KEY_ESCAPE)
Cls
For b.Ball=Each Ball
UpdateBall b
Next
Flip
Wend
End
Also, when I disable BugMode, run the program and try to escape out of the program, it does not work. Any ideas? Thanks!
AppTitle "Bouncing Balls"
Const BALL_COUNT=100
Const KEY_ESCAPE=1
Const WIDTH=640
Const HEIGHT=480
Type Ball
Field x,y
Field xspeed,yspeed
End Type
Function CreateBall()
b.Ball=New ball
b\x=Rnd(WIDTH)
b\y=Rnd(HEIGHT)
b\xspeed=Rnd(-3,3)
b\yspeed=Rnd(-3,3)
End Function
Function UpdateBall (b.ball)
If b\x<0 b\xspeed=-b\xspeed
If b\y<0 b\yspeed=-b\yspeed
If b\x>WIDTH b\xspeed=-b\xspeed
If b\y>HEIGHT b\yspeed=-b\yspeed
b\x=b\x+b\xspeed
b\y=b\y+b\yspeed
Oval b\x,b\y,10,10
End Function
Graphics WIDTH,HEIGHT
SetBuffer BackBuffer()
For i=1 To BALL_COUNT
CreateBall
Next
While Not KeyHit(KEY_ESCAPE)
Cls
For b.Ball=Each Ball
UpdateBall b
Next
Flip
Wend
End