Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Screen 0 PacMan game from an old Tutorial
#1
In my archives, I found and old program I created following a simple tutorial. I thought I would share it.

Code: (Select All)

CLS
RANDOMIZE TIMER
SCREEN 0
DIM maze$(22)
maze$(01) = "±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±"
maze$(02) = "±ùùù±ùùù±±±±±±±±±±ùùù±ùù±±±±ùùù±ùùùùùù±±ùùù±±±±ùùùùùù±±±±±±±±±±ùùùù±±±±±ùù±±ùùù±"
maze$(03) = "±ù±ù±ù±ùùùùùùùùùùùù±ùùùùùùùùùùù±ùùùùùù±±ùùùùùùùùù±±ùùùùùùùùù±ùùùùùùùùùùùùùùùù±ù±"
maze$(04) = "±ù±ùùù±ùùù±±±±±±±ù±±±±±±±±±±±±ù±ù±±±±ù±±ù±±ùùùùùùù±ù±ùùùùùùù±ùù±±±±±±±ùùùùùùù±ù±"
maze$(05) = "±ùùù±ùùùùùùùùùùùùùùùùùùùùùù±±ùùùùùùù±ù±±ùùùùù±±±±ù±ù±±±±±±ùù±ùùùù±±±ùùù±±±±±ùùù±"
maze$(06) = "±ù±ùùùù±ùù±±±±±±±ù±±±ùù±±±ùùùùùù±±±±±ù±±ùùùùùùùù±±±ù±ùùù±±ùù±ùùùùùùùùùùùùùùùù±ù±"
maze$(07) = "±ù±ùùù±±±ùùùùùùùùùùùùùùùùùù±ùùùù±ùùùùùùùù±±ùùùùùùù±±±ù±ùùùùù±ùùù±±±±±±±ùùùùùù±ù±"
maze$(08) = "±ù±ùùùù±ùù±±±±±±±±±±±±±±±±±±±±ùù±ùù±±ùùùùù±±±±ù±±ùù±±±±±±±±ù±ùùùùùùù±±ùùùùùùùùù±"
maze$(09) = "±ùùùùùùùùùùù±ùù±ùù±±±±ùùùùùùùùùùùùù±±ù±±ùù±±±±ùùùùù±±±ùùùùùù±ùùùùùù±±±±±ùùùùù±±±"
maze$(10) = "±±±±±±±±±±ù±ùùùùùùùùùùùù±ùù±±±±±ùù±ùùùùù±±ùùùùùùù±±±ùùùùùùù±±ùùùùùùùùùùùùùùùùùù±"
maze$(11) = "±ùùùùùùùùùùùùù±±±±±±ù±ùù±ùùùùùùùùù±ùùùùùùùùù±±ùùù±±±±±±±±±ùùùùù±±±±±±±±±±ùù±±±±±"
maze$(12) = "±±±±±±ùù±ù±±±±±±±±±±±±±ù±ùù±±±±±±±±±±±±±ùù±±±±±ùù±±±ùùùù±ùùùùù±±±±ù±±±ù±ùùù±±ùù±"
maze$(13) = "±ùùùùùùù±ùùùùù±ù±±±±ù±±ù±ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù±±±ùùùùùùùùù±"
maze$(14) = "±ù±±ù±ùù±ùùù±ùùùùùùùùùùù±ù±±±±±±ùù±±±±±±±±±±±±±±±±±±±±±±±±±±±±±ùùùù±±±ùù±±±±ù±±±"
maze$(15) = "±ùùùùùùù±ù±±±±±±±±±ù±ùùùùùùù±ù±±ùùùù±±ùùùùùùù±±ùùùùùùùùùùùù±±±ùùùùùùùùùùùùùùùùù±"
maze$(16) = "±ù±±±ù±ù±ùùùùùùùùùùùùùùù±ùùùùùùùù±±ùùùù±±±±±ùùùù±±±±±±±±ùùùùùùùùùùù±±±ùùù±±±ù±±±"
maze$(17) = "±ùùùùùùù±±±±ù±ù±±±±±±±±±±ù±±±±±±ùùùù±±ùù±±ùùù±±ùùùù±ùùù±ùù±±±±±±±ùùùùùùùùùùùùùù±"
maze$(18) = "±ù±±±±ù±±ùùùù±ùùùùùùù±±ù±ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù±ù±ùùù±±±±±±±ùù±"
maze$(19) = "±ùùùùùùù±ù±±±±±±±±±±ùùùù±±±ùùùùù±±±ù±±ù±±±±±±±±±±±±±±±±±±ùù±±±±±±ù±ùùùùùùùùùùù±±"
maze$(20) = "±ù±±ùù±ù±ùùù±ùùùùùùùù±ùùùùùù±±±ùùùùù±±ù±ùùùùùùùùù±ùù±±ùù±ùùùùù±±ùùùùùù±±±±±±±ùù±"
maze$(21) = "±ùù±ù±±±±±±ùùù±±ù±±ùù±±ù±±±ùùùùù±±±ùùùùùù±±ùù±ù±ù±ùùùùùùùùù±ùùùùùù±ùùùùù±±ùùùùù±"
maze$(22) = "±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±"

