` Grid Bugs    LBFN  Started 7/5/07
randomize timer()
sync on : sync rate 45
hide mouse
dim p1(10) : dim spray(30,10) : dim bug(24,20) : dim btu(12) : dim bd(30)
dim grid_coordx(8) : dim grid_coordy(7)
score=0
level=1
lives=3
bd_master=2500
max_bugs_aat=5 : ` max bugs that can be on the screen at one time (includes larvae)
 gosub INIT_VARS
 gosub SCREEN_SETUP
 gosub MAKE_IMGS
 gosub TITLE_SCREEN
Grid(70,70,10,9,48,48,RGB(255,255,255),RGB(150,70,0))
get image 999,700,150,799,400
` MAIN LOOP *************************************************************************************
do
  if (timer()>bd_master_delay or bugs_on_screen=0) and bugs_on_screen<max_bugs_aat and missed_bugs+bugs+bugs_on_screen<total_bugs and bd(3)=0 then gosub NEW_BUGS
  if bd(3)>0 then gosub MOVE_BUG_DISPENSER
  gosub MOVE_BUGS
  gosub USER_INPUT
 ` gosub DEBUG
  gosub SPRAY_EM
  gosub DP_STUFF
  if missed_bugs+bugs=total_bugs and bugs_on_screen=0 and spray_on=0 and bd(3)=0 then gosub FINISH_LEVEL
  sync
loop
` MAIN LOOP *************************************************************************************
show mouse
` screen back to normal
set display mode scr_wid,scr_hgt,scr_dpt
sync
end
 
 
` SUBROUTINES
 
MOVE_BUGS:
for i=1 to 24
  if bug(i,3)>0 and bug(i,3)<3
    if timer()>bug(i,6)
      bug(i,3)=bug(i,3)+1
      if bug(i,3)=2 then bug(i,4)=18 : bug(i,2)=bug(i,2)-4 : bug(i,6)=timer()+2500
      if bug(i,3)=3
        bug(i,2)=bug(i,2)-4
        if rnd(100)>50
          if rnd(100)>50
            bug(i,4)=20 : ` current pat
            bug(i,7)=20 : ` min pat
            bug(i,8)=22 : ` max pat
            bug(i,9)=8  : ` dir = left
            bug(i,10)=0-(rnd(2)+1) : ` x add
            bug(i,11)=0 : ` y add
          else
            bug(i,4)=23
            bug(i,7)=23
            bug(i,8)=25
            bug(i,9)=4 : ` dir = right
            bug(i,10)=rnd(2)+1
            bug(i,11)=0
          endif
        else
          if rnd(100)>50
            bug(i,4)=26 : ` current pat
            bug(i,7)=26 : ` min pat
            bug(i,8)=28 : ` max pat
            bug(i,9)=1  : ` dir = up
            bug(i,10)=0 : ` x add
            bug(i,11)=0-(rnd(2)+1) : ` y add
          else
            bug(i,4)=29 : ` current pat
            bug(i,7)=29 : ` min pat
            bug(i,8)=31 : ` max pat
            bug(i,9)=2  : ` dir = down
            bug(i,10)=0 : ` x add
            bug(i,11)=rnd(2)+1 : ` y add
          endif
        endif
      endif
    endif
  else
    if bug(i,3)=3
      bug(i,1)=bug(i,1)+bug(i,10)
      bug(i,2)=bug(i,2)+bug(i,11)
      ` animate bug
      if timer()>bug(i,5)
        bug(i,4)=bug(i,4)+1
        if bug(i,4)>bug(i,8) then bug(i,4)=bug(i,7)
        bug(i,5)=timer()+75
      endif
      ` check to see if the bug is on the grid
      if bug(i,1)<41 or bug(i,1)>550 or bug(i,2)<41 or bug(i,2)>502 then delete sprite 200+i : bug(i,3)=0 : inc missed_bugs,1 : dec bugs_on_screen,1
    endif
    if bug(i,3)=4
      ` bug frying
      if timer()>bug(i,5)
        bug(i,4)=bug(i,4)+1
        if bug(i,4)>bug(i,8)
          inc bugs,1
          dec bugs_on_screen,1
          bug(i,3)=0
          delete sprite i+200
        endif
        bug(i,5)=timer()+75
      endif
    endif
  endif
  if bug(i,3)>0 then sprite 200+i,bug(i,1),bug(i,2),bug(i,4)
next i
return
 
MOVE_BUG_DISPENSER:
x=bd((bd(3)*2)+4) : y=bd((bd(3)*2)+5)
if abs(bd(1)-x)>bd(26)
  if bd(1)<x
    bd(1)=bd(1)+bd(26)
  else
    bd(1)=bd(1)-bd(26)
  endif
else
 bd(1)=x
endif
if abs(bd(2)-y)>bd(27)
  if bd(2)<y
    bd(2)=bd(2)+bd(27)
  else
    bd(2)=bd(2)-bd(27)
  endif
else
  bd(2)=y
endif
if bd(1)=x and bd(2)=y and bug(btu(bd(3)),3)=0 and bd(3)<bd(28)-1
  ` we are at the way point
  bd(4)=15
  bd(5)=timer()+150
  x=x+41 : y=y+107
  sprite btu(bd(3))+200,x,y,17
  bug(btu(bd(3)),3)=1 : ` status=small larvae
  bug(btu(bd(3)),4)=17
  bug(btu(bd(3)),6)=2000+timer()
  bug(btu(bd(3)),1)=x-9
  bug(btu(bd(3)),2)=y-5
  bd(3)=bd(3)+1
  bd(5)=timer()+150 : ` keep img 15 for a split second
  inc bugs_on_screen,1
  bd_master_delay=1000+timer()+rnd(bd_master)
endif
if bd(3)=bd(28)-1 and bd(1)=x and bd(2)=y then bd(3)=0
if timer()>bd(5) then bd(4)=16
if bd(3)>0 then sprite 300,bd(1),bd(2),bd(4)
return
 
 
NEW_BUGS:
` find bugs to use
for i=1 to 4 : btu(i)=0 : next i
b=0
for i=1 to 24
  if bug(i,3)=0 then inc b,1 : btu(b)=i : if b=8 or (bugs+missed_bugs+bugs_on_screen+b>=total_bugs) or b+bugs_on_screen>=max_bugs_aat then exit
next i
if b=0 then return : ` no bugs available to use
` set initial spot for bug dispenser
d=rnd(2)
select d
  case 0
   ` left side
   bd(1)=-100
   bd(2)=rnd((scr_hgt-200)+50)
  endcase
  case 1
   ` top
   bd(1)=rnd(400)+50
   bd(2)=-170
  endcase
  case 2
   ` bottom
   bd(1)=rnd(400)+50
   bd(2)=scr_hgt+150
  endcase
