Qbasicnews.com

Full Version: PACMAN MUST LIVE FOREVER!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey guys, ummm im having trouble making my pacman game....its working fine, but its just not appealing...and i have till friday to finish it, im really screwed....if anyone can help me, im all for it.......thanx in advance.........

p.s. Ill post my code tommorow, its on my school computer

but feel free to post ideas/code to help....thanx
add fruit.
ok heres the code, but 1st, i would like to know is it possible to make the ghosts move without having to move pacman, and also if its possible to, when u hit a movement key, that pacman keeps going that way until another movement key is pressed..... just wondering....

Code:
CLS                                         'clear screen
SCREEN 13                                    'set screen resolution
DIM maze$(11)                                   'Declares that there is 6 maze variables
DIM oldrow
DIM oldcol

maze$(1) = "ÉÍÍÍÍÍÍÍËÍÍÍÍÍÍÍ»"                  'the following is the maze in
maze$(2) = "º       º       º"                  'the variables
maze$(3) = "º º ÍÍÍÍÊÍÍÍÍ º º"
maze$(4) = "º º           º º"
maze$(5) = "º ÈÍÍ» ÍÎÍ ÉÍͼ º"
maze$(6) = "º    Âº  Âº  Âº    Âº"
maze$(7) = "º               º"
maze$(8) = "º  ÃÃÃÃÃÃ‹ÃÃÃÃÃ  Âº"
maze$(9) = "º       º       º"
maze$(10) = "º               º"
maze$(11) = "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"

row = 4                                     'says which row pacman is at
col = 7                                     'says which column pacman is at

ghostrow = 9                               'says which row the ghost starts at
ghostcol = 10                                'says which column the ghost starts at

dots = 54                                   'declares how many dots there are

DO                                          'Begins the Game loop
    LOCATE 1, 1                             'positions the maze
    
        FOR count = 1 TO 11                  'Prints the maze out
            PRINT maze$(count)
        NEXT count
  
    LOCATE row, col
    COLOR 14                                    'Prints Pacman
    PRINT "C"
    COLOR 15
  
    LOCATE ghostrow, ghostcol
    COLOR 4                                  'makes ghost red
    PRINT ""                               'Prints ghost
    COLOR 15

        IF dots = 0 THEN                    'declares when the user can win
            LOCATE 15, 1
            PRINT "You Have Won"            'Prints You win, if you eat all
            END                             'dots
        END IF
                                            'The following condition is for
                                            'when you get eaten by a ghost
        IF ((row = ghostrow) AND (col = ghostcol)) THEN
            LOCATE 15, 1
            PRINT "Your Dead"               'Prints your dead
            END
        END IF

   DO                                       'Program freezes until user press'
    press$ = INKEY$                         'any key
   LOOP UNTIL press$ <> ""

    oldrow = row                            'every move is stored into the variable
    oldcol = col

        SELECT CASE press$                  'the following is the conditions for
            CASE CHR$(0) + CHR$(72)         'the key press'
               row = row - 1
            CASE CHR$(0) + CHR$(80)
               row = row + 1
            CASE CHR$(0) + CHR$(75)
               col = col - 1
            CASE CHR$(0) + CHR$(77)
                col = col + 1
        END SELECT

    SELECT CASE MID$(maze$(row), col, 1)    'wont let you get passed maze
      CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
        row = oldrow
        col = oldcol
      CASE "."                              'when you eat a dot, it dissapears
        MID$(maze$(row), col, 1) = " ": BEEP
        dots = dots - 1
    END SELECT


  
    '*******************
    'Ghost Movements
    '*******************

  
    IF RND < .9 THEN                       'randomizes the ghosts movements
        oldrow = ghostrow
        SELECT CASE ghostrow
            CASE IS < row                  'moves ghost closer to you
                ghostrow = ghostrow + 1
            CASE IS > row
                ghostrow = ghostrow - 1
        END SELECT
    
  
  
    oldrow = ghostrow
  
    SELECT CASE ghostcol                   'moves ghost closer to you
        CASE IS < row
            ghostrow = ghostrow + 1
        CASE IS > row
            ghostrow = ghostrow - 1
    END SELECT

                                           'wont let ghost go through walls
        SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
                CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
            ghostrow = oldrow
        END SELECT

                                                   'makes the ghost stay if he tries to
                                           'get out of maze
                SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
                    CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
                       ghostcol = oldcol
                END SELECT
        END IF

LOOP UNTIL press$ = CHR$(13)

and thats that......
nifty
just have a var to store the key and have pacman move the next turn with that var if a new one has not been set...
It was an okay game. Problem is, CHR$(27) is [ESCAPE]. Better for "escaping" the program than [ENTER] is. Also, your monster jumped across the whole "level" at one point. I don't know how, but he did. And I managed to walk right past him at one point also, and he didn't even chase after me or kill me. What a loser ghost he is!

I wanna try my hand at a pacman game. Only problem is I'd have to go all out on it (graphics, keyhandling, memory, etc) and that would take too much time.
OK heres my new code.....

with title screen and all..Big GrinBig GrinBig Grin

