`Dark Shooter
`aka
`Nick's Shooting Game
 
`-----------------editable variables-------------------
 
`change when adding things to game
numcolors = 9              :`change when adding more colors for more images
numdrawings = 5            :`change when adding more images
numenemies = 2             :`change when adding more enemy drawings
 
`change to config game
numenemiesatatime = 3      :`max enemies on the screen at a time - up to 9
maxpowerupsatatime = 1     :`max powerups floating at a time - you'll usually want this at 1
maxshots = 8               :`max shots on the screen - up to 8
initialenemyspeed# = 1.5   :`initial speed enemies move at - up this to make it faster
maxescaped=9               :`max to let escape - if more than this escape the game is over
maxbombs=9                 :`maximum number of bombs the player can have
maxclouds=3                :`maximum number of clouds on screen
 
sync on
hide mouse
screenh=screen height()
screenw=screen width()
 
`intro
otheight=text height("A")
theight=0
hide all sprites
cls 0
ink rgb(255,255,255),0
center text 176,theight,"Log of Argus Jiba, June 29, 3980"                    :  inc theight,otheight*2
printslowly(0,theight,"I was on my way to investigate an emergency signal",1)   :  inc theight,otheight
printslowly(0,theight,"eminating from a planet in Sector 359 when my right",1)  :  inc theight,otheight
printslowly(0,theight,"thruster lost power, sending me on a new trajectory.",1) :  inc theight,otheight*2
sleep 600
printslowly(0,theight,"Though I fought to keep the craft straight, I lost",1)   :  inc theight,otheight
printslowly(0,theight,"control and the spaceship crashed onto an uninhabited",1):  inc theight,otheight
printslowly(0,theight,"planet somewhere in Sector 298.",1)                      :  inc theight,otheight*2
sleep 800
printslowly(0,theight,"At least, I thought it was uninhabited...",1)            :  inc theight,otheight*2
sleep 400
printslowly(0,theight,"As I walked away from the wreckage of my ship, I came",1):  inc theight,otheight
printslowly(0,theight,"upon some strange creatures that immediately tried to",1):  inc theight,otheight
printslowly(0,theight,"eat me.  I used the remaining power in my ship's",1):  inc theight,otheight
printslowly(0,theight,"crushed generator to charge my laser pistol and get in",1):  inc theight,otheight
printslowly(0,theight,"contact with Headquarters.  I relayed the information",1):  inc theight,otheight
printslowly(0,theight,"about the creatures, and received an answer just as my",1):  inc theight,otheight
printslowly(0,theight,"generator lost power:",1)                                :  inc theight,otheight*2
sleep 800
printslowly(0,theight,"ARGUS - DESTROY ALL ORGANISMS ON PLANET.",1)             :  inc theight,otheight*2
sleep 800
printslowly(0,theight,"And so, I set out on the unknown planet with nothing",1) :  inc theight,otheight
printslowly(0,theight,"but my trusty laser pistol...",1)                        :  inc theight,otheight*3
sleep 800
center text 176,theight,"PRESS ANY KEY TO START"
wait key
gosub _menu
 
gosub _setup
gosub _resetvariables
 
do
  cls
  gosub _background
  gosub _clouds
  gosub _enemies
  gosub _powerups
  gosub _movement
  gosub _shots
  gosub _playercollisions
  gosub _bombs
  gosub _finishhandle
  gosub _hud
  sync
loop
 
`----------------------------------------------------------------------GOSUBS!!!
 
_setup:
  cls
  center text screenw/2,screenh/2,"LOADING..."
  dim colors(numcolors)
  bgcol = hsv(36.0,1.0,0.28)
 
  restore data_colors
  for i=1 to numcolors
    read r,g,b
    colors(i)=rgb(r,g,b)
  next i
 
  `background
  create bitmap 1,512,512
  cls hsv(36.0,1.0,0.28)
  for i=1 to 50000
    ink hsv(36.0,1.0,0.21+(rnd(14)/100)),0
    dot rnd(512),rnd(512)
  next i
  blur bitmap 1,1
  get image 100,0,0,512,512
  delete bitmap 1
  create bitmap 1,screenw+1024,screenh+512
  cls hsv(36.0,1.0,0.28)
  for i=0 to screenw+1024 step 512
    for j=0 to screenh+512 step 512
      paste image 100,i,j
    next j
  next i
  get image 101,0,0,screenw+1024,screenh+512
  delete bitmap 1
 
  for drawings = 1 to numdrawings
    select drawings
      case 1
        restore data_man
      endcase
      case 2
        restore data_shot
      endcase
      case 3
        restore data_enemy_eye
      endcase
      case 4
        restore data_enemy_bat
      endcase
      case 5
        restore data_cloud1
      endcase
      case default
        end
      endcase
    endselect
    read tox,toy
    create bitmap 1,tox+1,toy+1
    set current bitmap 1
    cls 0
    for y=1 to toy
      for x=1 to tox
        read colnum
        ink colors(colnum),bgcol
        dot x,y
      next x
    next y
    get image drawings,1,1,tox+1,toy+1
    delete bitmap 1
  next drawings
 
  `generate powerup sprites (so simple they can be drawn)
 
  `bomb
  cls 0
  tlength = text height("B")+5
  midtlength = tlength/2
  ink colors(3),0
  circle midtlength,midtlength,midtlength-1
  ink colors(9),0
  center text midtlength,midtlength-(text height("B")/2),"B"
  get image 10,0,0,tlength,tlength
 
  `health
  cls 0
  tlength = text height("+")+5
  midtlength = tlength/2
  ink colors(9),0
  circle midtlength,midtlength,midtlength-1
  ink rgb(255,0,0),0
  center text midtlength,midtlength-(text height("+")/2),"+"
  get image 11,0,0,tlength,tlength
 
  for i=1 to numenemiesatatime
    enemies(i,2)=rnd(screenh)
    enemies(i,1)=screenw
    enemies(i,3)=rnd(numenemies-1)+3
  next i
return
 
_resetvariables:
  Dim enemies(numenemiesatatime,3) :`1=x 2=y 3=type (3-eye or 4-bat)
  Dim shots(maxshots,3)   :`1=x 2=y 3=on/off
  Dim clouds(maxclouds,3) :`1=x 2=y 3=speed
  p_y=screenh/2
  curshots=0
  curpu=0
  health=100
  escaped=0
  killed=0
  bombs=0
  bg_x = 0
  pu_x = screenw
  pu_y = rnd(screenh)
  pu_num=10
  finishstate=0
  e_speed#=initialenemyspeed#
  for i=1 to numenemiesatatime
    enemies(i,2)=rnd(screenh)
    enemies(i,1)=screenw
    enemies(i,3)=rnd(numenemies-1)+3
  next i
  for i=1 to maxclouds
    clouds(i,2)=rnd(screenh-(screenh/3))
    clouds(i,1)=screenw-rnd(screenw/2)
    clouds(i,3)=clouds(i,3)=(rnd(3)+1)/4
  next i
  gosub _drawinitial
return
 
_drawinitial:
  set current bitmap 0
  cls bgcol
  sprite 1,0,p_y,1
  scale sprite 1,400
return
 
_background:
  dec bg_x, e_speed#
  if bg_x<-512 then bg_x=0
  paste image 101,bg_x,0
return
 
_enemies:
  for i=1 to numenemiesatatime
    enemies(i,1)=enemies(i,1)-e_speed#
    sprite i+10,enemies(i,1),enemies(i,2),enemies(i,3)
    if enemies(i,1)<0
      inc escaped
      enemies(i,2)=rnd(screenh)
      enemies(i,1)=screenw
      enemies(i,3)=rnd(numenemies-1)+3
    endif
    scale sprite i+10,400
  next i
  inc e_speed#,0.001
return
 
_powerups:
  if curpu<maxpowerupsatatime
    r=rnd(1000)
    if r=1
      pu_num=10
      inc curpu
      pu_x = screenw
      pu_y = rnd(screenh)
      sprite 21,pu_x,pu_y,pu_num
      scale sprite 21,200
    endif
    if r=2
      pu_num=11
      inc curpu
      pu_x = screenw
      pu_y = rnd(screenh)
      sprite 21,pu_x,pu_y,pu_num
      scale sprite 21,200
    endif
  endif
  if curpu>0
    dec pu_x,5
    sprite 21,pu_x,pu_y,pu_num
  endif
  if pu_x<0
    delete sprite 21
    dec curpu
  endif