endselect
bd(3)=1 : ` status=moving from initial x,y to first way point
bd(4)=16
` make way points
repeat
  okay=0
  for i=0 to b-1
    bd(6+(i*2))=grid_coordx(rnd(7)+1)-41
    bd(7+(i*2))=grid_coordy(rnd(6)+1)-107
  next i
  ` make sure no pairs are exactly the same
  c=0
  for i=0 to b-1
   if c<>i
     if (bd(6+(c*2))=bd(6+(i*2))) and (bd(7+(c*2))=bd(7+(i*2))) then okay=1
   endif
  next i
until okay=0
bd((b*2)+6)=bd(1) : bd((b*2)+7)=bd(2)
bd(28)=b+2
return
 
SPRAY_EM:
if spacekey()=1 and (spray_on=0 or (spray_on=1 and timer()>spray_timer))
  select p1(7)
    case 1
    ` facing up
      for i=1 to 30
        spray(i,1)=p1(3)+rnd(25) : ` x
        spray(i,2)=p1(4)-rnd(5) : ` y
        spray(i,3)=1 : ` status = active
        spray(i,4)=rnd(150)+150 : ` life
        spray(i,5)=rnd(2) : ` x add
        if rnd(100)>50 then spray(i,5)=(spray(i,5)*-1)
        spray(i,6)=0-(rnd(2)+4) : ` y subtract
        sprite 100+i,spray(i,1),spray(i,2),rnd(4)+10
        p1(9)=0 : p1(10)=-22
      next i
      spray_on=1
      spray_timer=timer()+250
    endcase
    case 2
    ` facing down
      for i=1 to 30
        spray(i,1)=p1(3)+rnd(15) : ` x
        spray(i,2)=p1(4)+rnd(5)+46 : ` y
        spray(i,3)=2 : ` status = active
        spray(i,4)=rnd(150)+150 : ` life
        spray(i,5)=rnd(2) : ` x add
        if rnd(100)>50 then spray(i,5)=(spray(i,5)*-1)
        spray(i,6)=(rnd(2)+4) : ` y subtract
        sprite 100+i,spray(i,1),spray(i,2),rnd(4)+10
        p1(9)=0 : p1(10)=20
      next i
      spray_on=1
      spray_timer=timer()+250
    endcase
    case 4
    ` facing right
      for i=1 to 30
        spray(i,1)=p1(3)+rnd(15)+48 : ` x
        spray(i,2)=p1(4)+rnd(9)+3 : ` y
        spray(i,3)=4 : ` status = active
        spray(i,4)=rnd(150)+150 : ` life
        spray(i,5)=rnd(2)+4 : ` x add
        spray(i,6)=rnd(2) : ` y add
        if rnd(100)>50 then spray(i,6)=(spray(i,6)*-1)
        sprite 100+i,spray(i,1),spray(i,2),rnd(4)+10
        p1(9)=22 : p1(10)=0
      next i
      spray_on=1
      spray_timer=timer()+250
    endcase
    case 8
    ` facing left
      for i=1 to 30
        spray(i,1)=p1(3)-rnd(15) : ` x
        spray(i,2)=p1(4)+rnd(9)+3 : ` y
        spray(i,3)=8 : ` status = active
        spray(i,4)=rnd(150)+150 : ` life
        spray(i,5)=0-(rnd(2)+4) : ` x add
        spray(i,6)=rnd(2) : ` y add
        if rnd(100)>50 then spray(i,6)=(spray(i,6)*-1)
        sprite 100+i,spray(i,1),spray(i,2),rnd(4)+10
        p1(9)=-22
        p1(10)=0
      next i
      spray_on=1
      spray_timer=timer()+250
    endcase
  endselect
endif
if spray_on=1
  ` spray is active, keep moving spray
  for i=1 to 30
    if spray(i,3)>0
      spray(i,1)=spray(i,1)+spray(i,5)
      spray(i,2)=spray(i,2)+spray(i,6)
      spray(i,4)=spray(i,4)-(abs(spray(i,5))+abs(spray(i,6)))
      if spray(i,4)<=0
        spray(i,3)=0 : delete sprite 100+i
        spray_on=0
        for q=1 to 30
          if spray(q,3)>0 then spray_on=1
        next q
        if spray_on=0 then p1(9)=0 : p1(10)=0 : total_spray_time=timer()-spray_timer : `set cursor 0,0 : print "total_spray_time= ";total_spray_time
      else
        ` spray particle is still alive
        sprite 100+i,spray(i,1),spray(i,2),rnd(4)+10
        for q=1 to 24
          ` check for coinc w/bugs
          if bug(q,3)>0 and bug(q,3)<>4
             if spray(i,1)>=bug(q,1) and spray(i,1)<=(bug(q,1)+sprite width(q+200))
               if spray(i,2)>=bug(q,2) and spray(i,2)<=(bug(q,2)+sprite height(q+200))
                  bug(q,3)=4 : ` frying
                  select bug(q,9)
                    case 1
                      ` up
                      bug(q,4)=500 : ` current pat
                      bug(q,7)=500 : ` min pat
                      bug(q,8)=505 : ` max pat
                    endcase
                    case 2
                      ` down
                      bug(q,4)=506 : ` current pat
                      bug(q,7)=506 : ` min pat
                      bug(q,8)=511 : ` max pat
                    endcase
                    case 4
                    ` right
                      bug(q,4)=512 : ` current pat
                      bug(q,7)=512 : ` min pat
                      bug(q,8)=517 : ` max pat
                    endcase
                    case 8
                      ` left
                      bug(q,4)=518 : ` current pat
                      bug(q,7)=518 : ` min pat
                      bug(q,8)=523 : ` max pat
                    endcase
                  endselect
                  bug(i,5)=timer()+75
                 score=score+100
               endif
             endif
          endif
        next q
        if timer()>spray_timer then p1(9)=0 : p1(10)=0
      endif
    endif
  next i
