Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH 40, 25
- CLS
- DEFINT A-Z
- DEFSTR S
- DEFSNG F
- ' # walls
- ' - walls that ghost can pass
- ' . edible dots
- ' * edible super dots
- ' @ player initial position
- ' x ghost initial position
- DIM sMap(25), sM(25)
- sM(1) = "7888888888w8888888889"
- sM(2) = "4.........5.........6"
- sM(3) = "4.789.789.5.789.789.6"
- sM(4) = "4*5 5.5 5.5.5 5.5 5*6"
- sM(5) = "4.123.123.s.123.123.6"
- sM(6) = "4...................6"
- sM(7) = "4.789.w.78889.w.789.6"
- sM(8) = "4.123.5.12w23.5.123.6"
- sM(9) = "4.....5...5...5.....6"
- sM(10) = "18889.a88.s.88d.78883"
- sM(11) = " 5.5.......5.5 "
- sM(12) = "22223.s.7---9.s.12222"
- sM(13) = " ...5 x 5... "
- sM(14) = "88889.w.18883.w.78888"
- sM(15) = " 5.5.......5.5 "
- sM(16) = "72223.s.22w22.s.12229"
- sM(17) = "4.........5.........6"
- sM(18) = "4.889.888.5.888.788.6"
- sM(19) = "4*..5.....@.....5..*6"
- sM(20) = "189.5.w.78889.w.5.783"
- sM(21) = "723.s.5.12w23.5.s.129"
- sM(22) = "4.....5...5...5.....6"
- sM(23) = "4.8888s88.s.88s8888.6"
- sM(24) = "4...................6"
- sM(25) = "122222222222222222223"
- DIM iX, iY, iC, M, N, iDots
- DIM iPlayerX, iPlayerY, iStartX, iStartY
- DIM iSpawnX, iSpawnY, iRand
- DIM iScore, iLives
- DIM iSuper, iPlayer, iDead
- DIM iGhostX(3), iGhostY(3), iGhostSX(3), iGhostSY(3)
- DIM iGhostMov(3), iGhostWait(3)
- iPlayer = 1: iDead = 1: iLives = 3
- 'exibe labirinto inicial conforme os dados no mapa
- 'salvando os pontos de teleporte, e os pontos iniciais do jogador/fantasmas
- FOR iY = 1 TO 25
- sMap(iY) = sM(iY): LOCATE iY, 1
- FOR iX = 1 TO 21
- COLOR 9
- SELECT CASE MID$(sMap(iY), iX, 1)
- CASE "1": PRINT CHR$(200); : MID$(sMap(iY), iX, 1) = "y"
- CASE "2": PRINT CHR$(205); : MID$(sMap(iY), iX, 1) = "y"
- CASE "3": PRINT CHR$(188); : MID$(sMap(iY), iX, 1) = "y"
- CASE "4", "5", "6": PRINT CHR$(186); : MID$(sMap(iY), iX, 1) = "y"
- CASE "7": PRINT CHR$(201); : MID$(sMap(iY), iX, 1) = "y"
- CASE "8": PRINT CHR$(205); : MID$(sMap(iY), iX, 1) = "y"
- CASE "9": PRINT CHR$(187); : MID$(sMap(iY), iX, 1) = "y"
- CASE "w": PRINT CHR$(203); : MID$(sMap(iY), iX, 1) = "y"
- CASE "s": PRINT CHR$(202); : MID$(sMap(iY), iX, 1) = "y"
- CASE "a": PRINT CHR$(204); : MID$(sMap(iY), iX, 1) = "y"
- CASE "d": PRINT CHR$(185); : MID$(sMap(iY), iX, 1) = "y"
- CASE "-": PRINT "-"; : MID$(sMap(iY), iX, 1) = "z"
- CASE " ": PRINT " ";
- CASE "x": PRINT " "; : iSpawnX = iX: iSpawnY = iY
- CASE ".": COLOR 6: PRINT CHR$(250); : iDots = iDots + 1
- CASE "*": COLOR 14: PRINT CHR$(254); : iDots = iDots + 1
- CASE "@": PRINT " "; : iStartX = iX: iStartY = iY
- END SELECT
- NEXT iX
- NEXT iY
- 'ghost initial position
- 'and delay between movements
- FOR N = 0 TO 3
- iGhostX(N) = iSpawnX: iGhostY(N) = iSpawnY
- iGhostSX(N) = 1: iGhostSY(N) = 0
- iGhostWait(N) = N * 128 + N + 32
- NEXT N
- iPlayerX = iStartX: iPlayerY = iStartY
- DIM sKey
- ContinueDo:
- DO
- 'adjust "randmoness"
- iRand = iRand + 1
- WHILE iRand > 3
- iRand = iRand - 4
- WEND
- 'move ghosts
- FOR N = 0 TO 3
- iX = iGhostX(N): iY = iGhostY(N)
- 'delete ghost (put back map character)
- LOCATE iY, iX:
- SELECT CASE MID$(sMap(iY), iX, 1)
- CASE ".": COLOR 6: PRINT CHR$(250);
- CASE "z": COLOR 9: PRINT "-";
- CASE "*": COLOR 14: PRINT CHR$(254);
- CASE ELSE: PRINT " ";
- END SELECT
- 'if player touch ghost then one of them die
- IF iX = iPlayerX AND iY = iPlayerY THEN
- IF iSuper > 0 THEN 'ghost dies
- iScore = iScore + 150
- FOR M = 0 TO 3
- IF iGhostWait(M) > 8 THEN iScore = iScore + 50
- NEXT M
- iGhostX(N) = iSpawnX: iGhostY(N) = iSpawnY
- iGhostSX(N) = 1: iGhostSY(N) = 0
- iGhostWait(N) = 128 + N
- ELSE 'player dies
- iDead = 1
- END IF
- END IF
- IF iGhostWait(N) > 0 THEN
- 'decrement counter for ghost action
- IF iGhostWait(N) < 9 OR iSuper = 0 THEN iGhostWait(N) = iGhostWait(N) - 1
- IF iGhostWait(N) < 1 THEN
- 'fantasmas metade da velocidade enquanto jogador esta super
- IF iSuper > 0 THEN iGhostWait(N) = 8 ELSE iGhostWait(N) = 4
- iC = 0
- 'which direction ghosts can go?
- '1) cant go trough walls
- '2) cant go back on same path (if possible)
- '3) cant hit another ghost
- DIM iUp, iDn, iLt, iRt
- iUp = 0: iDn = 0: iLt = 0: iRt = 0
- 'prevent ghosts from moving on top of each other
- FOR M = 0 TO 3
- IF M <> N THEN 'ignora o próprio
- IF (iX + 1) = iGhostX(M) AND (iY) = iGhostY(M) THEN iRt = -1
- IF (iX - 1) = iGhostX(M) AND (iY) = iGhostY(M) THEN iLt = -1
- IF (iX) = iGhostX(M) AND (iY - 1) = iGhostY(M) THEN iUp = -1
- IF (iX) = iGhostX(M) AND (iY + 1) = iGhostY(M) THEN iDn = -1
- END IF
- NEXT M
- 'if not hit wall and not going back then add as valid direction
- IF iRt = 0 AND iX < 21 THEN
- IF MID$(sMap(iY), iX + 1, 1) < "y" THEN
- IF iGhostSX(N) <> -1 OR iGhostSY(N) <> 0 THEN iC = iC + 1: iRt = 1: iRand = iRand + 1
- END IF
- END IF
- IF iLt = 0 AND iX > 1 THEN
- IF MID$(sMap(iY), iX - 1, 1) < "y" THEN
- IF iGhostSX(N) <> 1 OR iGhostSY(N) <> 0 THEN iC = iC + 2: iLt = 1: iRand = iRand + 1
- END IF
- END IF
- IF iUp = 0 AND MID$(sMap(iY - 1), iX, 1) <> "y" THEN
- IF iGhostSX(N) <> 0 OR iGhostSY(N) <> 1 THEN iC = iC + 4: iUp = 1: iRand = iRand + 1
- END IF
- IF iDn = 0 AND MID$(sMap(iY + 1), iX, 1) < "y" THEN
- IF iGhostSX(N) <> 0 OR iGhostSY(N) <> -1 THEN iC = iC + 8: iDn = 1: iRand = iRand + 1
- END IF
- 'if theres no other possibility then make it go back
- IF iC = 0 THEN
- IF iGhostSX(N) = -1 AND iGhostSY(N) = 0 THEN iC = iC + 1: iRt = 1: iRand = iRand + 1
- IF iGhostSX(N) = 1 AND iGhostSY(N) = 0 THEN iC = iC + 2: iLt = 1: iRand = iRand + 1
- IF iGhostSX(N) = 0 AND iGhostSY(N) = 1 THEN iC = iC + 4: iUp = 1: iRand = iRand + 1
- IF iGhostSX(N) = 0 AND iGhostSY(N) = -1 THEN iC = iC + 8: iDn = 1: iRand = iRand + 1
- END IF
- 'choose new direction
- DO WHILE iC > 0 AND iC <> iGhostMov(N)
- iRand = (iRand + 1) AND 3
- IF iRand = 0 AND iRt = 1 THEN iGhostSX(N) = 1: iGhostSY(N) = 0: EXIT DO
- IF iRand = 1 AND iDn = 1 THEN iGhostSX(N) = 0: iGhostSY(N) = 1: EXIT DO
- IF iRand = 2 AND iLt = 1 THEN iGhostSX(N) = -1: iGhostSY(N) = 0: EXIT DO
- IF iRand = 3 AND iUp = 1 THEN iGhostSX(N) = 0: iGhostSY(N) = -1: EXIT DO
- LOOP
- 'move o fantasma (se puder)
- iGhostMov(N) = iC
- IF iC > 0 THEN
- iGhostX(N) = iGhostX(N) + iGhostSX(N)
- iGhostY(N) = iGhostY(N) + iGhostSY(N)
- END IF
- END IF
- END IF
- 'if dead than put all ghosts on start position and add some delay
- IF iDead THEN
- iGhostX(N) = iSpawnX: iGhostY(N) = iSpawnY
- iGhostWait(N) = N * 128 + N + 32
- END IF
- LOCATE iGhostY(N), iGhostX(N)
- IF iSuper > 0 THEN
- 'while player is super then ghosts are same color
- 'but when super time is running out they blink white
- iC = 3
- FOR M = 4 TO 40 STEP 4
- IF iSuper > M THEN
- IF iC = 3 THEN iC = 15 ELSE iC = 3
- END IF
- NEXT M
- COLOR iC
- ELSE
- COLOR N + 10
- END IF
- PRINT CHR$(15);
- NEXT N
- 'if dead then put player on start position
- 'if was not there then decrement a life
- IF iDead THEN
- LOCATE iPlayerY, iPlayerX: PRINT " ";
- IF iPlayerX <> iStartX OR iPlayerY <> iStartY THEN iLives = iLives - 1
- iPlayerX = iStartX: iPlayerY = iStartY
- END IF
- 'teleport side to side
- IF iPlayerX < 1 THEN iPlayerX = 21: iRand = iRand + 3
- IF iPlayerX > 21 THEN iPlayerX = 1: iRand = iRand + 1
- SELECT CASE MID$(sMap(iPlayerY), iPlayerX, 1)
- CASE "."
- 'when step on a dot eat it and decrement dot count
- 'if theres no more dots then you won!
- iDots = iDots - 1: iRand = iRand + 2
- iScore = iScore + 5: SOUND 8000, 1 / 18
- MID$(sMap(iPlayerY), iPlayerX, 1) = " "
- CASE "*"
- 'if it was super dot then become super for 256 frames
- iDots = iDots - 1: iSuper = iSuper + 256
- iRand = iRand + 3: iScore = iScore + 20
- MID$(sMap(iPlayerY), iPlayerX, 1) = " "
- END SELECT
- 'screen information
- COLOR 15: LOCATE 2, 23: PRINT "Dots.: "; iDots; " ";
- COLOR 14: LOCATE 4, 23: PRINT "Super: "; (iSuper + 19) \ 20; " ";
- COLOR 10: LOCATE 6, 23: PRINT "Score: "; iScore
- COLOR 12: LOCATE 8, 23: PRINT "Vidas: "; iLives
- 'if player super then swap between chr$(1 and chr$(2) otherwise chr$(1)
- IF iSuper > 0 THEN
- iSuper = iSuper - 1: iRand = iRand + 1
- iPlayer = 3 - iPlayer '2<->1
- ELSE
- iPlayer = 1
- END IF
- 'if theres no more lives game end without drawing player
- IF iLives < 1 THEN EXIT DO
- 'draw player
- LOCATE iPlayerY, iPlayerX, 0
- COLOR 14: PRINT CHR$(iPlayer);
- 'if no more dots to get game ends with player showing
- IF iDots < 1 THEN EXIT DO
- 'while no key is pressed go back to start
- sKey = INKEY$
- IF sKey = "" THEN
- IF ABS(TIMER-fDelay) > 1 THEN fDelay = TIMER
- WHILE ABS(TIMER-fDelay) < (1/18.2)
- WAIT &H3DA, 8: WAIT &H3DA, 8, 8 'vsync?
- WEND
- fDelay = fDelay+(1/18.2) : GOTO ContinueDo
- END IF
- IF sKey = CHR$(27) THEN EXIT DO 'escape quit
- 'erase player (as it may change position)
- LOCATE iPlayerY, iPlayerX
- PRINT " ";
- 'one arrow was pressed can the player move to that direction?
- SELECT CASE sKey
- CASE CHR$(0) + "K"
- IF iPlayerX > 1 THEN
- IF MID$(sMap(iPlayerY), iPlayerX - 1, 1) < "y" THEN
- iPlayerX = iPlayerX - 1: iRand = iRand + 1: iDead = 0
- END IF
- ELSE
- iPlayerX = iPlayerX - 1: iRand = iRand + 1: iDead = 0
- END IF
- CASE CHR$(0) + "M"
- IF MID$(sMap(iPlayerY), iPlayerX + 1, 1) < "y" THEN
- iPlayerX = iPlayerX + 1: iRand = iRand + 2: iDead = 0
- END IF
- CASE CHR$(0) + "H"
- IF MID$(sMap(iPlayerY - 1), iPlayerX, 1) < "y" THEN
- iPlayerY = iPlayerY - 1: iRand = iRand + 3: iDead = 0
- END IF
- CASE CHR$(0) + "P"
- IF MID$(sMap(iPlayerY + 1), iPlayerX, 1) < "y" THEN
- iPlayerY = iPlayerY + 1: iRand = iRand + 1: iDead = 0
- END IF
- END SELECT
- LOOP
- IF iDots <= 0 THEN
- WHILE INKEY$ <> CHR$(27)
- IF iC = 10 THEN iC = 15 ELSE iC = 10
- LOCATE 16, 27: COLOR iC
- PRINT "Well Done!";
- SOUND 32767, 3
- WEND
- ELSE
- IF iLives <= 0 THEN
- WHILE INKEY$ <> CHR$(27)
- IF iC = 12 THEN iC = 9 ELSE iC = 12
- LOCATE 16, 27: COLOR iC
- PRINT "GAME OVER!";
- SOUND 32767, 4
- WEND
- END IF
- END IF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement