0001  // Ghostbusters/4a
0002  // 2023 by Stefan Bauch & Helge Spahrbier
0003  //
0004  // see https://github.com/SteveB69/Ghostbusters4a
0005  
0006  call SCRN2
0007  call clear
0008  call screen2(2)
0009  call autochar
0010  
0011  dim GEnc(9),ass(5),bl(30)
0012  
0013  gosub title
0014  
0015  
0016  repeat
0017    gosub init
0018    gosub shop
0019    repeat
0020      gosub map
0021      gosub drive
0022      if pk<9999 then gosub HouseGhost
0023    until pk>=9999
0024    gosub final
0025    display at(16,5):"Play again? (Y/N)"
0026    CALL DISPLY(23,2,"@2023 by S.Bauch & H.Spahrbier")
0027    CALL DISPLY(24,10,"Version 1.0")
0028    CALL PLAY(2432)
0029    repeat
0030      call key(3,k,s)
0031    until s=1
0032    call sound(-100,110,30)
0033  until k=78
0034  end
0035  
0036  title:
0037    CALL VWRITE(2432,BIN$("038C35900F038C359F05038C35900F038C359F05038A2A9007038A2A9F0203832890070383289F02038E23900F038E239F0503801E900F03871C9F0503871C900F03871C9F05038328900F0383289F05" )
0038    CALL VWRITE(2512,BIN$("038328900F0383289F05038C35900F038C359F05038C35900F038C359F05038A2A9007038A2A9F0203832890070383289F02038E23900F038E239F0503801E900F03871C9F0503871C900F03871C9F05" )
0039    CALL VWRITE(2592,BIN$("038328900F0383289F19039FBFDF01000980" )
0040    CALL PLAY(2432)
0041  
0042    call magnify(4)
0043    call char(116,#CHAR3064:4)
0044    call char(120,#CHAR3068:4)
0045    call sprite(#1,116,9, 50,112,#2,120,15, 50,112)
0046    display at(13,9):"Ghostbusters!"
0047    repeat
0048      call key(3,k,s)
0049      call key(1,k,s1)
0050    until s=1 or s1=1
0051    call delsprite(all)
0052    ac=50
0053    call sound(-100,110,30)
0054  return
0055  
0056  init:
0057    pk=0
0058    for i=0 to 29
0059      bl(i)=0
0060    next i
0061   dy1 = 145 :: dx1 = 121
0062   HN=15
0063   GOSUB NextBlinkHouse
0064   HQ=0
0065   pkmm = 5000 + 500*rnd  // Marshmallows first appearance
0066   AC = 50  // Account: $ / 50 (=5.000$)
0067   for i=1 to 5 :: ASS(i)=0 :: next i
0068   //ASS(5)=5
0069   CALL CHAR2(64,"3C4299A1A199423C")
0070  return
0071  
0072  // *** SHOP ***
0073  shop:
0074    call clear
0075    call magnify(3)
0076    display at(10,1):"Do you have an account?"
0077    accept at(10,26) Validate("YN"):a$
0078    if a$="Y" then begin
0079      display at(13,1):"Account number:"
0080      accept at(13,16) Validate("0123456789"):a$
0081      gosub decode
0082      if ac=0 then display at(16,1):"Invalid account number.":: ac=50
0083      display at(18,1):"Your balance: $"&str$(ac)&"00"
0084    end else display at(18,1):"Your credit is $5000"
0085    call waitkey
0086    call clear
0087    display at(1,10):"Equipment"
0088    display at( 5,2):"PK Energy Detector $800" // 1
0089    display at( 7,2):"Bait               $400" // 2
0090    display at( 9,2):"Ghost Vacuum       $500" // 3
0091    display at(11,2):"Image Intensifier  $800" // 4
0092    display at(13,2):"Traps              $600 x 0" // 5
0093    display at(15,2):"Done Shopping"
0094    display at(20,2):"Credit           $  "&str$(AC)&"00"
0095    call char(116,#CHAR3112:4)
0096    call sprite(#1,116,15,33,4)
0097    call color2(18,4,2,17,2,2)
0098    GY=33
0099    repeat
0100      call key(1,k,s)
0101    until s=0
0102    repeat
0103      call joyst(1,x,y)::call key(1,k,s)
0104      gy=gy-y*4-16*(k=0)+16*(k=5)
0105      if gy>113 or gy<33 then gy=33
0106      if s<>0 or y<>0 then call delay(200)
0107      call locate(#1,gy,4)
0108      gx=(gy-17)/16
0109      if k=18 and gy<97 then ass(gx)=-(ass(gx)=0) :: call hchar(3+gx*2,30,167+ass(gx))
0110      if k=18 and gy=97 then ass(gx)=-(ass(gx)+1)*(ass(gx)<9) :: call hchar(3+gx*2,30,48+ass(gx))
0111      E = AC - ass(1)*8 - ass(2)*4 - ass(3)*5 - ass(4)*8 - ass(5)*6
0112      display at(20,22):str$(E)&"00"
0113      if k=18 and gy=113 and E<0 then begin
0114        display at(17,4):"Insufficient funding!"
0115        call sound(600,110,0,220,4,440,8)
0116        call delay(2000)
0117        call hchar(17,1,32,32)
0118        k=0
0119      end
0120    until k=18 and gy=113
0121    AC=E :: TR=ass(5)
0122    call delsprite(#1)
0123  return
0124  
0125  
0126  // *** MAP ***
0127  
0128  map:
0129    call clear
0130    call magnify(3)
0131    call char(116,#CHAR3064:4)
0132    call char(120,#CHAR3068:4)
0133    call char(124,#CHAR3072:8)
0134    call char(132,#CHAR3100:2) // MM oben
0135    call char(134,#CHAR3104:2)
0136    call char(136,#CHAR3102:2) // MM unten 102,106
0137    call char(138,#CHAR3106:2)
0138  
0139    call color2(13,2,2,14,2,2,15,2,2,16,2,2)
0140    call color2(17,2,2,31,2,2)
0141    call hchar(1,1,16,768)
0142    for i=0 to 29
0143      if BL(i)=0 then call drawhouse(i,128) else call drawhouse(i,144)
0144    next i
0145    for i=0 to 9 :: GEnc(i)=9999 :: next i
0146    for i=0 to 4 :: call hchar(21,11+i,160+i,1)::next i
0147    call hchar(1,1,32,64) :: call hchar(22,1,32,96)
0148    call hchar(2,19,137,1) :: call hchar(2,20,138,1) :: call hchar(2,21,139,1)
0149  
0150    call magnify(3)
0151    call sprite(#1,116,9,145,121,#2,120,15,145,121,#3,88,16,226,1,0,50)
0152    call color2(13,2,13,14,2,13,15,2,10,16,2,10)
0153    call color2(17,2,12,31,16,2)
0154    call pkstart(pk)
0155    Ghost=16 :: GY = 0 :: GhostPK=100+100*rnd
0156    dr=0 :: GhostSpeed=10
0157    x1=dx1 :: y1=dy1
0158    if hq=1 then display at(23,11):"Go to HQ!"
0159    repeat
0160      call position(#3,i,j)
0161      if j<128 then call color2(15,2,10,16,2,10) else call color2(15,2,13,16,2,13)
0162      call mod(x1,28,mx) :: call mod(y1,20,my)
0163      if mx=9 and my=5 then call joyst(1,x,y) :: call key(1,k,s) else k=0
0164      if x1=9   and x=-4 then x=0
0165      if x1=233 and x=4  then x=0
0166      if y1=145 and y=-4 and x1<>93 then y=0
0167      if y1=25  and y=4  then y=0
0168      if x<>0 then y=0
0169      call gchar(y1/8+2-(y/2),max(x1/8+1+(x/2),1),e)
0170      if e=16 then x1=x1+x :: y1=y1-y ELSE gosub CalcHouse
0171      if e=16 and x+y<>0 then dr=dr+1
0172      call pkplus(pk,ac)
0173      if pk>GhostPK and GY=0 and ghost<26 then gosub startghost
0174      if GY>0 then gosub MoveGhost
0175      if pk>pkmm then gosub Marshmallow
0176      if pk>=hp then gosub StartBlink
0177      if ass(4)=1 and abs(y1-(hny*8-7))<24 and abs(x1-(hnx*8-7))<40 then call hchar(hny,hnx,140) else call hchar(hny,hnx,136)
0178      call locate(#1,y1,x1,#2,y1,x1)
0179    until (house>0 and k=18 and HQ=0) OR (house=26 and k=18 and HQ=1) or pk>10000
0180    call delsprite(all)
0181    dx1=x1 :: dy1=y1
0182  return
0183  
0184  CalcHouse:
0185    house=0
0186    if y= 4 then house=((y1-25)/40)*6 + (x1+19)/56 // + 1
0187    if y=-4 then house=((y1+15)/40)*6 + (x1+19)/56 // + 1
0188    if x= 4 then house=((y1-5)/40)*6  + (x1-9)/56 + 1
0189    if x=-4 then house=((y1-5)/40)*6  + (x1-9)/56 // + 1
0190  RETURN
0191  
0192  startghost:
0193    gz = int(rnd*4)
0194    case gz of
0195      0 : begin
0196            gx=1 :: gy=120 + RND*40
0197          end
0198      1 : begin
0199            gx=RND*40+1 :: gy=160
0200          end
0201      2 : begin
0202            gx=240-RND*40 :: gy=160
0203          end
0204      3 : begin
0205            gx=240 :: gy= 120 + RND*40
0206          end
0207    endcase
0208    call sprite(#ghost,124-4*(gx>50),15,gy,gx)
0209    GP=0
0210  return
0211  
0212  MoveGhost:
0213    GhostSpeed=GhostSpeed-1 :: if GhostSpeed<1 then GP=GP+1 :: GhostSpeed=5-int(pk/2000)
0214    call locate(#ghost,GY+GP*(9-GY)/160,GX+GP*(160-GX)/160)
0215    if GP=160 then  call delsprite(#ghost):: GY=0 :: pk=pk+100
0216    call coinc(#ghost,#1,10,GC)
0217    if GC then GY=0 :: GEnc(ghost-16)=dr :: Ghost=ghost+1 :: GhostPK=pk+10+40*rnd
0218  return
0219  
0220  Marshmallow:
0221    i=1 :: e=0
0222    dx1=56*int(rnd*4)+38 :: dy1=int(rnd*3)+1
0223    call sprite(#5,132,15,1,dx1,#6,136,15,17,dx1)
0224    CALL DELAY(600)
0225    repeat
0226      call locate(#5,i*dy1,dx1,#6,i*dy1+16,dx1)
0227      call key(3,k,s)
0228      if k=66 and ass(2)=1 then e=-1 :: display at(23,9):"Bait applied!"
0229      i=i+1
0230      call delay(30)
0231      call pkplus(pk,ac)
0232    until i>40
0233    if e then ac=ac+20 :: goto MarshmallowEnd
0234    display at(23,8):"Building destroyed!"
0235    for i=1 to 10
0236      call char(136,#CHAR3108:4)
0237      call delay(250)
0238      call char(136,#CHAR3102:2,138,#CHAR3106:2)
0239      call delay(250)
0240      call pkplus(pk,ac)
0241    next i
0242    ac=max(0,ac-40)
0243    MarshmallowEnd:
0244    pkmm=pk+500+rnd*1000
0245    call delsprite(#5,#6)
0246    CALL HCHAR(23,10,32,20)
0247  return
0248  
0249  StartBlink:
0250    call drawhouse(HN,144)
0251    gosub NextBlinkHouse
0252  return
0253  
0254  NextBlinkHouse:
0255    bl(hn)=1 :: i=0
0256    ass(4)=abs(ass(4))
0257    while bl(hn)=1 and i<30
0258      HN=7+int(RND*3)*6+INT(RND*4)
0259      i=i+1
0260    wend
0261    if bl(hn)=1 then ass(4)=-ass(4)
0262    HNX=(hn-6*int(hn/6))*7-1
0263    HNY=int(hn/6)*5+2
0264    HP=PK+100+int(rnd*200)
0265  RETURN
0266  
0267  
0268  // *** DRIVE ***
0269  
0270  drive:
0271    call clear
0272    call magnify(4)
0273    call char( 92,#CHAR3032:2)
0274    call char( 94,#CHAR3038:2)
0275    call char( 96,#CHAR3044:2)
0276    call char( 98,#CHAR3050:2)
0277  
0278    call char(100,#CHAR3034:2)
0279    call char(102,#CHAR3040:2)
0280    call char(104,#CHAR3046:2)
0281    call char(106,#CHAR3052:2)
0282  
0283    call char(108,#CHAR3036:2)
0284    call char(110,#CHAR3042:2)
0285    call char(112,#CHAR3048:2)
0286    call char(114,#CHAR3054:2)
0287  
0288    call sprite(#3, 92,15, 50,50,#4, 96,15, 50,82)
0289    call sprite(#5,100,15, 82,50,#6,104,15, 82,82)
0290    call sprite(#7,108,15,114,50,#8,112,15,114,82)
0291  
0292    call char(116,#CHAR3056:4)
0293    call char(120,#CHAR3060:4)
0294    call char(124,#CHAR3076:8)
0295    call sprite( #9,116,10,143,50,#10,116,10,143, 96)
0296    call sprite(#11,120,16, 49,50,#12,120,16, 49,100)
0297    call sprite(#1,124,16,194,1,#2,128,3, 53,66)
0298    if ass(3)=0 then call color(#2,1)
0299  
0300    call COLOR2(31,12,2)
0301  
0302    ghost=0
0303    drc=0
0304    x1=50
0305    gy=1
0306    gz=15
0307    dr2=25
0308    verz=20
0309  
0310    call pkstart(pk)
0311    call sprite(#1,124,16,194,1,0,0)
0312  
0313    repeat
0314      call joyst(1,x,y)
0315      if drc<dr then x1=x1+x/2 else x1=x1+2 :: if x1>180 then verz=verz+30
0316      if x1<1   then x1=2
0317      if x1>190 then x1=190
0318      x2=x1+32
0319      call locate(#3,50,x1,#4,50,x2,#5,82,x1,#6,82,x2,#7,114,x1,#8,114,x2)
0320      call locate(#9,143,x1,#10,143,x2+14,#11,49,x1,#12,49,x2+18,#2,53,x1+16)
0321      if gy<14 then le=min(11,gy) else le=24-gy
0322      call vchar(gy,9,16,le)
0323      if x1<62  and x1>10 then call vchar(8, 9,32,11)
0324      call vchar(gy,20,16,le)
0325      if x1<150 and x1>98 then call vchar(8,20,32,11)
0326      call vchar(gz,9,32,3) :: call vchar(gz,20,32,3)
0327      if gy>23 then gy=1 else gy=gy+1
0328      if gz>23 then gz=1 else gz=gz+1
0329  
0330      if drc=GEnc(ghost) then call sprite(#1,124,16,220,78+100*rnd,4,0)::ghost=ghost+1
0331      call key(1,k,s)
0332      call distance(#1,#2,GC) :: call position(#1,my,mx)
0333      if k=18 and GC<400 and ass(3)=1 then begin
0334        GP=GP+1
0335        if int(RND*2)=1 then gosub Ghostleft else gosub Ghostright
0336        if my>50 then call locate(#1,my-2,mx)
0337        call sound(-500,-6,8)
0338        if GP=15 then call sprite(#1,124,16,194,1,0,0)
0339      end else GP=0
0340      if my>180 and my<194 then pk=pk+100 :: call sprite(#1,124,16,194,1,0,0)
0341      call delay(verz)
0342      dr2=dr2-1 :: call pkplus(pk,ac)
0343      if dr2=0 then dr2=3 :: if my=0 then drc=drc+1
0344    until drc>dr and x1>=190 and verz>400
0345    call delay(1000)
0346    call delsprite(all)
0347  return
0348  
0349  Ghostleft:
0350    call char(124,#CHAR3076:4)
0351  return
0352  
0353  Ghostright:
0354    call char(124,#CHAR3072:4)
0355  return
0356  
0357  // *** HOUSE GHOST ***
0358  
0359  HouseGhost:
0360    if pk>10000 then return
0361    call clear
0362    call magnify(4)
0363  
0364    call char( 92,#CHAR3000:8)
0365    call char(100,#CHAR3008:8)
0366    call char(108,#CHAR3016:8)
0367    call char(116,#CHAR3024:8)
0368  
0369    call COLOR2(29,5,15) // bricks
0370    call COLOR2(30,5,15) // bricks
0371    call COLOR2(31,12,2) // Yellow Beam
0372  
0373    for i=4 to 15
0374      call hchar(i,5,11,24)
0375    next i
0376    call hchar(16,1,10,32)
0377    for i=5 to 13 step 4
0378      for j=6 to 27 step 4
0379        call hchar(i,j,6,1)
0380        call hchar(i+1,j,7,1)
0381        call hchar(i,j+1,8,1)
0382        call hchar(i+1,j+1,9,1)
0383      next j
0384    next i
0385  
0386    call pkstart(pk)
0387    if house=26 then gosub VisitHQ :: call delsprite(all) :: Return
0388  
0389    call sprite(#10,100,9,132,200)  // Buster 1
0390    call sprite(#13,112,11,140,200) // Trap
0391  
0392  
0393  
0394    // speech: He slimed me!
0395    a$=bin$("0498394c80e3752ab85705acfaae80955f1835538353ad25c0b7610cf8358301bfa513e0af7402fc9d4e805fda10705531cb33f37e4b75aac8dceb3cd49b3489ce16cb6e8ad85335264b288bc956f776ad1cda32d2938d6ae8f0084d3bea1133c2d56dab7bca")
0396    b$=bin$("34956da5ed294254b785b6250e4ddf22f062a93a3a31a9a3f4d8543b046cd22d2b6c23b031d3887083c042d56a3a2923472a668fac0ced2d5cc5fa88718c080eed2bc6f17248bc0b01c66e47c02eee08d8a91c01cb972360bb72046c9f8e80edca10b06c28")
0397    sp$=chr$(96) & chr$(0) & chr$(LEN(a$)+LEN(b$)) & a$ & b$
0398  
0399    state=1
0400    x=200
0401    gx=70 :: gxd=0
0402    gy=50 :: gyd=0
0403  
0404    if pk>=hp then bl(hn)=1 :: gosub NextBlinkHouse :: HP=PK+100+int(rnd*200)
0405  
0406    if bl(house)=0 then gosub NoGhostHere :: call delsprite(all) :: Return
0407  
0408    call sprite(#12,108,15-2*abs(ass(4)),50,150)  // Ghost Color 13 / 15
0409    repeat
0410      call key(1,k,s)
0411      if s=-1 then k=0
0412      call joyst(1,jx,jy)
0413      on state gosub state_buster1bait,state_buster1,state_buster2,state_beam,state_trap
0414      gxd=gxd + (rnd*5)-2
0415      gyd=gyd + (rnd*5)-2
0416      if abs(gxd)>10 then gxd=gxd/2
0417      if abs(gyd)>10 then gyd=gyd/2
0418      if gx<30  then gxd=rnd*5
0419      if gx>200 then gxd=-(rnd*5)
0420      if gy<30  then gyd=rnd*5
0421      if gy>70  then gyd=-(rnd*5)
0422  
0423      if state>3 then begin
0424        dx = gx - (x1+28 + (135-gy)/2)
0425        if dx<-5 and dx>-20 then gxd=2 :: gyd = rnd*3
0426        if dx<-20 and dx>-40 then gxd=-2
0427  
0428        dx = gx - (x2 - (135-gy)/2)
0429        if dx<5 and dx>-20 then gxd=-2 :: gyd = -(rnd*3)
0430        if dx>5 and dx<15 then gxd=2
0431        if state<5 and x2-x1<125 then state=6
0432      end
0433      if state<6 then gy=gy+gyd :: gx=gx+gxd :: call locate(#12,gy,gx)
0434  
0435      call pkplus(pk,ac)
0436      call delay(40)
0437    until state>5
0438    if state=6 then gosub StreamsCrossed
0439    call delsprite(all)
0440  return
0441  
0442  VisitHQ:
0443    call COLOR2(29,7,11) // bricks
0444    call COLOR2(30,7,11) // bricks  132
0445    call sprite(#10,104,9,110,120)
0446    call sprite(#11,104,9,100,100)
0447    call delay(500)
0448    for i=1 to 120 step 4
0449      call locate(#10,min(132,110+i/3),120+i)
0450      call locate(#11,min(132,100+i/3),100+i)
0451      call delay(80)
0452      call pkplus(pk,ac)
0453    next i
0454    hq=0 :: TR=ass(5)
0455  return
0456  
0457  state_buster1bait:
0458    x=max(x+jx,4)
0459    if jx<>0 then call pattern(#10,100-4*(jx=4))
0460    call locate(#10,132,x)
0461    call locate(#13,140,x)
0462    if k<>18 then return
0463    trx = int(x/8)*8+3
0464    call locate(#13,153,trx)
0465    state = state + 1
0466  return
0467  
0468  state_buster1:
0469    x=max(x+jx,4)
0470    if jx<>0 then call pattern(#10,100-4*(jx=4))
0471    call locate(#10,132,x)
0472    if k<>18 then return
0473    call pattern(#10,104)
0474    call sprite(#11,100,9,132,200)
0475    x1=x
0476    x=200
0477    state = state + 1
0478  return
0479  
0480  state_buster2:
0481    x=x+jx
0482    if jx<>0 then call pattern(#11,100-4*(jx=4))
0483    call locate(#11,132,x)
0484    if k<>18 then return
0485    call pattern(#11,100)
0486    x2 = x
0487    call sprite(#1,94,4,40,x2-60)
0488    call sprite(#2,94,4,72,x2-44)
0489    call sprite(#3,94,4,104,x2-28)
0490  
0491    call sprite(#4,98,4,40,x1+60)
0492    call sprite(#5,98,4,72,x1+44)
0493    call sprite(#6,98,4,104,x1+28)
0494  
0495    state = state + 1
0496  return
0497  
0498  state_beam:
0499    x1=x1-4*(jx=4)
0500    x2=x2+4*(jx=-4)
0501    if jx=4  then call locate(#10,132,x1,#4,40,x1+60,#5,72,x1+44,#6,104,x1+28)
0502    if jx=-4 then call locate(#11,132,x2,#1,40,x2-60,#2,72,x2-44,#3,104,x2-28)
0503    if k<>18 then return
0504    state=5
0505    try=123
0506    call sprite(#14,120,12,123,trx-6)
0507  return
0508  
0509  StreamsCrossed:
0510    call delsprite(#1,#2,#3,#4,#5,#6)
0511    call pattern(#10,116,#11,116)
0512    call motion(#12,-5,5)
0513    call disply(1,5,"You crossed the streams!")
0514    repeat
0515      call position(#12,gy,gx)
0516      call pkplus(pk,ac)
0517    until gy<5 or gx>250
0518    call delsprite(all)
0519    HQ=1
0520  return
0521  
0522  State_Trap:
0523    if try >20 then try=try-2 else state=8
0524    call locate(#14,try,trx-6)
0525    if try-int(try/8)*8=1 then begin
0526      call gchar(try/8+4,trx/8+2,c)
0527      call hchar(try/8+4,trx/8+2,16,1)
0528      bg$=bg$&chr$(c)
0529    end
0530    call distance(#12,#14,e)
0531    if e<800 or state=8 then begin
0532      for try=try to 123 step 2
0533        call locate(#14,try,trx-6)
0534        if state=8 then call locate(#12,gy-8+rnd*4,gx-8+rnd*4) else
0535                        call locate(#12,try,trx-9+rnd*6)
0536        if try-int(try/8)*8=1 then begin
0537          call hchar(try/8+4,trx/8+2,asc(seg$(bg$,len(bg$),1)))
0538          bg$=seg$(bg$,1,len(bg$)-1)
0539        end
0540        call delay(40)
0541        call pkplus(pk,ac)
0542      next try
0543      call delsprite(#12,#14,#1,#2,#3,#4,#5,#6)
0544      if state=8 then begin
0545        for i=1 to 132-gy
0546          call locate(#12,gy+i,gx+i*(x2-gx)/(132-gy))
0547          call pkplus(pk,ac)
0548          call delay(40)
0549        next i
0550        call SAY(,sp$)
0551        call color(#11,3)
0552        call motion(#12,-5,5)
0553        repeat
0554          call position(#12,gy,gx)
0555          call pkplus(pk,ac)
0556        until gy<5 or gx>250
0557        pk=pk+300 :: HQ=1
0558        call delsprite(#12)
0559      end else call color(#13,3) :: ac=ac+4
0560      while x1<250
0561        x1=x1+4
0562        if x1=trx-3 then call locate(#13,140,trx) :: trx=trx+4
0563        call locate(#10,132,x1)
0564        if x1=x2-40 then call pattern(#11,104)
0565        if x2<x1-30 then call locate(#11,132,x2) :: x2=x2+4
0566        call pkplus(pk,ac)
0567        call delay(30)
0568      endwhile
0569      if HQ=0 then bl(house)=0 :: TR=TR-1 :: IF TR=0 then HQ=1
0570      call delsprite(#10,#11,#13)
0571      state=7
0572    end
0573  return
0574  
0575  NoGhostHere:
0576    call sprite(#11,100,9,132,230)  // Buster 2
0577    for i=1 to 70 step 4
0578      call locate(#10,132,200-i,#13,140,200-i,#11,132,230-i)
0579      call delay(80) :: call pkplus(pk,ac)
0580    next i
0581    call pattern(#10,104,#11,104)
0582    call delay(1000)
0583    for i=70 to 0 step -4
0584      call locate(#10,132,200-i,#13,140,200-i,#11,132,230-i)
0585      call delay(80) :: call pkplus(pk,ac)
0586    next i
0587  return
0588  
0589  
0590  final:
0591    call magnify(4)
0592    call clear
0593    call color2(18,4,13)
0594    call char(112,"80",113,"",114,"",115,"")
0595    call char(116,#CHAR3084:8)
0596    call char(124,#CHAR3092:8)
0597    call char2(176,#CHAR3116:6)
0598    call color2(19,5,1,20,15,1,29,2,14)
0599    call sprite(#1,116,16, 100,40,#2,120,16,132,40,#3,128,13,153,40)
0600    call sprite(#4,112,6,140,205)
0601    call hchar(20,1,169,32) :: call hchar(21,1,170,32)
0602    call hchar(18,26,180,1)
0603    call hchar(19,26,181,1)
0604    call disply(18,30,chr$(184)&chr$(186)&chr$(188))
0605    call disply(19,30,chr$(185)&chr$(187)&chr$(189))
0606    call hchar(18,28,182,2)
0607    call hchar(19,28,183,2)
0608    call disply(1,1,chr$(2)&chr$(3),32,10)
0609    call disply(1,2,chr$(4)&chr$(5),32,10)
0610  
0611    y1 = 0 :: x1 = 40 :: e = -50 :: gx=1
0612    x2 = 52 :: s1=0 :: J=-1 :: JY = 3
0613    repeat
0614      y1 = y1 + e :: e = e+1 :: x1=x1+gx
0615      call locate(#1,y1/75+100,x1,#2,y1/75+134,x1,#3,154,x1)
0616      if e=51 then e=-50 :: gx=-gx
0617      if e=0 then call pattern(#2,122+gx*2)
0618      call joyst(1,x,y)
0619      j=j+1
0620      if x<>0 and J>4 then begin
0621         s1=(s1=0) :: x2=min(x2+x/4,58)
0622         if x2<6 then gosub mmnext
0623         call hchar(18,x2/2+(x=4),32,2) :: call hchar(19,x2/2+(x=4),32,2)
0624         if s1=0 then call hchar(18,x2/2,180,1) :: call hchar(19,x2/2,181,1)
0625         if s1 then call hchar(18,x2/2,176,1) :: call hchar(19,x2/2,177,1)::call hchar(18,x2/2+1,178,1) :: call hchar(19,x2/2+1,179,1)
0626         call locate(#4,140,x2*4-3)
0627         j=0
0628      end
0629      call coinc(all,k)
0630      if k<>0 then gosub mmsmash
0631      call key(1,k,s)
0632    until s<>0 or jy<1
0633    call delsprite(all)
0634    call clear
0635    if jy<0 then return
0636    call disply(5,1,"Congratulations!")
0637    call disply(7,1,"You saved the city.")
0638    sp$=str$(ac) :: s=0
0639    call disply(10,1,"Your balance: "&sp$&"00$")
0640    if ac>50 then begin
0641      gosub encode
0642      call disply(12,1,"Your new account number:")
0643      call disply(14,1,A$)
0644    end
0645  return
0646  
0647  mmnext:
0648    call vchar(18,3,32,2)
0649    jy = jy - 1
0650    s1=0 :: X2=58-jy*2
0651  return
0652  
0653  mmsmash:
0654    call sound(-300,440,0)
0655    call hchar(18,x2/2-1,32,3) :: call hchar(19,x2/2-1,32,3)
0656    call delsprite(#4)
0657    call char2(176,#CHAR3025,177,#CHAR3027)
0658    call disply(19,x2/2,chr$(176)&chr$(177))
0659    call disply(7,12,"Game Over!")
0660    repeat
0661      call key(1,k,s)
0662    until s=1
0663    jy=-1
0664  return
0665  
0666  encode:
0667    sp$=str$(ac) :: s=0
0668    sp$=rpt$("0",5-len(sp$))&SP$
0669    a$=chr$(int(rnd*10)+48)
0670    for i=1 to len(sp$)
0671      k=asc(seg$(sp$,i,1))+2+i
0672      if k>57 then k=k-10
0673      a$=a$&chr$(k)
0674      s=s+k-48
0675      a$=a$&chr$(int(rnd*10+48))
0676    next i
0677    a$=a$&chr$(48+s-int(s/10)*10)
0678  return
0679  
0680  decode:
0681    sp$="" :: s=0
0682    for i=2 to len(a$)-1 step 2
0683      k=asc(seg$(a$,i,1))
0684      s=s+k-48
0685      k=k-2-(i/2)
0686      if k<48 then k=k+10
0687      sp$=sp$&chr$(k)
0688    next i
0689    if chr$(48+s-int(s/10)*10)=seg$(a$,len(a$),1) then ac=val(sp$) else ac=0
0690  return
0691  
0692  
0693  sub drawhouse(h,b)
0694    r=int(h/6) :: c=h-6*r
0695    if c>0 then call hchar(r*5+1,c*7-3,b) :: call hchar(r*5+2,c*7-3,b+7) :: call hchar(r*5+3,c*7-3,b+6)
0696    if c>0 and c<5 then call hchar(r*5+1,c*7-2,b+1,3) :: call hchar(r*5+2,c*7-2,b+8,3) :: call hchar(r*5+3,c*7-2,b+5,3)
0697    if c<5 then call hchar(r*5+1,c*7+1,b+2) :: call hchar(r*5+2,c*7+1,b+3) :: call hchar(r*5+3,c*7+1,b+4)
0698  subend
0699  
0700  
0701  sub pkstart(pk)
0702    call sprite(#15,64,1,170,1,0,1+PK/2000)
0703    call disply(23,1,"PK          ")
0704    call disply(24,1,"$           ")
0705  subend
0706  
0707  
0708  sub pkplus(pk,ac)
0709    call position(#15,y,x)
0710    if x=1 then subexit
0711    pk = pk + x - 1
0712    call locate(#15,170,1)
0713    display at(23,1):PK;
0714    display at(24,1):str$(AC)&"00";
0715  subend
0716  
0717  
0718  
0719  
0720  
0721  
0722