endif
return
 
 
DP_STUFF:
paste image 998,650,433
ink rgb(0,255,0),0
text 690,445,str$(score)
paste image 997,650,490
ink rgb(255,255,255),0
text 711,500,str$(missed_bugs)
return
 
 
FINISH_LEVEL:
copy bitmap 0,1
set current bitmap 0
cls
hide sprite 1
hide sprite 2
ink rgb(128,64,255),0
box 40,40,759,560
ink rgb(180,0,180),0
box 60,60,739,540
ink rgb(255,255,255),0
set text size 48
sync
center text 400,70,"LEVEL EVALUATION"
ink rgb(128,64,255),0
box 60,130,739,140
ink rgb(128,0,255),0
text 80,150,"Your rank is:"
set text size 48
ink rgb(156,130,48),0
` give ranking
advance=0 : bonus=0
if missed_bugs=0
  ` terminator
   advance=1
   bonus=5000
   a$="X Terminator!"
endif
if missed_bugs>0 and missed_bugs<=3
   ` master tech
   a$="Master Bug Destroyer"
   advance=1
   bonus=2000
endif
if missed_bugs>3 and missed_bugs<=5
   ` okay average
   a$="Close, but no cigar."
 
endif
if missed_bugs>5 and missed_bugs<=10
   ` below average - need to improve
   a$="The bugs win this round."
endif
if missed_bugs>10
   ` lousy
   a$="Do better or you'll lose your job!"
endif
text 80,200,a$
if bonus>0 then text 80,240,"Bonus "+str$(bonus)+" points!" : score=score+bonus
if advance=1
  if level<10
    text 80,280,"Shuss is warming up his next batch."
    inc level,1
    ` good place to shorten times, increase bugs, etc.
    bd_master=bd_master-250 : if bd_master<250 then bd_master=250
    inc total_bugs,5
    if max_bugs_aat<16 then inc max_bugs_aat,1
  else
    cls
    set text size 18
    sync
    text 80,280,"Congratulations!!  You have defeated Shuss' bug army!!!"
    paste image 1005,400,100
    sync
    text 80,400,"Press any key to quit."
    wait key
    end
    ` squashed bug w/white flag , score
  endif
else
  text 80,360,"You must do better to"
  text 80,400," take on Shuss' next batch."
endif
set text size 26
sync
ink rgb(26,141,204),0
text 80,480,"Press any key to continue."
text 80,510,"Press ESC to quit."
wait key
cls
copy bitmap 1,0
set current bitmap 0
gosub INIT_VARS
gosub DP_STUFF
show sprite 1
show sprite 2
return
 
 
USER_INPUT:
if leftkey()=1
  select p1(7)
    case 1
      ` facing up
      if p1(1)>68
        p1(1)=p1(1)-10
        p1(3)=p1(3)-10
      else
        ` switch to facing right
        p1(1)=0
        p1(2)=501
        p1(3)=24
        p1(4)=501
        p1(5)=1 : ` img 1
        p1(6)=2 : ` img 2
        p1(7)=4
 
      endif
    endcase
    case 2
      ` facing down
      if p1(1)<551
        p1(1)=p1(1)+10
        p1(3)=p1(3)+10
      else
        ` switch to facing left
        p1(1)=560+47
        p1(2)=66
        p1(3)=560
        p1(4)=66
        p1(7)=8 : ` facing left
        p1(5)=3 : ` img 1
        p1(6)=4 : ` img 2
      endif
    endcase
    case 4
      ` facing right
      if p1(2)>65
        p1(2)=p1(2)-10
        p1(4)=p1(4)-10
      else
        ` change to facing down
        p1(1)=73
        p1(2)=2
        p1(3)=73
        p1(4)=2+23
        p1(7)=2 : ` facing down
        p1(5)=5 : ` img 1
        p1(6)=6 : ` img 2
      endif
    endcase
    case 8
      ` facing left
      if p1(2)<506
        p1(2)=p1(2)+10
        p1(4)=p1(4)+10
      else
        ` switch to facing up
        p1(1)=549
        p1(2)=512+45
        p1(3)=549
        p1(4)=512
        p1(5)=7 : ` img 1
        p1(6)=8 : ` img 2
        p1(7)=1
 
      endif
    endcase
  endselect