return
 
_movement:
  if upkey() then dec p_y,5
  if downkey() then inc p_y,5
  if p_y>screenh then p_y=screenh
  if p_y<-40 then p_y=-40
  sprite 1,0,p_y,1
return
 
_shots:
  if curshots>0
    for i=1 to maxshots
      if shots(i,3)=1
        shots(i,1)=shots(i,1)+5
        if shots(i,1) < screenw
          sprite i+1,shots(i,1),shots(i,2),2
          s_hit=sprite collision(i+1,0)
          if s_hit>9 and s_hit<20
            delete sprite i+1
            shots(i,3)=0
            delete sprite s_hit
            inc killed
            dec curshots
            enemies(s_hit-10,2)=rnd(screenh)
            enemies(s_hit-10,1)=screenw
            enemies(s_hit-10,3)=rnd(numenemies-1)+3
          endif
        else
          delete sprite i+1
          shots(i,3)=0
          dec curshots
        endif
      endif
    next i
  endif
  if spacekey() and spacesep=0 and curshots<maxshots
    inc curshots
    spacesep=15
    for i=1 to maxshots
      if shots(i,3)=0
        tshot=i
        exit
      endif
    next i
    shots(tshot,2)=p_y+16
    shots(tshot,1)=36
    sprite tshot+1,shots(tshot,1),shots(tshot,2),2
    scale sprite tshot+1,400
    shots(tshot,3)=1
  endif
  if spacesep>0 then dec spacesep
return
 
_playercollisions:
  p_hit=sprite collision(1,0)
  if p_hit>9 and p_hit<20
    dec health,10
    cls rgb(255,0,0)
    sync
  endif
  if p_hit=21
    delete sprite p_hit
    dec curpu
    if pu_num=10 and bombs<maxbombs then inc bombs,3
    if bombs>maxbombs then bombs=maxbombs
    if pu_num=11 and health<100 then inc health,25
    if health>100 then health=100
  endif
return
 
_bombs:
  if bombs>0 and scancode()=48 and bombsep=0
    bombsep=20
    dec bombs
    for i=1 to numenemiesatatime
      delete sprite i+10
      enemies(i,2)=rnd(screenh)
      enemies(i,1)=screenw
      enemies(i,3)=rnd(numenemies-1)+3
      inc killed
    next i
    cls rgb(255,255,0)
    sync
    wait 100
    cls bgcol
    sync
  endif
  if bombsep>0 then dec bombsep
return
 
