TGC Codebase Backup



A Demo by OSX Using Happy Dude

12th Sep 2003 18:57
Summary

A demo featuring lines, dots and rotating sprites



Description

Enjoy!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: Lines
Rem Created: 09/09/2003 19:36:22

Rem ***** Main Source File *****
SYNC On
SYNC RATE 0

#constant MAXLINES   4*4
#constant MAXDOTS    128

screenWidth=screen width()
screenHeight=screen height()

type lines
   x as float
   y as float
   dx as float
   dy as float
   r as integer
   g as integer
   b as integer
endtype

type dots
   x as float
   y as float
   dy as float
   dx as float
endtype

dim l(MAXLINES) as lines
dim d(MAXDOTS) as dots

for x=1 to MAXDOTS
   d(x).x=0.0
   d(x).y=0.0
   d(x).dy=0.0
next x

randomize timer()
for x=1 to MAXLINES
   l(x).x=rnd(screenWidth>>1)*1.0
   l(x).y=rnd(screenHeight>>1)*1.0
   l(x).dx=(rnd(4)+1)*0.5
   l(x).dy=(rnd(4)+1)*0.5
   l(x).r=rnd(254)+1
   l(x).g=rnd(254)+1
   l(x).b=rnd(254)+1
next x

cls 0
print "Please Wait"
sync
sync

bmSize=screenWidth*2
create bitmap 1,bmSize,bmSize
set current bitmap 1
for x=0 to bmSize step 8
   for y=0 to bmSize step 8
      box x,y,x+8,y+8,_
         rgb(rnd(64),rnd(64),rnd(64)),_
         rgb(rnd(64),rnd(64),rnd(64)),_
         rgb(rnd(64),rnd(64),rnd(64)),_
         rgb(rnd(64),rnd(64),rnd(64))
   next y
next x
get image 1,0,0,bmSize-1,bmSize-1,1
set current bitmap 0

draw sprites first
sprite 1,screenWidth>>1,screenHeight>>1,1
offset sprite 1,bmSize>>1,bmSize>>1
angle#=0.0
dotColour=rgb(rnd(256-32)+32,rnd(256-32)+32,rnd(256-32)+32)
count=0
dir#=0.5
loopc=0
sa#=0.0
cls 0
sync
do
   sprite 1,(screenWidth>>1)+(64*sin(sa#)),(screenHeight>>1)+(64*cos(sa#)),1
   rotate sprite 1,angle#
   sa#=wrapvalue(sa#+1.0)
   angle#=wrapvalue(angle#+dir#)

   for x=1 to MAXLINES
      ink rgb(l(x).r,l(x).g,l(x).b),0
      if x<MAXLINES
         line l(x).x,l(x).y,l(x+1).x,l(x+1).y
      else
         line l(x).x,l(x).y,l(1).x,l(1).y
      endif

      inc l(x).x,l(x).dx
      if l(x).x<0
         l(x).x=0
         l(x).dx=-l(x).dx
         if rnd(100)<50
            l(x).dx=(rnd(4)+1)*0.5
         endif
         l(x).r=(l(x).r+1) && 255
         l(x).g=(l(x).g+1) && 255
         l(x).b=(l(x).b+1) && 255
      else
         if l(x).x>screenWidth-1
            l(x).x=screenWidth-1
            l(x).dx=-l(x).dx
            if rnd(100)>75
               l(x).dx=(rnd(4)+1)*0.5
            endif
            l(x).r=(l(x).r+1) && 255
            l(x).g=(l(x).g+1) && 255
            l(x).b=(l(x).b+1) && 255
         endif
      endif

      inc l(x).y,l(x).dy
      if l(x).y<0
         l(x).y=0
         l(x).dy=-l(x).dy
         if rnd(100)>40
            l(x).dx=(rnd(4)+1)*0.5
         endif
         l(x).r=(l(x).r+1) && 255
         l(x).g=(l(x).g+1) && 255
         l(x).b=(l(x).b+1) && 255
      else
         if l(x).y>screenHeight-1
            l(x).y=screenHeight-1
            l(x).dy=-l(x).dy
            if rnd(100)<30
               l(x).dy=(rnd(4)+1)*0.5
            endif
         endif
         l(x).r=(l(x).r+1) && 255
         l(x).g=(l(x).g+1) && 255
         l(x).b=(l(x).b+1) && 255
      endif
   next x

   for index=1 to MAXDOTS
      if d(index).x>0.0
         ink dotColour,0
         box d(index).x,d(index).y,d(index).x+2,d(index).y+2
         inc d(index).y,d(index).dy
         inc d(index).x,d(index).dx
         if d(index).y>screenHeight or d(index).x>screenWidth
            d(index).x=0.0
            d(index).y=0.0
         endif
      else
         if rnd(10)<3
            d(index).x=rnd(screenWidth)*1.0
            d(index).y=0.0
            d(index).dy=(rnd(5)+1)*1.0
            d(index).dx=((rnd(5)-1)*1.0)+0.5
         endif
      endif
   next index
   inc count
   if count>screenHeight*4
      dotColour=rgb(rnd(256-32)+32,rnd(256-32)+32,rnd(256-32)+32)
      count=0
   endif
   if loopc>2000
      loopc=0
      dir#=0.0-dir#
      if dir#>0.0
         inc dir#,0.25
         if dir#>2.0
            dir#=0.5
         endif
      endif
   else
      inc loopc
   endif
   text 0,0,"FPS:"+str$(screen fps())+" Speed:"+str$(dir#)+" Angle #2:"+str$(sa#)
   text 0,100,"SW:"+str$((screenWidth>>1)+(256*sin(sa#)))+" SH:"+str$((screenHeight>>1)+(256*cos(sa#)))
   sync
loop