endif
if rightkey()=1
select p1(7)
    case 1
      ` facing up
      if p1(1)<550
        p1(1)=p1(1)+6
        p1(3)=p1(3)+6
      else
        ` switch to facing left
        p1(1)=560+47
        p1(2)=505
        p1(3)=560
        p1(4)=505
        p1(7)=8 : ` facing left
        p1(5)=3 : ` img 1
        p1(6)=4 : ` img 2
      endif
    endcase
    case 2
      ` facing down
      if p1(1)>72
        p1(1)=p1(1)-6
        p1(3)=p1(3)-6
      else
        ` change to facing right
        p1(1)=0
        p1(2)=62
        p1(3)=24
        p1(4)=62
        p1(5)=1 : ` img 1
        p1(6)=2 : ` img 2
        p1(7)=4
      endif
    endcase
    case 4
      ` facing right
      if p1(2)<502
        p1(2)=p1(2)+6
        p1(4)=p1(4)+6
      else
        ` change to facing up
        p1(1)=69
        p1(2)=512+45
        p1(3)=69
        p1(4)=512
        p1(5)=7 : ` img 1
        p1(6)=8 : ` img 2
        p1(7)=1
      endif
    endcase
    case 8
      ` facing left
      if p1(2)>65
        p1(2)=p1(2)-6
        p1(4)=p1(4)-6
      else
        ` switch to facing down
        p1(1)=550
        p1(2)=2
        p1(3)=550
        p1(4)=2+23
        p1(5)=5 : ` img 1
        p1(6)=6 : ` img 2
        p1(7)=2
 
      endif
    endcase
  endselect
endif
sprite 1,p1(1)+p1(9),p1(2)+p1(10),p1(5)
sprite 2,p1(3),p1(4),p1(6)
return
 
 
 
INIT_VARS:
 
p1(1)=0 : ` x1
p1(2)=200 : ` y1
p1(3)=24 : ` x2
p1(4)=200 : ` y2
p1(5)=1 : ` img 1
p1(6)=2 : ` img 2
p1(7)=4 : ` direction  1=facing up   2=facing down  4=facing right   8=facing left
p1(8)=0 : ` plunger level 0=full out  4=pushed in all the way
p1(9)=0 : ` plunger x add
p1(10)=0 : ` plunger y add
 
for i=1 to 10
  spray(i,3)=0
next i
spray_on=0
for i=1 to 24
  for g=1 to 10
    bug(i,g)=0
  next g
next i
bugs=0 : ` includes active bugs + destroyed bugs
total_bugs=49 : ` # of bugs for the entire level
bugs_on_screen=0
 
for i=1 to 30 : bd(i)=0 : next i
bd(26)=5 : bd(27)=4
missed_bugs=0
restore grid_coord
for i=1 to 8
  read grid_coordx(i)
  if i<8 then grid_coordy(i)=grid_coordx(i)
next i
bd_master_delay=1000+timer()+rnd(bd_master)
return
 
 
DEBUG:
paste image 999,700,150
ink rgb(255,0,255),0
text 700,150,"bd(3))= "+str$(bd(3))
text 700,170,"bugs on scr= "+str$(bugs_on_screen)
text 700,190,"bd(28)="+str$(bd(28))
 
 
return
 
 
Function Grid(XPosition,YPosition,Columns,Rows,XSize,YSize,CellColourF,CellColourB)
  Ink CellColourB,0
  Box XPosition,YPosition,XPosition+(Columns*(XSize+1)),YPosition+(Rows*(YSize+1))
  Ink CellColourF,0
  For N=0 To Rows
    Line XPosition,  N*(YSize+1)+YPosition,  Columns*(XSize+1)+XPosition,  N*(YSize+1)+YPosition
  Next N
  For N=0 To Columns
    Line N*(XSize+1)+XPosition,  YPosition,  N*(XSize+1)+XPosition,  Rows*(YSize+1)+YPosition
  Next N
Endfunction
 
 
 
SCREEN_SETUP:
scr_wid=screen width()
scr_hgt=screen height()
scr_dpt=screen depth()
set display mode 800,600,16
sync
create bitmap 1,800,600
set current bitmap 0
 
return
 
 
MAKE_IMGS:
` P1 a bug sprayer
set current bitmap 1
cls
x=0 : y=0
ink rgb(255,255,128),0
line x,y+3,x,y+9
ink rgb(128,64,0),0
line x+1,y+3,x+1,y+9
line x+2,y+6,x+23,y+6
ink rgb(0,225,0),0
box x+24,y+2,x+68,y+3
box x+24,y+9,x+68,y+10
ink rgb(0,255,0),0
line x+24,y+6,x+68,y+6
line x+24,y+11,x+68,y+11
ink rgb(0,205,0),0
box x+24,y+4,x+68,y+5
box x+24,y+7,x+68,y+8
ink rgb(0,185,0),0
line x+24,y+6,x+68,y+6
ink rgb(185,0,0),0
cx=59 : cy=12
for i=2 to 3
 circle cx,cy,i
next i
ink rgb(205,0,0),0
for i=4 to 5
 circle cx,cy,i
next i
ink rgb(225,0,0),0
for i=6 to 7
 circle cx,cy,i
next i
ink rgb(255,0,0),0
 circle cx,cy,8
get image 1,0,0,23,16
get image 2,24,0,71,24
sprite 7,-100,-100,1
hide sprite 7
cls
mirror sprite 7
paste sprite 7,0,0
sync
sync
get image 3,0,0,23,16
cls
sprite 7,-100,-100,2
paste sprite 7,0,0
sync
sync
get image 4,0,0,47,24
cls
ink rgb(255,255,128),0
line x+3,y+1,x+9,y+1
ink rgb(128,64,0),0
line x+3,y,x+9,y
line x+6,y+2,x+6,y+23
ink rgb(0,255,0),0
line x+1,y+24,x+1,y+67
line x+11,y+24,x+11,y+67
ink rgb(0,225,0),0
box x+2,y+24,x+3,y+67
box x+9,y+24,x+10,y+67
ink rgb(0,205,0),0
box x+4,y+24,x+5,y+67
box x+7,y+24,x+8,y+67
ink rgb(0,185,0),0
line x+6,y+24,x+6,y+67
ink rgb(185,0,0),0
cx=11 : cy=58
for i=2 to 3
 circle cx,cy,i
next i
ink rgb(205,0,0),0
for i=4 to 5
 circle cx,cy,i
next i
ink rgb(225,0,0),0
for i=6 to 7
 circle cx,cy,i
