Book Blitz 3D

Blitz3D Forums/Blitz3D Beginners Area/Book Blitz 3D

Merrie(Posted 2006) [#1]
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


IPete2(Posted 2006) [#2]
Merrie,

In the random speed generation your balls could randomly select 0 as this lies between -3 and 3.

Change these to positive numbers and it will be fine.



Function CreateBall()

b.Ball=New ball
b\x=Rnd(WIDTH)
b\y=Rnd(HEIGHT)
b\xspeed=Rnd(1,3)
b\yspeed=Rnd(1,3)
End Function



....whistles...

IPete2.


H&K(Posted 2006) [#3]
Also, when posting if you put code inside
 [code]
[/code]

or

[/codebox]


Merrie(Posted 2006) [#4]
Woops, *blush* Ok sorry about that H&K thanks for letting me know.


H&K(Posted 2006) [#5]
Dont worry about it, weve all had to be told how to do it, because the FAQ page isnt easy to find