Code:
CLS                                         'clear screen
SCREEN 13                                    'set screen resolution
DIM maze(1 TO 11) AS STRING                               'Declares that there is 6 maze variables
DIM maze2(1 TO 18) AS STRING
DIM ghostrow(1 TO 3)  AS INTEGER
DIM ghostcol(1 TO 3)  AS INTEGER

DIM oldrow
DIM oldcol

maze$(1) = "ÉÍÍÍÍÍÍÍËÍÍÍÍÍÍÍ»"                  'the following is the maze in
maze$(2) = "º.......º.......º"                  'the variables
maze$(3) = "º.º.ÍÍÍÍÊÍÍÍÍ.º.º"
maze$(4) = "º.º...........º.º"
maze$(5) = "º.ÈÍÍ».ÍÎÍ.ÉÍͼ.º"
maze$(6) = "º.......º.......º"
maze$(7) = "º....º.. ..º....º"
maze$(8) = "º...ÍÍÍÍËÍÍÍÍ...º"
maze$(9) = "º...º...º...º...º"
maze$(10) = "º....... .......º"
maze$(11) = "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"

maze2$(1) = "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"
maze2$(2) = "Û........ÛÛ..........ÛÛ........Û"
maze2$(3) = "Û.ÛÛÛÛÛÛ.ÛÛ.ÛÛÛÛÛÛÛÛ.ÛÛ.ÛÛÛÛÛÛ.Û"
maze2$(4) = "Û..............................Û"
maze2$(5) = "ÛÛÛÛ.ÛÛÛ.ÛÛÛÛÛ.ÛÛ.ÛÛÛÛÛ.ÛÛÛ.ÛÛÛÛ"
maze2$(6) = "   Û.ÛÛÛ.ÛÛÛÛÛ.ÛÛ.ÛÛÛÛÛ.ÛÛÛ.Û"
maze2$(7) = "ÛÛÛÛ.ÛÛÛ.......ÛÛ.......ÛÛÛ.ÛÛÛÛ"
maze2$(8) = "    .ÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛ.    "
maze2$(9) = "ÛÛÛÛ.                      .ÛÛÛÛ"
maze2$(10) = "   Û.ÛÛÛÛÛÛ ÚÄÄÄÄÄÄ¿ ÛÛÛÛÛÛ.Û"
maze2$(11) = "   Û.ÛÛÛ    Â³      Â³    Ã›Ã›Ã›.Û"
maze2$(12) = "ÛÛÛÛ.ÛÛÛ ÛÛ ÀÄÄÄÄÄÄÙ ÛÛ ÛÛÛ.ÛÛÛÛ"
maze2$(13) = "    .    Ã›Ã›          Ã›Ã›    .    "
maze2$(14) = "ÛÛÛÛ.ÛÛÛÛÛÛÛÛÛ ÛÛ ÛÛÛÛÛÛÛÛÛ.ÛÛÛÛ"
maze2$(15) = "   Û........   ÛÛ    .......Û"
maze2$(16) = "ÛÛÛÛ.ÛÛÛÛÛÛ.ÛÛÛÛÛÛÛÛÛ.ÛÛÛÛÛ.ÛÛÛÛ"
maze2$(17) = "Û..............  ..............Û"
maze2$(18) = "Û.ÛÛÛÛÛ.ÛÛÛÛÛÛ.ÛÛ.ÛÛÛÛÛÛ.ÛÛÛÛÛ.Û"


row = 7                                     'says which row pacman is at
col = 9                                     'says which column pacman is at

ghostrow = 10                               'says which row the ghost starts at
ghostcol = 9                              'says which column the ghost starts at

dots = 93                                   'declares how many dots there are

DRAW "s8 bm4,3 c14 d50 r10 u23 r20 u27 l30 bm25,25 u2 r10 d10 l10 u8" 'P
DRAW "s8 bm38,102 u20 r20 d20 l7 u7 l6 d7 l7 bm48,78 u5 r7 d5 l7"     'A
DRAW "s8 bm88,102 u20 r15 g10 f10 l15"                                'C
CIRCLE (118, 82), 5                                                   'o
CIRCLE (138, 82), 5                                                   'o
CIRCLE (158, 82), 5                                                   'o
DRAW "s8 bm173,102 c14 u20 r5 f5 e5 r5 d20 l5 u10 g5 h5 d10 l5"       'M
DRAW "s8 bm223,102 u20 r20 d20 l7 u7 l6 d7 l7 bm233,78 u5 r7 d5 l7"   'A
DRAW "s8 bm273,102 u20 r5 f11 u11 r5 d20 l5 h11 d11 l5"               'N

CIRCLE (50, 150), 40, 14, .9, 5.4
DRAW "s8 bm50,150 e13 g13 f13"

DO
        press$ = INKEY$
LOOP UNTIL press$ = CHR$(13)

SCREEN 0

LOCATE 10, 8
PRINT "Created By: Justin Malcolm"

FOR i# = 1 TO 10000000 STEP 2
NEXT i#

LOCATE 10, 6
PRINT "Originally Created By: Micro$oft"

FOR b# = 1 TO 10000000 STEP 2
NEXT b#