next i
ink rgb(255,0,0),0
circle cx,cy,8
get image 5,0,0,9,23
get image 6,0,24,24,69
cls
sprite 6,-100,-100,6
flip sprite 6
paste sprite 6,0,0
get image 8,0,0,23,48
cls
ink rgb(255,255,128),0
line x+3,y+22,x+9,y+22
ink rgb(128,64,0),0
line x+3,y+23,x+9,y+23
line x+6,y,x+6,y+23
get image 7,0,0,9,23
sync
flip sprite 6
delete sprite 6
delete sprite 7
sync
sync
` make particles for spray
cls
ink rgb(255,255,255),0
box 0,0,2,2
get image 10,0,0,2,2
cls
ink rgb(180+rnd(40),180+rnd(40),180+rnd(40)),0
box 0,0,2,2
get image 11,0,0,2,2
cls
ink rgb(140+rnd(40),140+rnd(40),140+rnd(40)),0
box 0,0,2,2
get image 12,0,0,2,2
cls
ink rgb(100+rnd(40),100+rnd(40),100+rnd(40)),0
box 0,0,2,2
get image 13,0,0,2,2
cls
ink rgb(60+rnd(40),60+rnd(40),60+rnd(40)),0
box 0,0,2,2
get image 14,0,0,2,2
 
` make small larvae
cls
ink rgb(255,255,128),0
line 2,0,4,0 : line 11,0,14,0
dot 1,1 : line 5,1,10,1
line 0,2,0,5 : line 15,1,15,4
line 7,5,10,5 : dot 14,5
dot 1,6 : dot 6,6 : line 10,6,13,6
line 2,7,5,7
ink rgb(195,195,68),0
line 2,1,4,1 : line 11,1,14,1
box 1,2,14,4
line 1,5,6,5 : line 11,5,13,5
line 2,6,5,6
get image 17,0,0,16,8
` make large larvae
cls
ink rgb(255,255,128),0
line 3,0,7,0 : line 17,0,21,0
dot 2,1 : line 8,1,9,1 : line 15,1,16,1 : dot 22,1
line 1,2,1,3 : line 10,2,14,2 : line 23,2,23,6
line 0,4,0,8 : line 22,7,22,8
line 11,8,15,8
dot 1,9 : dot 10,9 : line 16,9,21,9
dot 2,10 : dot 9,10
line 3,11,8,11
ink rgb(195,195,68),0
line 3,1,7,1 : line 17,1,21,1
line 2,2,9,2 : line 15,2,22,2
line 2,3,22,3
box 1,4,21,7 : line 22,4,22,6
line 1,8,10,8 : line 16,8,21,8
line 2,9,9,9
line 3,10,8,10
get image 18,0,0,24,12
` bug facing left
cls
ink rgb(128,128,128),0
dot 9,0 : line 16,0,16,1 : dot 23,0
line 10,1,10,2 : line 11,2,11,6
line 17,2,17,6 : dot 22,1
line 21,2,21,6
line 11,15,11,19 : line 17,15,17,19
line 21,15,21,19 : line 10,19,10,20
dot 9,21 : line 16,20,16,22
dot 22,20 : dot 23,21
ink rgb(135,0,0),0
box 12,5,16,6 : box 18,5,20,6
dot 10,6 : line 22,6,23,6
line 9,15,10,15 : box 12,15,16,16
box 18,15,20,16 : line 22,15,23,15
ink rgb(215,0,0),0
line 10,7,24,7 : line 9,8,26,8
line 8,9,26,9 : line 10,12,26,12
line 8,13,26,13 : line 8,14,24,14
ink rgb(255,0,0),0
box 9,10,27,11
ink rgb(255,255,0),0
dot 7,9 : dot 8,8 : line 9,6,9,7
dot 7,11 : line 8,12,9,12
ink rgb(188,124,0),0
line 4,6,5,6 : line 2,7,7,7
line 2,13,7,13 : line 4,14,5,14
ink rgb(158,94,0),0
line 1,8,7,8 : line 0,9,3,9 : dot 6,9
line 0,11,6,11 : dot 8,11
line 1,12,3,12 : line 6,12,7,12
ink rgb(128,64,0),0
line 2,10,8,10
ink rgb(5,5,5),0
line 4,9,5,9 : line 4,12,5,12
get image 20,0,0,28,23
sync
cls
sprite 8,-100,-100,20
mirror sprite 8
paste sprite 8,0,0
sync
sync
get image 23,0,0,28,23
mirror sprite 8
delete sprite 8
` anim bug
cls
ink rgb(128,128,128),0
dot 14,0 : line 7,1,8,1 : line 9,2,10,2 : dot 10,3 : line 11,4,11,6
line 15,1,15,2 : dot 16,3 : line 17,4,17,6 : line 21,1,21,6
line 11,15,11,20 : line 12,21,12,22 : line 17,15,17,19
line 18,20,18,22 : line 21,15,21,17 : line 22,17,22,18
line 23,19,23,20 : dot 24,21
ink rgb(135,0,0),0
box 12,5,16,6 : box 18,5,20,6
dot 10,6 : line 22,6,23,6
line 9,15,10,15 : box 12,15,16,16
box 18,15,20,16 : line 22,15,23,15
ink rgb(215,0,0),0
line 10,7,24,7 : line 9,8,26,8
line 8,9,26,9 : line 10,12,26,12
line 8,13,26,13 : line 8,14,24,14
ink rgb(255,0,0),0
box 9,10,27,11
ink rgb(255,255,0),0
dot 7,9 : dot 8,8 : line 9,6,9,7
dot 7,11 : line 8,12,9,12
ink rgb(188,124,0),0
line 4,6,5,6 : line 2,7,7,7
line 2,13,7,13 : line 4,14,5,14
ink rgb(158,94,0),0
line 1,8,7,8 : line 0,9,3,9 : dot 6,9
line 0,11,6,11 : dot 8,11
line 1,12,3,12 : line 6,12,7,12
ink rgb(128,64,0),0
line 2,10,8,10
ink rgb(5,5,5),0
line 4,9,5,9 : line 4,12,5,12
get image 21,0,0,28,23
sync
cls
sprite 9,-110,-100,21
mirror sprite 9
paste sprite 9,0,0
sync
sync
get image 24,0,0,28,23
mirror sprite 9
delete sprite 9
` 2nd anim bug
cls
ink rgb(128,128,128),0
line 5,2,7,2 : line 8,3,10,3 : line 11,4,11,6
line 12,1,13,1 : line 14,2,15,2 : dot 16,3 : line 17,4,17,6
dot 18,0 : dot 19,1 : line 20,2,20,3 : line 21,4,21,6
line 11,15,11,17 : line 12,18,12,19 : line 13,20,14,20 : dot 15,21
line 17,15,17,17 : line 18,18,18,19 : line 19,20,20,20 : line 21,21,22,21
line 21,15,21,16 : dot 22,17 : line 23,18,24,18 : line 25,19,26,19
ink rgb(135,0,0),0
box 12,5,16,6 : box 18,5,20,6
dot 10,6 : line 22,6,23,6
line 9,15,10,15 : box 12,15,16,16
box 18,15,20,16 : line 22,15,23,15
ink rgb(215,0,0),0
line 10,7,24,7 : line 9,8,26,8
line 8,9,26,9 : line 10,12,26,12
line 8,13,26,13 : line 8,14,24,14
ink rgb(255,0,0),0
box 9,10,27,11
ink rgb(255,255,0),0
dot 7,9 : dot 8,8 : line 9,6,9,7
dot 7,11 : line 8,12,9,12
ink rgb(188,124,0),0
line 4,6,5,6 : line 2,7,7,7
line 2,13,7,13 : line 4,14,5,14
ink rgb(158,94,0),0
line 1,8,7,8 : line 0,9,3,9 : dot 6,9
line 0,11,6,11 : dot 8,11
line 1,12,3,12 : line 6,12,7,12
ink rgb(128,64,0),0
line 2,10,8,10
ink rgb(5,5,5),0
line 4,9,5,9 : line 4,12,5,12
get image 22,0,0,28,23
sync
cls
sprite 9,-100,-100,22
mirror sprite 9
paste sprite 9,0,0
sync
sync
get image 25,0,0,28,23
mirror sprite 9
delete sprite 9
` bug facing up
cls
ink rgb(128,128,128),0
dot 0,15 : line 1,13,1,14 : line 2,12,3,12 : line 4,11,6,11
line 0,21,0,22 : line 1,19,1,20 : line 2,18,3,18 : line 4,17,6,17
line 2,25,2,26 : line 3,23,3,24 : dot 4,22 : line 5,21,6,21
line 15,11,17,11 : line 18,8,18,10 : line 19,5,19,7
line 15,17,17,17 : dot 18,16 : line 19,14,19,15 : line 20,12,20,13
line 15,21,17,21 : line 18,20,19,20 : dot 20,19 : dot 21,18
 
ink rgb(135,0,0),0
line 6,9,6,10 : box 5,12,6,16 : box 5,18,6,20 : line 6,22,6,23
dot 15,10 : box 15,12,16,16 : box 15,18,16,20 : line 15,22,15,23
ink rgb(215,0,0),0
line 7,8,7,24 : line 8,8,8,26 : line 9,10,9,26
line 12,8,12,26 : line 13,10,13,26 : line 14,10,14,24
ink rgb(255,0,0),0
box 10,9,11,27
ink rgb(255,255,0),0
line 9,8,9,9 : dot 10,7 : dot 12,7 : dot 13,8 : line 14,9,15,9
ink rgb(188,124,0),0
line 7,4,7,5 : line 8,2,8,7 : line 14,2,14,7 : line 15,4,15,5
ink rgb(158,94,0),0
line 9,1,9,3 : line 9,6,9,7 : line 10,0,10,6 : dot 10,8
line 12,0,12,3 : dot 12,6 : line 13,1,13,7
ink rgb(128,64,0),0
line 11,2,11,8
ink rgb(5,5,5),0
line 9,4,9,5 : line 12,4,12,5
get image 26,0,0,22,28
cls
sprite 7,-100,-100,26
flip sprite 7
paste sprite 7,0,0
sync
sync
get image 29,0,0,22,28
cls
flip sprite 7
delete sprite 7
sync
sync
` bug facing up anim
cls
ink rgb(128,128,128),0
dot 0,12 : line 1,11,6,11 : line 0,18,1,18 : line 2,17,6,17
line 0,23,1,23 : line 2,22,4,22 : line 4,21,6,21
line 15,11,17,11 : line 18,10,19,10 : line 20,9,21,9
line 15,17,17,17 : line 19,15,21,15 : dot 18,16
line 15,21,19,21 : line 20,20,21,20
 
