`-----------------------------------------------------------------------------------------------------------
`Basic 2d starfield in DBPro - Converted From an original I wrote in Blitz
`Mainly written to test out basic type usage in DBP
`-----------------------------------------------------------------------------------------------------------
sync rate 60:sync on `set window and sync rate etc
hide mouse `hide the mouse pointer (extra fps)
set display mode 800,600,16 `set display mode
global maxstars=250 `max stars is our total number of stars
gosub setup_stars `setup our stars and their original location
repeat `repeat
do `do the following loop
cls `clear screen to avoid tearing
gosub update_stars `update our stars
sync `sync our screen to see changes
loop `loop back to the do
until escapekey()=1 `until escape is pressed
end `if it is then end the program
`-----------------------------------------------------------------------------------------------------------
setup_stars:
type stars `define our custom type
field x,y,speed `and it's fields
endtype `end of type
dim star(maxstars) as stars `decide how many instances of the type we need
for a=0 to maxstars `fill the following variables "maxstars" amount of times
star(a).x=rnd(800) `random x position on the screen
star(a).y=rnd (600) `random y position on the screen
star(a).speed=rnd(5) `random speed
next `repeat and fill variable until we have filled them all
return `return from this subroutine and continue the program
`-----------------------------------------------------------------------------------------------------------
update_stars:
for a=0 to maxstars `repeat for all stars
circle star(a).x,star(a).y,1 `plot a circle at each stars x and y position
star(a).x=star(a).x-star(a).speed`move each star type by it's own star speed
if star(a).x < 0 `if it goes off the screen (position 0)
star(a).x=800 `redraw it again at the other side
endif `if not, don't bother
next `repeat the loop until all stars (as per maxstars) have been done
return `return from this subroutine
`---------------------------------------------------
Basic 2d starfield example using types...I converted it from one I originally wrote in Blitz2d, so it'll give you some sort of idea as to the difference between bb2d and dbp types..
(please note, I am not the best of coders, but you should get the idea)
For game/demo music for YOUR PC productions visit:-www.futuredevelopments.org.uk