Hello All!
My name is Jim and I'm new to DB and DB Pro. I just ordered the boxed set of DBPro yesterday and I'm using the evaluation version until it comes in the mail.
Anyway...
Whenever I'm new to a language I write a simple little program to put it through the riggers. It's always the same type of program. That is, a program that will bounce a random number of sprites all over the screen in random directions.
I keep increasing the number of sprites in order to see how smoothly the program will run.
Here's a link to my code:
http://www.Pishlo.Net/dbpro/Mine.zip
Or you can view it here:
REM Project: Mine
REM Created: 9/15/2004 11:04:32 AM
REM
REM ***** Main Source File *****
REM
set display mode 800,600,16
hide mouse
sync rate 0
sync on
backdrop off
`Phong is a 32 x 32 16 million color bitmap
load image "phong.bmp",1,0
`Mondy around with this number
max_phongs = 500
`Definition of a phong
type phong
spr AS INTEGER
x AS FLOAT
y AS FLOAT
xd AS FLOAT
yd AS FLOAT
endtype
`Dynaimcally allocated phong container
dim phongs(-1) as phong
`Call the function to create the phongs
create_phongs(max_phongs)
`Show them and wait
pause()
`Main program loop
repeat
cls
render_phongs(0)
sync
until escapekey()
end
`----------------------------------------------------------
`Functions
`----------------------------------------------------------
`Create a new phong and place it in the container
function new_phong(sp)
local p as phong
p.spr = sp
set sprite p.spr,0,1
p.x = 400
p.y = 300
p.xd = rnd_float#(4) * coin_flip() `A random float between -4 and 4
p.yd = rnd_float#(4) * coin_flip() `A random float between -4 and 4
array insert at top phongs(0)
phongs(0) = p
endfunction
`Function to create 'n' phongs
function create_phongs(n)
for i = 1 to n
new_phong(i)
next i
endfunction
`Flip a coin and return either -1 or 1
function coin_flip()
c = rnd(1)
if c = 0 then side = 1
if c = 1 then side = -1
endfunction side
`return a random float between 1 and 'num'
function rnd_float#(num)
n# = (rnd(999) / 999.0) * num
endfunction n#
`Draw phongs and update positions (bounce them around)
function render_phongs(paused)
for i = 1 to array count(phongs(0))
sprite phongs(i).spr, phongs(i).x, phongs(i).y,1
if paused = 0 `If paused do not update positions
phongs(i).x = phongs(i).x + phongs(i).xd
phongs(i).y = phongs(i).y + phongs(i).yd
if phongs(i).x >= (800 - sprite width(phongs(i).spr)) or phongs(i).x <= 0 then phongs(i).xd = -phongs(i).xd
if phongs(i).y >= (600 - sprite height(phongs(i).spr)) or phongs(i).y <= 0 then phongs(i).yd = -phongs(i).yd
endif
next i
endfunction
`Show phongs and wait for spacebar
function pause()
repeat
cls
print "Paused [Space] to continue"
render_phongs(1)
sync
until spacekey()
endfunction
I've actually got the program running pretty smoothly with 500 sprites on my laptop (Pentium 4 2.4 Ghz ATI something or other video chip).
In fact, the equivalent program for Blitz Plus and Blitz 3D don't run as fast as it does on DBPro.
I was wondering if there was anyway I can optimize the code any further to make it even smoother. (Aside from using a particle emitter).
Thanks in advance.
-Jim