Mysoft

Untitled

May 13th, 2022 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. width 40,25
  2.  
  3. ' # são paredes
  4. ' - também são paredes mas que os fantasmas podem passar
  5. ' . são pontos comestiveis
  6. ' * são pontos comestiveis de invencibilidade
  7. ' @ é o ponto inicial do jogador
  8. ' x é o ponto inicial dos fantasmas
  9.  
  10. dim as string sMap(25),sM(25)
  11. sM( 1)="7888888888w8888888889"
  12. sM( 2)="4.........5.........6"
  13. sM( 3)="4.789.789.5.789.789.6"
  14. sM( 4)="4*5 5.5 5.5.5 5.5 5*6"
  15. sM( 5)="4.123.123.s.123.123.6"
  16. sM( 6)="4...................6"
  17. sM( 7)="4.789.w.78889.w.789.6"
  18. sM( 8)="4.123.5.12w23.5.123.6"
  19. sM( 9)="4.....5...5...5.....6"
  20. sM(10)="18889.a88.s.88d.78883"
  21. sM(11)="    5.5.......5.5    "
  22. sM(12)="22223.s.7---9.s.12222"
  23. sM(13)="     ...5 x 5...     "
  24. sM(14)="88889.w.18883.w.78888"
  25. sM(15)="    5.5.......5.5    "
  26. sM(16)="72223.s.22w22.s.12229"
  27. sM(17)="4.........5.........6"
  28. sM(18)="4.889.888.5.888.788.6"
  29. sM(19)="4*..5.....@.....5..*6"
  30. sM(20)="189.5.w.78889.w.5.783"
  31. sM(21)="723.s.5.12w23.5.s.129"
  32. sM(22)="4.....5...5...5.....6"
  33. sM(23)="4.8888s88.s.88s8888.6"
  34. sM(24)="4...................6"
  35. sM(25)="122222222222222222223"
  36.  
  37. dim as integer iX,iY,iC,M,N,iOff1,iOff2
  38. dim as integer iPlayerX,iPlayerY,iStartX,iStartY
  39. dim as integer iSpawnX,iSpawnY,iRand,iLevel=1,iPlayer=1
  40. dim as integer iScore=0,iScore2,iLives=3,iAuto=4
  41. dim as integer iErase,iUpdate=1
  42. dim as integer iGhostX(3),iGhostY(3),iGhostSX(3),iGhostSY(3)
  43. dim as integer iGhostMov(3),iGhostWait(3),iGhostSlow(3)
  44. 'dim as integer iGhostColor(3)={2,3,4,5}
  45.  
  46. do
  47.  
  48.   dim as integer iDots,iSuper,iDead=1
  49.   locate 1,1
  50.  
  51.   'exibe labirinto inicial conforme os dados no mapa
  52.   'salvando os pontos de teleporte, e os pontos iniciais do jogador/fantasmas
  53.   for iY=1 to 25
  54.     sMap(iY)=sM(iY)
  55.     for iX=1 to 21
  56.       iC = asc( sMap(iY) , iX )
  57.       'if iC = asc("#") then color 9 : print "#"; : mid(sMap(iY),iX,1) = "#"
  58.      
  59.       if iC = asc("1") then color 9 : print chr(200); : mid(sMap(iY),iX,1) = "y"
  60.       if iC = asc("2") then color 9 : print chr(205); : mid(sMap(iY),iX,1) = "y"
  61.       if iC = asc("3") then color 9 : print chr(188); : mid(sMap(iY),iX,1) = "y"
  62.       if iC = asc("4") then color 9 : print chr(186); : mid(sMap(iY),iX,1) = "y"
  63.       if iC = asc("5") then color 9 : print chr(186); : mid(sMap(iY),iX,1) = "y"
  64.       if iC = asc("6") then color 9 : print chr(186); : mid(sMap(iY),iX,1) = "y"
  65.       if iC = asc("7") then color 9 : print chr(201); : mid(sMap(iY),iX,1) = "y"
  66.       if iC = asc("8") then color 9 : print chr(205); : mid(sMap(iY),iX,1) = "y"
  67.       if iC = asc("9") then color 9 : print chr(187); : mid(sMap(iY),iX,1) = "y"    
  68.       if iC = asc("w") then color 9 : print chr(203); : mid(sMap(iY),iX,1) = "y"    
  69.       if iC = asc("s") then color 9 : print chr(202); : mid(sMap(iY),iX,1) = "y"    
  70.       if iC = asc("a") then color 9 : print chr(204); : mid(sMap(iY),iX,1) = "y"    
  71.       if iC = asc("d") then color 9 : print chr(185); : mid(sMap(iY),iX,1) = "y"    
  72.      
  73.       if iC = asc("-") then color 9 : print "-"; : mid(sMap(iY),iX,1) = "z"
  74.       if iC = asc(" ") then print " ";
  75.       if iC = asc("x") then print " "; : iSpawnX=iX : iSpawnY=iY
  76.       if iC = asc(".") then color 6 : print chr(250); : iDots += 1
  77.       if iC = asc("*") then color 14 : print chr(254); : iDots += 1
  78.       if iC = asc("@") then print " "; : iStartX=iX : iStartY=iY
  79.     next iX
  80.     if iY <> 25 then print 'avança para a próxima linha (menos na última)
  81.   next iY
  82.  
  83.   'posição inicial dos fantasmas
  84.   'e tempo entre cada movimentação
  85.   for N=0 to 3
  86.     iGhostX(N) = iSpawnX : iGhostY(N) = iSpawnY
  87.     iGhostSX(N) = 1 : iGhostSY(N) = 0
  88.     iGhostWait(N) = N*128+N+32 : iGhostSlow(N) = 0
  89.   next N
  90.   iPlayerX = iStartX : iPlayerY = iStartY
  91.  
  92.   dim as string sKey , sKey1 , sKey2
  93.   do
  94.    
  95.     'ajusta o nosso "aleatório"
  96.     iRand += 1
  97.     while iRand > 3
  98.       iRand -= 4
  99.     wend
  100.    
  101.     'movimenta os fantasmas
  102.     for N = 0 to 3
  103.      
  104.       iX = iGhostX(N) : iY = iGhostY(N)
  105.      
  106.       'apaga fantasma (coloca devolta o que tinha na posição dele)
  107.       locate iY,iX : iC = asc( sMap(iY) , iX )    
  108.       if iC = asc(".") then color 6 : print chr(250);
  109.       if iC = asc("z") then color 9 : print "-";
  110.       if iC = asc("*") then color 14 : print chr(254);    
  111.       if iC <> asc(".") and iC <> asc("*") and iC <> asc("z") then print " ";
  112.      
  113.       'se jogador tocou fantasma então um deles morre
  114.       if iX=iPlayerX and iY=iPlayerY then
  115.         if iGhostSlow(N)>0 then 'fantasma morre
  116.           iScore += 150
  117.           for M = 0 to 3
  118.             if iGhostWait(M) > 8 then iScore += 50
  119.           next M        
  120.           iGhostX(N) = iSpawnX : iGhostY(N) = iSpawnY
  121.           iGhostSX(N) = 1 : iGhostSY(N) = 0
  122.           iGhostWait(N) = 128+N : iGhostSlow(N) = 0
  123.         else 'jogador morre
  124.           iDead = 1 : sKey1 = "" : sKey2 = ""
  125.         end if
  126.       end if      
  127.      
  128.       if iGhostWait(N)>0 then      
  129.        
  130.         'reduz o contador e passa ao próximo fantasma até que ele zere
  131.         if iGhostWait(N) < 9 or iGhostSlow(N)=0 then iGhostWait(N) -= 1
  132.         if iGhostWait(N) < 1 then
  133.           'fantasmas metade da velocidade enquanto jogador esta super
  134.           if iGhostSlow(N)>0 then iGhostWait(N) = 8 else iGhostWait(N) = 4
  135.           iC = 0
  136.          
  137.           'que direções o fantasma pode ir?
  138.           '1) não pode bater nas paredes
  139.           '2) não pode voltar aonde veio
  140.           '3) não pode bater em outro fantasma
  141.           dim as integer iUp=0,iDn=0,iLt=0,iRt=0
  142.          
  143.           'previne o fantasma de mover um em cima do outro
  144.           for M = 0 to 3
  145.             if M = N then continue for 'ignora o próprio
  146.             if (iX+1)=iGhostX(M) and (iY  )=iGhostY(M) then iRt=-1
  147.             if (iX-1)=iGhostX(M) and (iY  )=iGhostY(M) then iLt=-1
  148.             if (iX  )=iGhostX(M) and (iY-1)=iGhostY(M) then iUp=-1
  149.             if (iX  )=iGhostX(M) and (iY+1)=iGhostY(M) then iDn=-1
  150.           next M
  151.          
  152.           'se não bater na parede e não estiver voltando então adiciona direção valida
  153.           if iRt=0 and asc( sMap( iY   ) , iX+1 ) <  asc("y") and iX < 21 then
  154.             if iGhostSX(N)<>-1 or iGhostSY(N)<> 0 then iC += 1 : iRt = 1 : iRand += 1 else iRt = -2
  155.           end if
  156.           if iLt=0 and asc( sMap( iY   ) , iX-1 ) <  asc("y") and iX > 1 then
  157.             if iGhostSX(N)<> 1 or iGhostSY(N)<> 0 then iC += 2 : iLt = 1 : iRand += 1 else iLt = -2
  158.           end if
  159.           if iUp=0 and asc( sMap( iY-1 ) , iX   ) <> asc("y") then          
  160.             if iGhostSX(N)<> 0 or iGhostSY(N)<> 1 then iC += 4 : iUp = 1 : iRand += 1 else iUp = -2
  161.           end if
  162.           if iDn=0 and asc( sMap( iY+1 ) , iX   ) <  asc("y") then
  163.             if iGhostSX(N)<> 0 or iGhostSY(N)<>-1 then iC += 8 : iDn = 1 : iRand += 1 else iDn = -2
  164.           end if
  165.          
  166.           'se não houver outra possibilidade de movimento então permite ir na direção oposta
  167.           if iC=0 then
  168.             if iRt=-2 and iGhostSX(N)=-1 and iGhostSY(N)= 0 then iC += 1 : iRt = 1 : iRand += 1
  169.             if iLt=-2 and iGhostSX(N)=+1 and iGhostSY(N)= 0 then iC += 2 : iLt = 1 : iRand += 1
  170.             if iUp=-2 and iGhostSX(N)= 0 and iGhostSY(N)=+1 then iC += 4 : iUp = 1 : iRand += 1
  171.             if iDn=-2 and iGhostSX(N)= 0 and iGhostSY(N)=-1 then iC += 8 : iDn = 1 : iRand += 1
  172.           end if        
  173.          
  174.           'decide nova direção
  175.           if 1 then 'N = 1 or N = 3 then
  176.             M = 1000
  177.             iOff1 = iPlayerX-iX : if iGhostSlow(N)>0  then ioff1 = -iOff1
  178.             ioff2 = iOff1 : if ioff2 < 0 then ioff2 = -ioff2
  179.             if ioff2>0 and ioff2<M then            
  180.               if iRt=1 and iOff1>0 then iGhostSX(N) =  1 : iGhostSY(N) =  0 : M = ioff2
  181.               if iLt=1 and iOff1<0 then iGhostSX(N) = -1 : iGhostSY(N) =  0 : M = ioff2
  182.             end if
  183.             iOff1 = iPlayerY-iY : if iGhostSlow(N)>0  then ioff1 = -iOff1
  184.             ioff2 = iOff1 : if ioff2 < 0 then ioff2 = -ioff2
  185.             if ioff2>0 and ioff2<M then
  186.               if iDn=1 and iOff1>0 then iGhostSX(N) = 0 : iGhostSY(N) = +1 : M = ioff2
  187.               if iUp=1 and iOff1<0 then iGhostSX(N) = 0 : iGhostSY(N) = -1 : M = ioff2
  188.             end if
  189.             if iC=0 or M <> 1000 then M = 0
  190.           else
  191.             if iC>0 and iC <> iGhostMov(N) then M = 1 else M = 0
  192.           end if
  193.          
  194.           while M
  195.             iRand += 1 : while iRand>3 : iRand -= 4 : wend
  196.             if iRand=0 and iRt=1 then iGhostSX(N) =  1 : iGhostSY(N) =  0 : exit while
  197.             if iRand=1 and iDn=1 then iGhostSX(N) =  0 : iGhostSY(N) =  1 : exit while
  198.             if iRand=2 and iLt=1 then iGhostSX(N) = -1 : iGhostSY(N) =  0 : exit while
  199.             if iRand=3 and iUp=1 then iGhostSX(N) =  0 : iGhostSY(N) = -1 : exit while          
  200.           wend
  201.          
  202.           'move o fantasma (se puder)
  203.           iGhostMov(N)=iC
  204.           if iC>0 then
  205.             iGhostX(N) += iGhostSX(N)
  206.             iGhostY(N) += iGhostSY(N)      
  207.           end if
  208.          
  209.         end if
  210.       end if
  211.      
  212.       'se está morto então coloca os fantasmas na posição/tempo padrão
  213.       if iDead then
  214.         iGhostX(N)=iSpawnX : iGhostY(N)=iSpawnY
  215.         iGhostWait(N) = N*128+N+32
  216.       end if
  217.      
  218.       locate iGhostY(N),iGhostX(N)
  219.       if iGhostSlow(N)>0 then
  220.         'enquanto player estar super fantasmas ficam da mesma cor
  221.         'mas quando o super estiver para acabar eles piscam
  222.         iC = 3
  223.         for M=4 to 40 step 4
  224.           if iSuper>M then
  225.             if iC=3 then iC=15 else iC=3
  226.           end if
  227.         next M
  228.         color iC
  229.       else
  230.         color N+10
  231.       end if
  232.       print chr(15);      
  233.      
  234.     next N
  235.    
  236.     'se esta morto coloca o jogador na posição padrão
  237.     'e se ele não estava na posição padrão então desconta uma vida
  238.     if iDead then    
  239.       if iPlayerX<>iStartX or iPlayerY<>iStartY then
  240.         locate iPlayerY,iPlayerX : print " "; : iLives -= 1      
  241.       end if
  242.       iPlayerX = iStartX : iPlayerY = iStartY    
  243.     else
  244.       if (iScore-iScore2) > 5000 then
  245.         iScore2 = iScore2 + 5000 : iLives += 1
  246.       end if
  247.     end if  
  248.    
  249.     'teleporta de um lado a outro
  250.     if iPlayerX < 1 then iPlayerX = 21 : iRand += 3
  251.     if iPlayerX > 21 then iPlayerX = 1 : iRand += 1
  252.      
  253.     'quando pisa num ponto come ele, reduz a contagem pontos
  254.     'se não tiver mais pontos para comer, venceu!
  255.     if asc( sMap(iPlayerY) , iPlayerX ) = asc(".") then
  256.       iDots -= 1 : iRand += 2 : iScore += 5
  257.       mid( sMap(iPlayerY) , iPlayerX ) = " "    
  258.     end if
  259.     'se era um super ponto fica poderoso por 256 frames
  260.     if asc( sMap(iPlayerY) , iPlayerX ) = asc("*") then
  261.       iDots -= 1 : iSuper += 256 : iRand += 3 : iScore += 20
  262.       mid( sMap(iPlayerY) , iPlayerX ) = " "    
  263.       'reiniciar AI ao começar o super
  264.       for N = 0 to 3
  265.         if iGhostX(N)<>iSpawnX or iGhostY(N)<>iSpawnY then iGhostMov(N) = 0 : iGhostSlow(N) = 1
  266.       next N
  267.     end if
  268.    
  269.     'informações na tela
  270.     if iUpdate then
  271.       color 15 : locate  2,23 : print "Dots.: ";iDots;" ";
  272.       color 14 : locate  4,23 : print "Super: ";(iSuper+19)\20;" ";
  273.       color 10 : locate  6,23 : print "Score: ";iScore
  274.       color 12 : locate  8,23 : print "Vidas: ";iLives
  275.       color 11 : locate 10,23 : print "Nivel: ";iLevel
  276.     end if
  277.    
  278.     'se estiver poderoso pisca entre chr(1) e chr(2) senão só chr(1)
  279.     if iSuper > 0 then
  280.       iSuper -= 1 : iRand += 1
  281.       iPlayer = 3-iPlayer '2<->1
  282.       if iSuper=0 then 'reiniciar AI se acabou super
  283.         for N = 0 to 3
  284.           if iGhostSlow(N) > 0 then iGhostMov(N) = 0 : iGhostSlow(N) = 0
  285.         next N
  286.       end if
  287.     else
  288.       iPlayer = 1
  289.     end if
  290.    
  291.     'se não tiver mais vidas acaba sem o jogador aparecer na tela
  292.     if iLives < 1 then exit do
  293.    
  294.     'desenha jogador
  295.     locate iPlayerY,iPlayerX,0
  296.     color 14 : print chr(iPlayer);
  297.    
  298.     'se tiver pego todos os pontos acaba com o jogador aparecendo na tela
  299.     if iDots < 1 then exit do
  300.    
  301.     'enquanto nenhuma tecla estiver pressionada volta para o começo do loop
  302.     sKey = inkey
  303.     'if sKey = "" then sleep 50,1 : continue do
  304.     sleep 50-iLevel,1
  305.     if sKey="" orelse sKey=sKey1 then
  306.       iAuto = iAuto-1
  307.       if iAuto then continue do
  308.       iAuto=4 : if sKey = "" then sKey=sKey2
  309.     end if
  310.     sKey2 = sKey
  311.      
  312.     'apaga jogador (possível mudará de posição)
  313.      
  314.     if sKey = chr(27) then exit do 'escape quit
  315.    
  316.     'uma das setas foi pressionada? e o jogador pode se mover para lá?
  317.     iErase = 0 : iX = iPlayerX : iY = iPlayerY
  318.     for N = 0 to 1    
  319.       if sKey = chr(255)+"K" and asc( sMap(iPlayerY  ) , iPlayerX-1 ) < asc("y") then      
  320.         iPlayerX -= 1 : iRand += 1 : sKey1 = sKey : iErase = 1
  321.       end if
  322.       if sKey = chr(255)+"M" and asc( sMap(iPlayerY  ) , iPlayerX+1 ) < asc("y") then      
  323.         iPlayerX += 1 : iRand += 2 : sKey1 = sKey : iErase = 1
  324.       end if
  325.       if sKey = chr(255)+"H" and asc( sMap(iPlayerY-1) , iPlayerX   ) < asc("y") then      
  326.         iPlayerY -= 1 : iRand += 3 : sKey1 = sKey : iErase = 1
  327.       end if
  328.       if sKey = chr(255)+"P" and asc( sMap(iPlayerY+1) , iPlayerX   ) < asc("y") then
  329.         iPlayerY += 1 : iRand += 1 : sKey1 = sKey : iErase = 1
  330.       end if    
  331.       if sKey=sKey1 then exit for
  332.       sKey = sKey1
  333.     next N
  334.     if iErase=1 then locate iY,iX : print " "; : iDead=0
  335.    
  336.   loop
  337.  
  338.   if iDots <= 0 then  
  339.     for N = 0 to 15
  340.       if iC=10 then iC=15 else iC=10
  341.       if N = 15 then iC = 0
  342.       locate 16,24 : color iC
  343.       print "Well Done!";  
  344.       sleep 150,1
  345.     next N
  346.     iLevel += 1 : continue do
  347.   else
  348.     if iLives <= 0 then
  349.       while inkey<>chr(27)
  350.         if iC=12 then iC=9 else iC=12
  351.         locate 16,24 : color iC
  352.         print "GAME OVER!";  
  353.         sleep 200,1
  354.       wend          
  355.     end if  
  356.   end if
  357.  
  358.   exit do
  359.  
  360. loop
  361.  
  362.  
Add Comment
Please, Sign In to add comment