ink rgb(135,0,0),0
line 6,9,6,10 : box 5,12,6,16 : box 5,18,6,20 : line 6,22,6,23
dot 15,10 : box 15,12,16,16 : box 15,18,16,20 : line 15,22,15,23
ink rgb(215,0,0),0
line 7,8,7,24 : line 8,8,8,26 : line 9,10,9,26
line 12,8,12,26 : line 13,10,13,26 : line 14,10,14,24
ink rgb(255,0,0),0
box 10,9,11,27
ink rgb(255,255,0),0
line 9,8,9,9 : dot 10,7 : dot 12,7 : dot 13,8 : line 14,9,15,9
ink rgb(188,124,0),0
line 7,4,7,5 : line 8,2,8,7 : line 14,2,14,7 : line 15,4,15,5
ink rgb(158,94,0),0
line 9,1,9,3 : line 9,6,9,7 : line 10,0,10,6 : dot 10,8
line 12,0,12,3 : dot 12,6 : line 13,1,13,7
ink rgb(128,64,0),0
line 11,2,11,8
ink rgb(5,5,5),0
line 9,4,9,5 : line 12,4,12,5
get image 27,0,0,22,28
sync
cls
sprite 10,-100,-100,27
flip sprite 10
paste sprite 10,0,0
sync
sync
get image 30,0,0,22,28
cls
flip sprite 10
delete sprite 10
sync
sync
` 3rd anim - bug facing up
cls
ink rgb(128,128,128),0
line 2,5,2,7 : line 3,8,3,10 : line 4,11,6,11
line 1,12,1,13 : line 2,14,2,15 : dot 3,16 : line 4,17,6,17
dot 0,18 : dot 1,18 : line 2,20,3,20 : line 4,21,6,21
line 15,11,17,11 : line 18,12,19,12 : line 20,13,20,14 : dot 21,15
line 15,17,17,17 : line 18,18,19,18 : line 20,19,20,20 : line 21,21,21,22
line 15,21,16,21 : dot 17,22 : line 18,23,18,24 : line 19,25,19,26
 
ink rgb(135,0,0),0
line 6,9,6,10 : box 5,12,6,16 : box 5,18,6,20 : line 6,22,6,23
dot 15,10 : box 15,12,16,16 : box 15,18,16,20 : line 15,22,15,23
ink rgb(215,0,0),0
line 7,8,7,24 : line 8,8,8,26 : line 9,10,9,26
line 12,8,12,26 : line 13,10,13,26 : line 14,10,14,24
ink rgb(255,0,0),0
box 10,9,11,27
ink rgb(255,255,0),0
line 9,8,9,9 : dot 10,7 : dot 12,7 : dot 13,8 : line 14,9,15,9
ink rgb(188,124,0),0
line 7,4,7,5 : line 8,2,8,7 : line 14,2,14,7 : line 15,4,15,5
ink rgb(158,94,0),0
line 9,1,9,3 : line 9,6,9,7 : line 10,0,10,6 : dot 10,8
line 12,0,12,3 : dot 12,6 : line 13,1,13,7
ink rgb(128,64,0),0
line 11,2,11,8
ink rgb(5,5,5),0
line 9,4,9,5 : line 12,4,12,5
get image 28,0,0,22,28
sync
sprite 7,-100,-100,28
flip sprite 7
cls
sync
paste sprite 7,0,0
sync
sync
get image 31,0,0,22,28
cls
flip sprite 7
delete sprite 7
sync
sync
 
` make bug dispenser
cls
r=180+rnd(40) : g=110+rnd(40) : b=35+rnd(40)
ink rgb(r,g,b),1
for i=2 to 36
 inc r,1 : inc g,1 : inc b,1
 ink rgb(r,g,b),0
 circle 49,49,i
 circle 50,50,i
 circle 51,50,i