_clouds:
  for i=1 to maxclouds
    clouds(i,1)=clouds(i,1)-(e_speed#+clouds(i,3))
    sprite i+24,clouds(i,1),clouds(i,2),5
    if clouds(i,1)<0
      clouds(i,2)=rnd(screenh-(screenh/3))
      clouds(i,1)=screenw
      clouds(i,3)=(rnd(3)+1)/4
    endif
    scale sprite i+24,400
  next i
return
 
_finishhandle:
  if escaped>maxescaped then finishstate=1 : gosub _finish : gosub _resetvariables
  if health<=0 then finishstate=2 : gosub _finish : gosub _resetvariables
return
 
_hud:
  ink colors(9),bgcol
  text 0,0,"Health: "+str$(health)
  text 0,otheight,"Killed: "+str$(killed)
  text 0,otheight*2,"Escaped: "+str$(escaped)
  if bombs>0 then text 0,otheight*3,"Bombs: "+str$(bombs)
return
 
_menu:
  selecteditem=2
  do
    cls
    theight=0
    center text screenw/2,theight,"Dark Shooter"   :  inc theight,otheight*4
    if selecteditem=1
      center text screenw/2,theight,">Play<" :  inc theight,otheight*2
    else
      center text screenw/2,theight,"Play" :  inc theight,otheight*2
    endif
    if selecteditem=2
      center text screenw/2,theight,">Help<" :  inc theight,otheight*2
    else
      center text screenw/2,theight,"Help" :  inc theight,otheight*2
    endif
    if upkey() and upbuffer=0 then dec selecteditem : upbuffer=15
    if downkey() and downbuffer=0 then inc selecteditem : downbuffer=15
    if selecteditem>2 then selecteditem=1
    if selecteditem<1 then selecteditem=2
    if returnkey()
      if selecteditem=1 then return
      if selecteditem=2 then gosub _help
    endif
    if downbuffer>0 then dec downbuffer
    if upbuffer>0 then dec upbuffer
    sync
  loop
return
 
_help:
  cls
  theight=0
  center text screenw/2,theight,"Help"                    :  inc theight,otheight*2
  sleep 800
  printslowly(0,theight,"In the game, use the up and down arrows to position yourself as you walk",1)   :  inc theight,otheight
  printslowly(0,theight,"across the planet.  Use the spacebar to fire lasers at the creatures.",1)   :  inc theight,otheight
  printslowly(0,theight,"Since you are supposed to kill all of the creatures, you are only allowed",1)   :  inc theight,otheight
  printslowly(0,theight,"to let 9 creatures get past you.  If a creature hits you, you",1)   :  inc theight,otheight
  printslowly(0,theight,"lose health.  The object of the game is to kill as many creatures as you can.",1)   :  inc theight,otheight
  printslowly(0,theight,"You may come across certain powerups, such as bombs, which clear the room of",1)   :  inc theight,otheight
  printslowly(0,theight,"creatures when you press B, and health packs, which raise your health.  Have Fun!",1)   :  inc theight,otheight*2
  sleep 800
  printslowly(0,theight,"Press any key to continue.",1)   :  inc theight,otheight
  wait key
return
 
_finish:
  if finishstate=1 then msg$="You let too many creatures escape!"
  if finishstate=2 then msg$="You died!"
  for i=1 to maxshots
    if shots(i,3)=1 then delete sprite i+1
    shots(i,3)=0
  next i
  for i=1 to numenemiesatatime
    delete sprite i+10
  next i
  for i=1 to maxclouds
    delete sprite i+24
  next i
  if curpu>0
    delete sprite 21
  endif
  delete sprite 1
  sync
  cls 0
  sync
  theight=0
  printslowly(0,theight,msg$,0) :  inc theight,otheight
  if killed>0
    if killed=1 then msg$="But not before you killed 1 creature!"
    if killed>1 then msg$="But not before you killed "+str$(killed)+" creatures!"
    printslowly(0,theight,str$,0)  :  inc theight,otheight
    if killed<10 then msg$="Keep trying!"
    if killed>=10 and killed<25 then msg$="Good job."
    if killed>=25 and killed<50 then msg$="Keep up the good work."
    if killed>=50 and killed<100 then msg$="You have the makings of a bounty hunter!"
    if killed>=100 and killed<150 then msg$="Excellent job!"
    if killed>=150 then msg$="You are AMAZING!"
    printslowly(0,theight,msg$,0)  :  inc theight,otheight
  endif
  sleep 1000
  printslowly(0,theight,"Press any key to restart or [ESC] to exit.",0)
  wait key
return
 
`--------------------------------------------------------------------DATA!!!!
 
end
data_colors:
data 40,40,40  :`1-almost black
data 170,85,0  :`2-light brown
data 253,221,111  :`3-fleshy
data 0,255,128 :`4-bright green
data 0,0,255   :`5-blue
data 128,128,128  :`6-gray
data 255,255,0 :`7-yellow
data 147,130,0  :`8-semi transparent (virtually) yellow
data 255,255,255  :`9-white
 
data_man:
remstart version 1
data 9,12
data 0,0,2,2,2,2,0,0,0
data 0,0,3,3,3,1,0,0,0
data 0,0,3,3,3,3,0,0,0
data 0,0,0,3,3,0,0,0,0
data 3,4,5,4,4,5,4,0,0
data 3,4,5,4,4,5,4,0,0
data 4,4,5,4,4,5,6,6,6
data 4,4,5,4,4,5,6,3,0
data 3,4,5,4,4,5,4,0,0
data 0,5,5,5,5,5,5,0,0
data 0,5,5,5,5,5,5,0,0
data 1,1,1,0,0,1,1,1,0
data 1,1,1,0,0,1,1,1,0
remend
data 9,12
data 0,2,2,2,2,0,0,0,0
data 0,3,3,3,1,0,0,0,0
data 0,3,3,3,3,0,0,0,0
data 0,0,3,3,0,0,0,0,0
data 4,5,4,4,5,4,0,0,0
data 4,5,4,4,5,6,6,6,6
data 4,5,4,4,5,6,3,0,3
data 4,5,4,4,5,4,0,0,0
data 5,5,5,5,5,5,0,0,0
data 5,5,5,5,5,5,0,0,0
data 1,1,1,0,1,1,1,0,0
data 1,1,1,0,1,1,1,0,0
 
data_shot:
data 6,3
data 0,0,8,8,8,0
data 8,7,7,7,7,8
data 0,0,8,8,8,0
 
data_enemy_eye:
data 9,9
data 0,0,0,4,4,4,0,0,0
data 0,4,4,0,0,0,4,4,0
data 0,4,0,0,0,2,0,4,0
data 4,9,9,0,2,0,0,0,4
data 4,1,9,0,0,2,2,0,4
data 4,9,9,0,0,0,0,2,4
data 0,4,0,0,2,2,0,4,0
data 0,4,4,2,0,0,4,4,0
data 0,0,0,4,4,4,0,0,0
 
data_enemy_bat:
data 15,4
data 0,1,1,1,1,0,1,1,1,0,1,1,1,1,0
data 1,0,0,0,0,1,5,1,5,1,0,0,0,0,1
data 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0
data 0,0,0,0,0,0,9,0,9,0,0,0,0,0,0
 
data_cloud1:
data 14,7
data 0,0,0,0,0,0,9,9,9,9,0,0,0,0
data 0,0,0,0,9,9,9,9,6,9,9,0,0,0
data 0,0,9,9,9,9,6,9,9,6,9,0,0,0
data 0,0,9,9,9,6,9,9,9,9,6,9,0,0
data 0,9,9,6,6,9,9,6,6,6,9,9,6,0
data 9,9,9,9,9,9,9,9,9,9,9,9,9,6
data 0,6,6,6,0,6,6,6,0,6,6,6,6,0
 
`---------------------------------------------------------------------------------FUNCTIONS
 
function printslowly(x,y,fullstr$,exitonkeypress)
  ink rgb(0,255,0),0
  `set text size,
  for i = 1 to len(fullstr$)
    if scancode()>0 and exitonkeypress
      text x,y,fullstr$
      exitfunction
    endif
 
    text x,y,left$(fullstr$,i)
 
    if scancode()>0 and exitonkeypress
      text x,y,fullstr$
      exitfunction
    endif
 
    sleep 100
 
    if scancode()>0 and exitonkeypress
      text x,y,fullstr$
      exitfunction
    endif
  next i
endfunction
 
function hsv(h#,s#,v#)
  i=0
  f#=0
  p#=0
  q#=0
  t#=0
 
  if s#=0.0
    exitfunction rgb(v#*255,v#*255,v#*255)
  endif
  h#=h#/60.0
  i=int(h#)
  f#=h#-i
  p#=v#*(1.0-s#)
  q#=v#*(1.0-s#*f#)
  t#=v#*(1.0-s#*(1.0-f#))
 
  select i
    case 0
      exitfunction rgb(v#*255,t#*255,p#*255)
    endcase
    case 1
      exitfunction rgb(q#*255,v#*255,p#*255)
    endcase
    case 2
      exitfunction rgb(p#*255,v#*255,t#*255)
    endcase
    case 3
      exitfunction rgb(p#*255,q#*255,v#*255)
    endcase
    case 4
      exitfunction rgb(t#*255,p#*255,v#*255)
    endcase
    case default
      exitfunction rgb(v#*255,p#*255,q#*255)
    endcase
  endselect
endfunction 0