PRINT
PRINT
PRINT
COLOR 14, 0
PRINT TAB(25); "C is PaQman"
PRINT
COLOR 4, 0
PRINT TAB(25); " is a Ghost"
PRINT
COLOR 15, 0
PRINT TAB(25); "'.' are the food"
PRINT
COLOR 6, 0
PRINT
PRINT TAB(25); "Press any key to play..."

DO
press$ = INKEY$
LOOP UNTIL press$ <> ""

CLS
points% = 0
lives% = 3

DO                                           'Begins Game loop
  
   LOCATE 1, 1                              'positions the maze
        
        FOR count = 1 TO 11
            COLOR 1, 0                       'Prints the maze out
            PRINT maze$(count)
            COLOR 15
        NEXT count
  
    LOCATE row, col
    COLOR 14, 0                                   'Prints Pacman
    PRINT "C"
  
    LOCATE ghostrow, ghostcol
    COLOR 4, 0                                 'makes ghost red
    PRINT ""                                   'Prints ghost
    COLOR 15

    LOCATE 13, 2: PRINT "Lives: "; lives%; "   Points: "; points%
    

        IF dots = 0 THEN                    'declares when the user can win
            LOCATE 15, 1
            PRINT "You Have Won"            'Prints You win, if you eat all
            PRINT "Get Ready for..."        'dots
            PRINT "LEVEL 2"
            END
        END IF


                                            'The following condition is for
                                            'when you get eaten by a ghost
        IF ((row = ghostrow) AND (col = ghostcol)) THEN
            LOCATE row, col
            PRINT " "
            row = 7
            col = 9
            LOCATE row, col
            COLOR 14, 0
            PRINT "C"
            COLOR 15, 0
            lives% = lives% - 1
        ELSEIF lives% <= 0 THEN
            CLS
            LOCATE 12, 8
            PRINT "You Lost All Of Your Lives"
            FOR i# = 1 TO 10000000 STEP 5
            NEXT i#
            END
        END IF

  'DO                                       'Program freezes until user press'
    press$ = INKEY$                         'any key
  'LOOP UNTIL press$ <> ""

blah = TIMER + .01
DO
LOOP UNTIL TIMER > blah


    oldrow = row                            'every move is stored into the variable
    oldcol = col

        SELECT CASE press$                  'the following is the conditions for
            CASE CHR$(0) + CHR$(72)             'the key press'
               'DO WHILE press$ = CHR$(0) + CHR$(72)
               row = row - 1
               'LOOP
            CASE CHR$(0) + CHR$(80)
               'DO WHILE press$ = CHR$(0) + CHR$(80)
               row = row + 1
               'LOOP
            CASE CHR$(0) + CHR$(75)
               'DO WHILE press$ = CHR$(0) + CHR$(75)
               col = col - 1
               'LOOP
            CASE CHR$(0) + CHR$(77)
                'DO WHILE press$ = CHR$(0) + CHR$(77)
                col = col + 1
                'LOOP
        END SELECT

    SELECT CASE MID$(maze$(row), col, 1)    'wont let you get passed maze
      CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
        row = oldrow
        col = oldcol
      CASE "."                              'when you eat a dot, it dissapears
        MID$(maze$(row), col, 1) = " ": PLAY "l16<<<b-"
        points% = points% + 10
        dots = dots - 1
    END SELECT


  
    '*******************
    'Ghost Movements
    '*******************

    IF RND < .1 THEN                    'randomizes the ghosts movements
        oldrow = ghostrow
        SELECT CASE ghostrow
            CASE IS < row                  'moves ghost closer to you
                ghostrow = ghostrow + 1
            CASE IS > row
                ghostrow = ghostrow - 1
        END SELECT
  
                                           'wont let ghost go through walls
        SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
                CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
            ghostrow = oldrow
        END SELECT

        IF ghostrow = oldrow THEN          'moves ghost closer to you
            oldcol = ghostcol
            SELECT CASE ghostcol
                CASE IS < col
                    ghostcol = ghostcol + 1
                CASE IS > col
                    ghostcol = ghostcol - 1
            END SELECT
        END IF
                                           'makes the ghost stay if he tries to
                                           'get out of maze
               SELECT CASE MID$(maze$(ghostrow), ghostcol, 1)
                    CASE "¹", "º", "»", "¼", "È", "É", "Ê", "Ë", "Ì", "Í", "Î"
                       ghostcol = oldcol
                END SELECT
        END IF

LOOP UNTIL press$ = CHR$(13)

any suggestions...besides that the second maze is unfinished?
for moving, and then keeping the pac man moving, store his direction to a var.
Code:
dir$=up
if dir$ = up then
pacy = pacy + 1
end if
if dir$ = down then
pacy = pacy - 1
end if
and so on and so forth. dont use that code though, there are so many problems with it unless you modify it. Big Grin
Suggestion: Make the playing area bigger, and let the ghost move even if Pacman isn't. Otherwise wholeGame=veryEasy.
Ok how i do that then?? its due on Friday....tommorow.....so i have no time

if u can, please help
Pages: 1 2