next i
sprite 8,-360,-360,20
paste sprite 8,33,39
sync
sync
get image 15,11,0,91,92
paste image 15,100,0
get image 15,43,60,57,95
paste image 15,43,87
get image 15,40,70,60,79
paste image 15,40,105
paste image 15,129,87
get image 15,11,0,91,72+36+6
get image 16,100,0,191,97
delete sprite 8
` light switch - down position
cls
ink rgb(255,255,128),0
box 0,0,50,99
ink rgb(225,225,108),0
box 3,3,49,97
ink rgb(255,255,128),0
box 18,33,31,66
line 48,3,48,96
line 3,96,48,96
ink rgb(96,96,96),0
box 19,34,29,50
ink rgb(225,225,108),0
line 49,3,49,97
line 2,97,49,97
line 20,52,29,52
line 29,52,29,63
line 20,63,29,63
line 21,54,27,54
line 27,54,27,61
get image 50,0,0,51,100
cls
sprite 8,-100,-100,50
flip sprite 8
paste sprite 8,0,0
sync
sync
get image 51,0,0,51,100
flip sprite 8
delete sprite 8
sync
` White bug facing left
cls
ink rgb(255,255,255),0
dot 9,0 : line 16,0,16,1 : dot 23,0
line 10,1,10,2 : line 11,2,11,6
line 17,2,17,6 : dot 22,1
line 21,2,21,6
line 11,15,11,19 : line 17,15,17,19
line 21,15,21,19 : line 10,19,10,20
dot 9,21 : line 16,20,16,22
dot 22,20 : dot 23,21
box 12,5,16,6 : box 18,5,20,6
dot 10,6 : line 22,6,23,6
line 9,15,10,15 : box 12,15,16,16
box 18,15,20,16 : line 22,15,23,15
line 10,7,24,7 : line 9,8,26,8
line 8,9,26,9 : line 10,12,26,12
line 8,13,26,13 : line 8,14,24,14
box 9,10,27,11
dot 7,9 : dot 8,8 : line 9,6,9,7
dot 7,11 : line 8,12,9,12
line 4,6,5,6 : line 2,7,7,7
line 2,13,7,13 : line 4,14,5,14
line 1,8,7,8 : line 0,9,3,9 : dot 6,9
line 0,11,6,11 : dot 8,11
line 1,12,3,12 : line 6,12,7,12
line 2,10,8,10
line 4,9,5,9 : line 4,12,5,12
get image 518,0,0,28,23
sync
cls
sprite 11,-100,-100,518
mirror sprite 11
paste sprite 11,0,0
sync
sync
get image 512,0,0,28,23
mirror sprite 11
delete sprite 11
bow=5
for i=513 to 517
  cls
  paste image 512,0,0
  `box 29-bow,0,29,28
  get image i,0,0,28-bow,23
  inc bow,5
next i
bow=5
for i=519 to 523
  cls
  paste image 518,0,0
`  box 0,0,bow,28
  get image i,bow,0,28,23
  cls
  paste image i,bow,0
  get image i,0,0,28,23
  inc bow,5
next i
` white bug facing up
cls
ink rgb(255,255,255),0
dot 0,15 : line 1,13,1,14 : line 2,12,3,12 : line 4,11,6,11
line 0,21,0,22 : line 1,19,1,20 : line 2,18,3,18 : line 4,17,6,17
line 2,25,2,26 : line 3,23,3,24 : dot 4,22 : line 5,21,6,21
line 15,11,17,11 : line 18,8,18,10 : line 19,5,19,7
line 15,17,17,17 : dot 18,16 : line 19,14,19,15 : line 20,12,20,13
line 15,21,17,21 : line 18,20,19,20 : dot 20,19 : dot 21,18
line 6,9,6,10 : box 5,12,6,16 : box 5,18,6,20 : line 6,22,6,23
dot 15,10 : box 15,12,16,16 : box 15,18,16,20 : line 15,22,15,23
line 7,8,7,24 : line 8,8,8,26 : line 9,10,9,26
line 12,8,12,26 : line 13,10,13,26 : line 14,10,14,24
box 10,9,11,27
line 9,8,9,9 : dot 10,7 : dot 12,7 : dot 13,8 : line 14,9,15,9
line 7,4,7,5 : line 8,2,8,7 : line 14,2,14,7 : line 15,4,15,5
line 9,1,9,3 : line 9,6,9,7 : line 10,0,10,6 : dot 10,8
line 12,0,12,3 : dot 12,6 : line 13,1,13,7
line 11,2,11,8
line 9,4,9,5 : line 12,4,12,5
get image 500,0,0,22,28
cls
sprite 7,-100,-100,500
flip sprite 7
paste sprite 7,0,0
sync
sync
get image 506,0,0,22,28
cls
flip sprite 7
delete sprite 7
sync
sync
bow=5
for i=501 to 505
  cls
  paste image 500,0,0
  get image i,0,bow,22,28
  inc bow,5
  cls
  paste image i,0,bow
  get image i,0,0,22,28
next i
bow=5
for i=507 to 511
  cls
  paste image 506,0,0
 ` box 0,28-bow,22,28
  get image i,0,0,22,28-bow
  inc bow,5