row = 5
column = 3
ghostRow = 21
ghostColumn = 79

ghostRow2 = 13
ghostColumn2 = 2
dots = 949

DO
    LOCATE 1, 1
    FOR count = 1 TO 22
        PRINT maze$(count)
    NEXT count

    LOCATE row, column
    COLOR 2
    PRINT ""
    COLOR 7

    LOCATE ghostRow, ghostColumn
    COLOR 4
    PRINT "²"
    COLOR 7

    IF dots = 0 THEN
        LOCATE 8, 1
        PRINT "You won!"
        SLEEP
        SLEEP
        END
    END IF

    IF ((row = ghostRow) AND (column = ghostColumn)) THEN
        LOCATE 8, 1
        BEEP
        PRINT "You got caught!"
        SLEEP
CLS

Exit do
End If
    keyed$ = INKEY$

    _DELAY .055
    oldRow = row
    oldColumn = column

    REM examine the keys
    SELECT CASE keyed$
        CASE IS = "w"
            row = row - 1
        CASE IS = "s"
            row = row + 1
        CASE IS = "a"
            column = column - 1
        CASE IS = "d"
            column = column + 1
    END SELECT

    REM examine the maze
    SELECT CASE MID$(maze$(row), column, 1)
        CASE IS = "±"
            row = oldRow
            column = oldColumn
        CASE IS = "ù"
            MID$(maze$(row), column, 1) = " "
dots = dots - 1
    END SELECT

: REM new
    IF RND < 0.30 THEN
        : REM
        REM move ghost closer to PACMAN
        oldRow = ghostRow
        SELECT CASE ghostRow
            CASE IS < row
                ghostRow = ghostRow + 1
            CASE IS > row
                ghostRow = ghostRow - 1
        END SELECT
        IF MID$(maze$(ghostRow), ghostColumn, 1) = "±" THEN ghostRow = oldRow

        IF ghostRow = oldRow THEN
            oldColumn = ghostColumn
            SELECT CASE ghostColumn
                CASE IS < column
                    ghostColumn = ghostColumn + 1
                CASE IS > column
                    ghostColumn = ghostColumn - 1
            END SELECT
            IF MID$(maze$(ghostRow), ghostColumn, 1) = "±" THEN ghostColumn = oldColumn
        END IF
    END IF: REM  <ÄÄÄ new


LOOP
Reply
#2
+1 nice LOC, i would change wasd to arrows. i didn't even see ghost, first time played, as it does not move until you start to get near it. cool thanks for share
b = b + ...
Reply
#3
The AI is indeed a bit wacky, and the ghost moves faster the closer it is to the player. It would need tweaking perhaps, or a simpler maze.
Reply
#4
(04-30-2024, 06:37 PM)Delsus Wrote: The AI is indeed a bit wacky, and the ghost moves faster the closer it is to the player. It would need tweaking perhaps, or a simpler maze.
Here is the pac-man dossier I used when I wrote my pac-man game:

https://pacman.holenet.info/

Complete info on the mechanics of the game.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#5
Thank you for posting this, +2.  Now Terry can get to work on making his Pac Man game in SCREEN 0.

Pete Big Grin

- SCREEN 0. The only SCREEN anyone would ever need!
Reply
#6
(05-01-2024, 07:57 AM)Pete Wrote: Thank you for posting this, +2.  Now Terry can get to work on making his Pac Man game in SCREEN 0.

Pete Big Grin

- SCREEN 0. The only SCREEN anyone would ever need!
I'll call it P0C-M0N
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 1 Guest(s)