TGC Codebase Backup



Bandits2 by Rasdini

19th Feb 2004 12:38
Summary

Fixed line 752:Bandits tutorial fully remarked and explained



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem written by Richard Sardini - E-mail noramdia@adelphia.net
rem phone 814-504-6033
rem note the lack of gosubs.  I call this streamline programming

set display mode 800,600,32
cls
print "Welcome to Bandits!"
print "Use the joystick left and right to move or left and right arrow keys."
print "Use joystick fire button A to fire or spacebar on the keyboards"
print "Don't let the bandits get all your barrels of fuel."
print "Up and Down keys or joystick fire b and c to zoom your view in and out."
print "Press any key to start."
waiting:
if joystick fire a()=1 then goto startnow
if inkey$()="" then goto waiting

startnow:


   rem set colors
red=rgb(255,0,0):green=rgb(0,255,0):blue=rgb(0,0,255):black=rgb(0,0,0):white=rgb(255,255,255)

   rem create particle bitmaps 100(for aliens explosion)
   rem and 101(for ship explosion)
create bitmap 1,5,5
ink red,1:dot 2,2:dot 3,3:ink rgb(30,200,255),1:dot 2,3:blur bitmap 1,6:get image 100,0,0,5,5
delete bitmap 1
create bitmap 1,5,5
ink white,1:dot 2,2:dot 3,3:ink blue,1:dot 2,3:blur bitmap 1,6:get image 101,0,0,5,5
delete bitmap 1

   rem manual sync allows us to build source objects
   rem out of view.  All drawing that takes place off the screen
   rem occurs much faster than drawing directly to the screen
sync on

   rem initialize dimension variables
   rem ax#(10)=alien x pos, az#(10)=alien z pos.
   rem aox#(10)=alien offset x, aoz#(10)=alien offset z
   rem the offset creates the circular motions of the
   rem aliens av#(10)=is 0 to 360%
   rem arx(10) and ary(10) are also 0 to 360% for alien
   rem limb spin, this spins the cylender limb of the aliens
   rem am(10)=0 means alien has no barrel,am(10)=1 means alien has a barrel
   rem aex#(10) and aez#(10) are alien explosion cooridinates
   rem aed#(x) is alien explosion duration
   rem brlx#(10) and brlz#(10) are barrel cooridinates
   rem amf(10)=0 means alien is not firing, 1 means aliens has
   rem released a bomb, bx#(10) and bz#(10) are bomb coordinates

dim ax#(10):dim az#(10):dim aox#(10):dim aoz#(10):dim av#(10)
dim arx#(10):dim ary#(10):dim am(10):dim aex#(10):dim aez#(10):dim aed#(10)
dim brlx#(10):dim brlz#(10):dim amf(10):dim bx#(10):dim bz#(10)


   rem build planet and moon position planet
make object sphere 1000,1000:position object 1000,900,-2000,500
color object 1000,rgb(0,75,180):make object sphere 1001,200
color object 1001,rgb(255,100,50):make object sphere 1002,50
color object 1002,green

   rem set moon orbit variables
   rem mrad#=moons radius around planet,mox#=moon ofset x
   rem moz#=moon offset z, op#=orbital position 0-360.
mrad#=1200:mox#=0:moz#=0:op#=1
mrad2#=250:mox2#=0:moz2#=0:op2#=1

   rem make homeship
make object sphere 11,14:color object 11,rgb(0,0,255)
make object cone 1,5:make mesh from object 1,1:delete object 1
add limb 11,1,1
offset limb 11,1,0,0,10:rotate limb 11,1,90,0,0:color limb 11,1,red
make object sphere 1,15:scale object 1,125,100,20:make mesh from object 2,1:delete object 1
add limb 11,2,2:offset limb 11,2,0,0,-5:color limb 11,2,green
scale object 11,150,150,150

   rem make aliens
make object sphere 12,8:color object 12,rgb(200,80,140)
make object cylinder 1,20:scale object 1,100,10,100:make mesh from object 3,1:delete object 1
add limb 12,1,3:color limb 12,1,blue
add limb 12,2,1:color limb 12,2,green:offset limb 12,2,0,0,-15
rotate limb 12,2,-90,0,0
position object 12,int(sx#),0,int(sz#)+100
scale object 12,200,200,200

   rem make fuel barrel
make object cylinder 13,20:color object 13,blue:position object 13,680,0,-20:rotate object 13,90,0,0
scale object 13,50,100,50
hide object 12
hide mouse

   rem turn sync off and back on:if we don't do this
   rem when we jump to endofgame syn is turned off.
   rem if you choose yes for new game we jump back to start
   rem where we turn sync back on.  If you try to turn sync
   rem on or off when it is already that way will generate
   rem an error.
sync off

start:

sync on

   rem reset certain variables
sx#=350:sz#=0:camy=570:firedelay=0:angle1=0:barls=20:lev#=.15
clch=0:sed#=0:ships=5:freq=2000

   rem position ship
position object 11,int(sx#),0,int(sz#)

   rem clear the screen
cls rgb(0,0,0)

   rem color backdrop
color backdrop black

   rem if we don't increase camera range, moon disapears into
   rem the distance
set camera range 1,5000

   rem camera will stay put instead of moving to newly
   rem created objects
autocam off

   rem lets dim things
set ambient light 50

   rem make a spot light for home ship
make light 2
color light 2,255,255,255
set spot light 2,2,50
set light range 2,3000

   rem reset random generator
randomize 1

   rem send first wave of enemys
gosub sendaliens

   rem main loop, I have come to love the do-loop
   rem almost as much as the endif
do

rem check for pause
if inkey$()="p"

      rem turn off backdrop or print won't work
   backdrop off

      rem center cursor and print game paused
   set cursor screen width()/2-20,screen height()/2
   print "!GAME PAUSED!"

      rem you must sync to update screen
   sync
      rem wait for a key
   wait key

      rem don't forget to turn you backdrop back on
   backdrop on
endif

   rem bonus ships and barrels based on score
   rem increase frequency of fire for aliens
if score=10000 then ships=ships+1:score=score+100
if score=12000 then ships=ships+1:score=score+100
if score=15000 then ships=ships+1:freq=freq-100:score=score+100
if score=20000 then ships=ships+1:barls=barls+5:score=score+100
if score=22000 then ships=ships+1:freq=freq-100:score=score+100
if score=24000 then ships=ships+1:score=score+100
if score=28000 then ships=ships+1:freq=freq-100:score=score+100
if score=30000 then ships=ships+1:score=score+100
if score=32000 then ships=ships+1:freq=freq-100:score=score+100
if score=34000 then ships=ships+1:score=score+100
if score=36000 then ships=ships+1:freq=freq-100:score=score+100
if score=38000 then ships=ships+1:score=score+100
if score=40000 then ships=ships+1:freq=freq-100:score=score+100
if score=42000 then ships=ships+1:score=score+100
if score=44000 then ships=ships+1:freq=freq-100:score=score+100
if score=46000 then ships=ships+1:score=score+100
if score=50000 then ships=ships+5:barls=barls+10:score=score+100

   rem get ships position on the x-axis store in sx#
sx#=object position x(11)

   rem zoom camera in and out
if upkey()=1 or joystick fire b()=1
   if camy>570 then camy=camy-1
endif
if downkey()=1 or joystick fire c()=1
   if camy<1200 then camy=camy+1
endif

   rem position and point camera
position camera 350,camy,250
point camera 350,200,250

   rem calculate moons movement
mox#=cos(op#)*mrad#:moz#=sin(op#)*mrad#
mox2#=cos(op2#)*mrad2#:moz2#=sin(op2#)*mrad2#
   rem position the moons
position object 1001,900+int(mox#),-2000+int(moz#),500+(moz#/2)
position object 1002,900+int(mox#)+int(mox2#),-2000+int(moz#)+int(moz2#),500+(moz#/2)
   rem and then calculate its' movement
op#=op#+.025:if op#>360 then op#=1
op2#=op2#-1:if op2#<0 then op2#=360

   rem see if all aliens have been killed and if so gosub
   rem sendaliens for new wave
check=0:for x=1 to 10:if object exist(x)=1 then check=check+1
next x:if check=0 then gosub sendaliens

   rem position and point our spotlight
position light 2,object position x(11),0,object position z(11)+20
point light 2,object position x(11),0,object position z(11)+50

   rem did aliens steal all our barrels? if so goto endofgame
if barls=0 then goto endofgame

   rem see if alien has collided with homeship
t1=object collision(11,0)
   if t1>0 and t1<11

         rem deduct ship and goto endofgame if we are all out.
      ships=ships-1:if ships=0 then goto endofgame

         rem get position of alien for particles explosion
      aex#(t1)=object position x(t1):aez#(t1)=object position z(t1)

         rem if alien has barrel, get barrel position from
         rem aliens position and release barrel to fall
      if am(t1)=1 then brlx#(t1)=object position x(t1):brlz#(t1)=object position z(t1)-35

         rem delete the alien object,set alien explosion duration
         rem set homeship explosion duration,erase alien marker by setting
         rem am(t1)=0:If you don't set am(t1) to 0 then the next wave
         rem of aliens will all have barrels
      delete object t1:score=score+100:aed#(t1)=5:am(t1)=0:sed#=5

         rem make explosion particles for alien and homeship
         rem I use the particles exist to make sure there
         rem isn't already an explosion going on
         rem if particle does already exist then just
         rem skip the particle or you will get a particles
         rem already exist error.  Hide homeship for explosion
      if particles exist(t1)=0 then make particles t1,100,20,30:position particles t1,aex#(t1),0,aez#(t1):set particle chaos t1,20
      if particles exist(11)=0 then make particles 11,101,20,80:position particles 11,object position x(11),0,object position z(11):rotate particles 11,90,0,0:set particle chaos 11,30:hide object 11:position object 11,0,0,0
   endif

      rem if mothership is exploding then skip reading
      rem homeship movement
if particles exist(11)=1 then goto skipmove

      rem read keyboard or joystick
if leftkey()=1 or joystick left()=1

      rem only move ship if it isn't all the way to the left
   if object position x(11)>-100
      move object left 11,2
   endif
endif

if rightkey()=1 or joystick right()=1

      rem only move ship if it isn't all the way to the right
   if object position x(11)<800
      move object right 11,2
   endif
endif

   rem if we just fired then delay firing for
   rem 30 cycles through the main loopand skip it all together
if firedelay>0 then dec firedelay:goto skipit2

   rem read keyboard or joystick for fire
if joystick fire a()=1 or spacekey()=1

      rem pick=0 until we find an available bullet
   pick=0

      rem check all 4 bullets with for-next loop
   for x=21 to 24

         rem did we already find a free bullet?
         rem if so, goto skipit1 to finish for-next loop
      if pick=1 then goto skipit1

         rem if bullet does not exist, make it
      if object exist(x)=0

            rem make and position bullet
         make object box x,3,1,15:color object x,red
         position object x,object position x(11),0,object position z(11)+20

            rem set pick to 1, we found an available bullet
            rem set firedelay to 30:if we don't delay the fire
            rem all 4 bullets will fire so fast you will only
            rem see one bullet as they will be right on top
            rem of each other
         pick=1:firedelay=30
      endif
   skipit1:
   next x
endif

   rem remember, we skipped here if particles 11=1
   rem which means our ship is exploding
skipmove:

   rem is the homeship exploding?
if particles exist(11)=1

      rem increase ships explosion duration
   sed#=sed#+.5

      rem if sed#>170 explosion is as big as it will get
      rem and is over so delete particles and reposition
      rem homeship in center and show it.
   if sed#>170 then delete particles x:position object 11,350,0,0:show object 11

      rem if sed# was >170 then the explosion is over
      rem we deleted the particles
      rem so we will not attemp to adjust their settings
      rem right after we deleted said particles
      rem we will get a particles does not exist error
      rem that is why we checked particle existence
      rem twice in one loop
   if particles exist(x)=1

         rem change particle size, emissions
         rem coloring the particles randomly gives a slightly
         rem different nuance to each explosion
         rem detectable mostly by the subconscious
      set particle chaos x,int(sed#)
      set particle emissions x,int((140-sed#)/5)
      color particles x,rnd(255),rnd(255),rnd(255)
   endif
endif

skipit2:

   rem checking all 4 bullets to see if we hit a alien
   rem with for-next loop
for x=21 to 24

      rem is there a bullet?
   if object exist(x)=1

         rem move bullet forewards
      move object x,1

         rem has bullet finished traveling, if so delete it
      if object position z(x)>600 then delete object x

         rem did we just delete the bullet? if so we won't check
         rem to see if it hit any aliens.
         rem if there is a bullet
      if object exist(x)=1

            rem check collision between bullet and any
            rem other object on the screen
         t1=object collision(x,0)

            rem aliens are objects 1 through 10 so we check to
            rem see if collision value is greater than 1
            rem or <11, if so, we hit an alien, and we know
            rem which one.  What ever t1 is equal to
            rem for example, if t1 returns a value of 5
            rem we hit the 5th alien
         if t1>0 and t1<11

               rem get the aliens position x and z before we delete
               rem the alien or we will lose the objects positions
            aex#(t1)=object position x(t1):aez#(t1)=object position z(t1)

               rem does alien have a barrel, if so get its position
               rem so we can release it to fall
            if am(t1)=1 then brlx#(t1)=object position x(t1):brlz#(t1)=object position z(t1)-20

               rem delete the alien by deleting object t1
               rem add 100 to score, set alien explosion
               rem duration:set the alien marker to zero
               rem or next wave alien will already have a barrle
            delete object t1:score=score+100:aed#(t1)=5:am(t1)=0

               rem make explosion particles if they don't
               rem already exist
            if particles exist(t1)=0 then make particles t1,100,20,30:position particles t1,aex#(t1),0,aez#(t1):set particle chaos t1,20:color particles t1,rnd(255),rnd(255),rnd(255)

               rem now we must delete the bullet or it will
               rem keep on going
            delete object x
         endif
      endif
   endif
next x

   rem for next loop checks for all explosions
for x=1 to 10

      rem is there an explosion?
   if particles exist(x)=1
         rem yes there is an explosion

      aed#(x)=aed#(x)+.5

         rem increase explosion size and duration
         rem if duration is greater than 130 then
         rem exposion is over, delete the particles
      if aed#(x)>130 then delete particles x

         rem did we just delete particle 'cause the
         rem explosion just ended? 0=yes
      if particles exist(x)=1

            rem 1=no , explosion is still happening
            rem adjust particle setting
         set particle chaos x,int(aed#(x))
         set particle emissions x,int((140-aed#(x))/5)

            rem add some randome colors to explosion
         rem color particles x,rnd(255),rnd(255),rnd(255)
      endif
   endif
next x

   rem check for alien bombs and move them, check for kill
   rem using for-next loop
for x=1 to 10

   rem is there an alien bomb, 1=yes
if object exist(60+x)=1

      rem move bomb down.
   bz#(x)=bz#(x)-.5

      rem did bomb finish falling greater than -30 means no,
      rem bomb is still falling.  less than -30 means bomb has
      rem run its' course.  delete object 60+x deletes the bomb
   if bz#(x)<-30 then delete object 60+x:amf(x)=0

      rem did we just delete the object bomb. 0=yes
   if object exist(60+x)=1

         rem 1=no we did not delete object. bomb is still falling
      position object 60+x,bx#(x),0,bz#(x)

         rem check to see if bomb is colliding
         rem with any other objects.
      t1=object collision(60+x,0)

         rem if t1=11 then bomb collided with homeship
      if t1=11

            rem deduct one ship:amf(x)=0 resets alien bombing
            rem if it stays 1 then alien wont be able to bomb
            rem you, delete object 60+x deletes our bomb
         ships=ships-1:amf(x)=0:delete object 60+x:if ships=0 then goto endofgame

            rem make sure explosion and particles don't already
            rem exist or you will get a particles already exist
            rem error.  0 means no particles, go ahead and make
            rem new one. 1 means particle exist already
            rem so skipit all together
         if particles exist(11)=0

               rem set the duration of explosion
            sed#=5

               rem create particles,position at homeship location
               rem rotate particles to face upwards,hide object 11
               rem move ship from harms way. Hide homeship.
            make particles 11,101,20,80
            position particles 11,object position x(11),0,object position z(11)
            rotate particles 11,90,0,0:set particle chaos 11,30
            hide object 11:position object 11,0,0,0
         endif
      endif
   endif
endif
next x

   rem alien bombing sequence
for x=1 to 10

      rem is alien still alive?1=yes because our alien
      rem object still exist.  If we had shot it we would
      rem have deleted the object
   if object exist(x)=1

         rem I set frequency(freq)=1200 at beginning of the game
         rem I randomize the frequency. if the random number
      fir=rnd(freq)

         rem equals the freq/2 or 600, and the alien isn't
         rem too close to the ground(az#(x)>130) and
         rem amf=0 or alien does not have a bomb in the air.
         rem as we decrease the freq number, we increase the
         rem chance that we will get freq/2:in other words
         rem the smaller the number the better the chance
         rem fir=freq/2:rnd of 600 will turn up 300
         rem twice as much as rnd of 1200 will return 600
      if fir=freq/2 and az#(x)>130 and amf(x)=0

            rem commence dropping bomb:amf(x)=1 is alien fire marker
            rem also, get bomb position x and z
            rem from alien object position.
            rem offset z-axis -20 meaning the bomb falls
            rem just below the alien
         amf(x)=1:bx#(x)=object position x(x):bz#(x)=object position z(x)-20

               rem make sure bomb does not exist before
               rem we attempt to make it or we will get an
               rem object already exist error
            if object exist(60+x)=0
               make object sphere 60+x,8:color object 60+x,rgb(200,100,80)

                  rem position our bomb for the first time
                  rem before it gets repositioned by the
                  rem move bombs loop
               position object 60+x,int(bx#(x)),0,int(bz#(x))
            endif
      endif
   endif
next x

   rem time to move the aliens one at a time with a for-next loop
for x=1 to 10

   rem is there an alien? 1=yes
if object exist(x)=1

      rem we will increase clch(color change) once every time
      rem through our main loop.
   inc clch

      rem every 50 times, we change the aliens color.
      rem if we changed their color every time through
      rem the main loop, the aliens would change colors
      rem so fast, they will usually appear white.
   if clch>50
      color object x,rgb(rnd(255),rnd(255),rnd(255))
      color limb x,1,blue:color limb x,2,green

         rem reset color change variable to 0
      clch=0
   endif

      rem this will move aliens up right side and overrides all
      rem other movement, hence the goto skiphere
   if ax#(x)>750 and az#(x)<500 then az#(x)=az#(x)+lev#:av#(x)=av#(x)+.5:goto skiphere

      rem this will move the aliens from right to left across
      rem the top of the screen and overrides all other movement
      rem hence the goto skipher
   if az#(x)>500 then ax#(x)=ax#(x)-lev#:goto skiphere

      rem move alien from left to right across the screen
   ax#(x)=ax#(x)+lev#

      rem first leg of alien travel, just adjust alien offset
      rem 0 to 360%
   if ax#(x)>0 and ax#(x)<100 then av#(x)=av#(x)-.25

      rem secon leg, move alien up and adjust offset 0-360%
   if ax#(x)>100 and ax#(x)<200 then az#(x)=az#(x)+lev#:av#(x)=av#(x)-.5

      rem third leg, move alien down and adjust offset 0-360%
   if ax#(x)>200 and ax#(x)<275 then az#(x)=az#(x)-lev#:av#(x)=av#(x)+.5

      rem fourth leg, move alien down and adjust offset 0-360%
   if ax#(x)>275 and ax#(x)<300 then az#(x)=az#(x)+lev#:av#(x)=av#(x)+.5

      rem 5th leg, move alien down and adjust offset 0-360%
   if ax#(x)>300 and ax#(x)<400 then az#(x)=az#(x)-lev#:av#(x)=av#(x)+.5

      rem 6th leg, move alien down and adjust offset 0-360%
   if ax#(x)>400 and ax#(x)<500 then az#(x)=az#(x)+lev#:av#(x)=av#(x)+.5

      rem 7th leg, move alien down and adjust offset 0-360%
   if ax#(x)>500 and ax#(x)<550 then az#(x)=az#(x)-lev#:av#(x)=av#(x)+.5

      rem 8th leg, move alien down and adjust offset 0-360%
   if ax#(x)>500 and ax#(x)<600 then az#(x)=az#(x)-lev#:av#(x)=av#(x)+.5

      rem 9th leg, move alien down and adjust offset 0-360%
   if ax#(x)>600 and ax#(x)<750 then az#(x)=az#(x)-lev#:av#(x)=av#(x)-.5

      rem is alien close enough to steel barrel
   if ax#(x)>650 and az#(x)<20 and am(x)=0
      am(x)=1
         rem make sure object doesn't exist before
         rem we try to make it or you will get an
         rem object already exist error
         rem show tractor beam limb 2 of alien
      if object exist(40+x)=0 then clone object 40+x,13:show limb x,2:rotate object 40+x,90,0,0:scale object 40+x,50,50,50
   endif

      rem we skipped here to override all other movement
      rem because alien was either moving up the right side
      rem or trying to exit left.  By the way, I have programmed
      rem the aliens to exit left, but for some unexplained
      rem reason, every now and again they exit
      rem to the right.  If anyone can explain this glitch
      rem I would consider you a guru.
   skiphere:

      rem calculate our alien offset.  this determines how big
      rem a loop the alien flies in
   aox#(x)=cos(av#(x))*di:aoz#(x)=sin(av#(x))*di

      rem position the alien
   position object x,int(ax#(x)+aox#(x)),0,int(az#(x)+aoz#(x))

      rem does alien have a barrel 1=yes
   if am(x)=1

         rem position the barrel just below the alien hence the -35 on z
      position object 40+x,int(ax#(x)+aox#(x)),0,int(az#(x)+aoz#(x))-35
   endif

      rem did alien get away with a barrel
   if ax#(x)<-200 and az#(x)>500

         rem yes he did. subtract a barrel.  turn alien marker
         rem off(0) so alien isn't carrying a barrel next attack
         rem wave.  Also hide tractor beam limb 2
      if am(x)=1 then barls=barls-1:am(x)=0:hide limb x,2:delete object 40+x

         rem resend alien until dead or victorious
      ax#(x)=-100:az#(x)=100+rnd(150)
   endif

      rem
   if ax#(x)>950

         rem did alien get away with a barrel, if yes he did.
         rem subtract a barrel.  turn alien marker off(0) so alien
         rem isn't carrying a barrel next attack
         rem wave.  Also hide tractor beam limb 2
      if am(x)=1 then barls=barls-1:am(x)=0:hide limb x,2:delete object 40+x


         rem resend alien until dead or victorious
      ax#(x)=-100:az#(x)=100+rnd(150)
   endif
endif
next x

   rem check and move falling released barrels with for-next loop
for x=1 to 10

      rem is the a barrel loose. this is the reason for the
      rem 'and am(x)=0' if am(x)=1 then that means an alien
      rem is holding it and it shouldn't be falling
   if object exist(40+x)=1 and am(x)=0

         rem move barrel down. is barrel done falling?
         rem if so then delet barrel
      brlz#(x)=brlz#(x)-.25:if brlz#(x)<-50 then delete object 40+x

         rem did we just delete the barrel. 1=no,0=yes
      if object exist(40+x)=1

            rem position barrel
         position object 40+x,int(brlx#(x)),0,int(brlz#(x))

            rem check if barrel is colliding with an alien
         t1=object collision(40+x,0)

            rem if t1 returns a 1-10 then yes (t1 is the alien #)
         if t1>0 and t1<11

               rem does alien already have a barrel 0=no
            if am(t1)=0

                  rem set alien marker to 1, gives alien a barrel
               am(t1)=1

                  rem delete the barrel that was falling
               delete object 40+x

                  rem make sure barrel doesn't already exist
                  rem before making one to match the alien
                  rem number. clone new barrel 40+t1(alien#)
                  rem show alien tractor beam limb 2
                  rem rotate barrel upright:scale object down some
               if object exist(40+t1)=0 then clone object 40+t1,13:show limb t1,2:rotate object 40+t1,90,0,0:scale object 40+t1,50,50,50
            endif
         endif
      endif
   endif
next x

   rem rotate aliens outer cylinder
for x=1 to 10

      rem does alien exist 1=yes
   if object exist(x)=1

         rem rotate the limb
      rotate limb x,1,int(arx#(x)),int(ary#(x)),1
         rem increase x axis, decrease y axis
         rem these values must be kept between 0 and 360
      arx#(x)=arx#(x)+2:if arx#(x)>360 then arx#(x)=1
      ary#(x)=ary#(x)-2:if ary#(x)<1 then ary#(x)=360
   endif
next x

   rem prepare to print score,barrels and ships
   rem position cursor top left
set cursor 0,0
ink white,1
print "SCORE---->";score;"                                 <-BANDITS->              Written by:Richard Sardini"
print "BARRELS-->";barls
print "SHIPS----->";ships

   rem finally, after all this, we can refresh the screen
   rem and all the changes we made in the blink of an eye.
sync
loop

   rem our programs only subroutine, which could have also
   rem been slipped into the main loop if I wanted.
   rem this will create all 10 aliens and position them
sendaliens:

   rem just in case,delete all aliens even though we probably
   rem don't need to as our only avenue to this subroutine
   rem results from our check early in the main loop to see
   rem if all aliens are dead which means, all 10 object should
   rem have been deleted.(precautionary)
for x=1 to 10:if object exist(x)=1 then delete object x
next x

   rem y=alien #:ht=randomalien entry height
y=1:ht=rnd(200)

   rem di=random size of alien looping
di=rnd(120)+5

   rem create aliens with for-next loop
for x=-100 to -1000 step -100

   rem set location,reset alien offsets to 0:reset av#(y)(0-360)
   rem reset limb rotation for aliens
ax#(y)=x-100:az#(y)=100+ht:aox#(y)=0:aoz#(y)=0:av#(y)=0:am(y)=0
arx#(y)=1:ary#(y)=1

   rem make alien y though clone, position it, hide tractor beam limb 2
clone object y,12:position object y,ax#(y),0,az#(y):hide limb y,2
scale object y,140,140,140
   rem increment y to next alien
inc y:next x

   rem increase speed of aliens a little bit with each
   rem new level
lev#=lev#+.0125

   rem don't let the aliens get to fast
if lev#>5 then lev#=5

   rem return back to main loop with 10 newaliens
return

   rem end of the game
endofgame:

   rem clear the screen and turn backdrop off
cls
backdrop off

   rem turn off sync or display will flicker
sync off

   rem move cursor down 10 lines
for x=0 to 10:print "  ":next x

   rem print our end message
print "Nice game"

   rem print barrels stolen if that were the case
if barls=0 then print "All your fuel has been stolen."
print "Your score was--->";score
print "Want to play again(y/n)?"

   rem loop here until we get a valid input
loophere1:
if inkey$()="y"
      rem delete light as we will recreate it
   delete light 2

      rem delete all alien objects and particles
   for x=1 to 10
   if object exist(x)=1 then delete object x
   if object exist(40+x)=1 then delete object 40+x
   if particles exist(x)=1 then delete particles x
   next x

      rem restore our backdrop
   backdrop on

      rem reset some variables
   sx#=350:sz#=0:camy=570:firedelay=0:angle1=0:barls=20:lev#=.15
   clch=0:sed#=0:ships=5:score=0

      rem return to start of game
   goto start
endif

   rem end the game
if inkey$()="n" then end

   rem no valid input, get another input
goto loophere1