TGC Codebase Backup



Zplane star field using sprites by Anonymous Coder

9th Nov 2003 7:54
Summary

A simple Z plane starfield Quite a fast routine



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Zplane Starfield using sprites
`By Jester    Contact Jester2000@btinternet.com
`tested on Amd 1.2GHz, 576Mb PC133 ram, Geforce 4 TI4200, Win XP

`Setup some variables

xsren=800                                 `Width of screen
ysren=600                                 `Height of screen
zscen=32                                  `Depth of Screen (16 or 32)
xrange=30                                 `number of angle around the centre
yrange=30                                 `same again
stars=500                                 `Number of stars

`setup arrays for X plane, Y plane, Xspeed, Yspeed
dim x(stars):dim y(stars):Dim xs(stars):dim ys(stars)

sync on:sync rate 0
set display mode xsren,ysren,zscrn
hide mouse

`Make a simple image for the stars
remstart
dot 1,1
get image 1,0,0,2,2
cls 0
remend
`remstart
circle 10,10,5
get image 1,0,0,20,20
cls 0
`remend



gosub setupstars

While mouseclick()=0
   set cursor 10,10                       `Just to show the FPS
   print screen fps()                     `I get 158 fps with my rig

   gosub Movestars
   sync
endwhile



setupstars:
for n=1 to stars                          `setup the stars at centre of screen
   x(n)=xsren/2
   y(n)=ysren/2
   xs(n)=(rnd(xrange)+1)-(xrange/2)       `with random speed and direction
   ys(n)=(rnd(yrange)+1)-(yrange/2)
   next n
return



movestars:
   for n=1 to stars
   inc x(n),xs(n)
   inc y(n),ys(n)

if x(n)<0 or x(n)>xsren or y(n)<0 or y(n)>ysren    `if they go off screen

   x(n)=xsren/2                                    `reset at centre of the screen
   y(n)=ysren/2
   xs(n)=(rnd(xrange)+1)-(xrange/2)
   ys(n)=(rnd(yrange)+1)-(yrange/2)

   endif
   sprite n,x(n),y(n),1
   next n
return