next i
cls
` We give up!
ink rgb(255,255,255),0
box 14,0,35,25
ink rgb(0,128,255),0
line 19,1,19,5 : line 20,6,21,6 : line 22,4,22,5 : line 23,6,24,6
line 25,1,25,5 : line 27,3,27,5 : dot 28,2 : line 28,4,29,4 : line 28,6,29,6
line 16,10,16,14 : line 17,9,19,9 : dot 20,10 : line 17,15,19,15
line 19,13,20,13 : dot 20,14 : dot 23,10 : line 23,12,23,15
line 26,12,26,14 : dot 27,15 : line 28,12,28,14 : dot 31,11
line 30,12,30,14 : line 32,12,32,14 : dot 31,13 : line 31,15,32,15
line 18,18,18,22 : line 19,23,21,23 : line 22,18,22,22 : line 24,20,24,24
line 24,20,26,20 : line 25,22,26,22 : dot 27,21 : line 31,18,31,21 : dot 31,23
ink rgb(128,64,0),0
line 13,0,13,40
ink rgb(135,0,0),0
line 4,33,5,33 : dot 7,33 : dot 11,32 : line 10,33,12,33 : line 5,34,12,34
dot 17,32 : dot 19,32 : box 16,33,19,34 : line 21,34,22,34 : dot 25,32
line 24,33,27,33 : line 25,34,28,34
ink rgb(215,0,0),0
line 5,35,12,35 : line 6,36,12,36 : line 14,35,30,35 : line 14,36,32,36
dot 7,37 : dot 4,38 : dot 1,36
ink rgb(255,0,0),0
line 0,38,1,38 : dot 1,37 : line 3,35,4,35 : line 4,36,5,36
line 4,37,6,37 : dot 5,38 : box 9,37,10,38 : dot 11,38 : dot 12,37
line 14,37,33,37 : line 14,38,19,38 : line 21,38,25,38 : line 27,38,31,38
ink rgb(255,255,0),0
dot 0,33 : dot 1,34 : dot 2,35 : dot 2,38 : dot 3,37
ink rgb(128,128,128),0
dot 11,37 : line 12,38,12,39 : dot 14,40 : dot 20,38 : dot 21,39 : dot 22,40
dot 21,41 : dot 26,38 : dot 27,39 : line 28,40,29,40
get image 1005,0,0,36,42
 
 
 
 
set current bitmap 0
return
 
 
TITLE_SCREEN:
hide mouse
set text size 48
set text to italic
set text to bold
sync
for i=1 to 24
  bug(i,3)=3
  bug(i,1)=(i*19)+261
  bug(i,2)=310 : if i>=13 then bug(i,1)=(i-11)*19+260 :  bug(i,2)=326
  bug(i,6)=timer()+50
  if rnd(100)>50
    if rnd(100)>50
      bug(i,4)=20 : ` current pat
      bug(i,7)=20 : ` min pat
      bug(i,8)=22 : ` max pat
      bug(i,9)=8  : ` dir = left
      bug(i,10)=0-(rnd(3)+4) : ` x add
      bug(i,11)=0 : ` y add
    else
      bug(i,4)=23
      bug(i,7)=23
      bug(i,8)=25
      bug(i,9)=4 : ` dir = right
      bug(i,10)=(rnd(3)+4)
      bug(i,11)=0
    endif
  else
    if rnd(100)>50
      bug(i,4)=26 : ` current pat
      bug(i,7)=26 : ` min pat
      bug(i,8)=28 : ` max pat
      bug(i,9)=1  : ` dir = up
      bug(i,10)=0 : ` x add
      bug(i,11)=0-(rnd(3)+4) : ` y add
    else
      bug(i,4)=29 : ` current pat
      bug(i,7)=29 : ` min pat
      bug(i,8)=31 : ` max pat
      bug(i,9)=2  : ` dir = down
      bug(i,10)=0 : ` x add
      bug(i,11)=(rnd(3)+4) : ` y add
    endif
  endif
next i
sprite 8,700,250,50
sync
wait 1500
ink rgb(255,255,255),0
box 0,0,799,599
sprite 8,700,250,51
ink rgb(0,255,0),0
center text 400,300,"GRID BUGS"
` scramble bugs
set text size 26
sync
bug_off=0
repeat
for i=1 to 24
  if bug(i,3)=3
    bug(i,1)=bug(i,1)+bug(i,10) : bug(i,2)=bug(i,2)+bug(i,11)
    sprite i+200,bug(i,1),bug(i,2),bug(i,4)
    if timer()>bug(i,6)
      ` animate
      bug(i,4)=bug(i,4)+1
      if bug(i,4)>bug(i,8) then bug(i,4)=bug(i,7)
      bug(i,6)=timer()+50
    endif
    if bug(i,1)<-30 or bug(i,1)>800 or bug(i,2)<-30 or bug(i,2)>600
      delete sprite i+200
      bug(i,3)=0 : inc bugs_off,1 : if bugs_off>=12 then text 720,550,"by LBFN"
    endif
  endif
next i
  sync
until bugs_off=24
text 50,400,"Press {ENTER} to view game info."
text 50,440,"Press ESC to QUIT."
text 50,480,"Press any other key to PLAY."
delete sprite 8
do
  if returnkey()=1 then gosub GAME_INFO
  if returnkey()=0 and len(inkey$())>0 then exit
  sync
loop
cls
ink rgb(0,91,215),0
box 644,0,799,599
set text font "Arial"
set text to italic
set text to bold
set text size 48
sync
ink rgb(255,255,0),0
text 648,0,"Grid"
text 675,40,"Bugs"
set text to normal
set text size 12
sync
text 740,95,"by LBFN"
set text size 26
sync
ink rgb(0,255,0),0
center text 721,413,"SCORE"
get image 998,650,433,750,473
ink rgb(255,255,255),0
center text 721,470,"MISSED"
get image 997,650,490,750,530
sync
return
 
 
GAME_INFO:
set text size 48
sync
cls
ink rgb(0,128,255),0
center text 400,10,"GAME INFO"
set text size 18
sync
ink rgb(255,255,0),0
text 10,70,"The world's gone BUGGY!"
text 10,95,"Your boss just put in a new grid and what happens?  His neighbor, Mel I. Shuss, gets jealous because your boss's grid"
text 10,120,"is bigger and better than his.  So what does he do?  He sends drone bug dispensers to fill your boss's grid with"
text 10,145,"unsightly bugs. Fortunately for you, your boss owns a pest control business.  The only problem is that he is a"
text 10,170,"cheapskate and uses antiquated equipment.  He's given you a sprayer to use to get rid of the bugs and a concentrated "
text 10,195,"form of Deet that will surely be able to tackle whatever Shuss sends.  Friends of the boss say that Shuss plans on"
text 10,220,"sending 10 waves of bugs to infiltrate your boss' grid.  You HAVE to get them.  You can't have your boss, the"
text 10,245,"exterminator, with bugs crawling around his grid can you?  The boss plans to rate you after every wave of bugs comes."
text 10,270,"Shuss will only send faster, smarter bugs, when you have defeated enough of the current wave of bugs."
text 10,295,"Insiders say that the left and right arrow keys move the sprayer around the boss's grid.  The sprayer is pumped"
text 10,320,"when the {SPACEBAR} is pressed.  You must get the bugs before they climb over the edge of the grid (and then head"
text 10,345,"for the boss's house!)"
text 10,395,"Some hints:  The spray mist will travel quite a ways if you let it.  The bugs Shuss is placing are still in the"
text 10,420,"larvae stage when they arrive - spray them before they quickly grow into full size bugs and scatter off! Follow"
text 10,445,"the bug dispenser as close as you can.  Learn the controls well; they take a little getting used to."
text 10,470,"Good luck, and spray on, bug destroyers, spray on!"
text 10,520,"Press ESC to quit.  Press any other key to play."
return
 
grid_coord:
data 120,169,218,267,316,365,414,463