Tabs

Pacman on graphing calculator


The title says it all-   I was bored in math class for most of junior year, so i learned how to write programs on the ti-83 graphing calculators.  This is an imitation of the classic arcade Pac-Man game, with a small playing field, and only one ghost.  It was written completely on the calculator, and the splash image was drawn pixel by pixel with the ptOn() and ptOff() functions in the draw menu.  enjoy!

Source code is very very long,
but you can see it here if you'd like!

EDIT: This program requires Matrix [J] from internal storage to be at least 8x16.
Manually set Matrix [J] to the following in order to avoid index out of bounds errors:
1 1 1 25 1 1 1 1 1 1 1 25 1 1 1 1
1 2 2 2 2 2 1 1 1 2 2 2 2 2 2 1
1 2 1 1 1 2 2 2 2 2 1 1 1 1 2 1
24 2 1 2 2 2 1 0 1 2 2 2 2 2 2 26
1 2 2 2 1 1 1 0 1 1 1 2 2 1 2 1
1 2 1 2 2 2 1 1 1 2 2 2 1 1 2 1
1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1
1 1 1 1 1 34 1 1 1 1 1 34 1 1 1 1 


Remove RecallPic 1 line if there isn't a splash screen image saved.

ClrHome
CoordOff
GridOff
AxesOff
LabelOff
DelVar Y1
DelVar Y2
DelVar Y3
ClrDraw
RecallPic 1 //only if you have the logo downloaded as pic 1
Pause
Goto 0
Lbl 0
ClrHome
AxesOn
LabelOn
ClrDraw
Menu("    PAC-MAN!    ","PLAY",1,"QUIT",2)
Lbl 1
ClrHome
0->S                    //score
0->[ J ](4,8)
For(R,1,8)
   For(C,1,16)
      If [ J ](R,C) = 3
         2->[ J ](R,C)
      If [ J ](R,C) = 1
         Output(R,C,"0")
      If [ J ](R,C) = 2
      Then
         Output(R,C,"+")
         S+1->S
      End
   End
End
Pause
7->Y   //player coordinates
8->X   //player coordinates
5->N   //AI coordinates
8->M   //AI coordinates
5->T   //AI buffer coordinates
8->W   //AI buffer coordinates
0->D   //AI direction vector
 x-1->E   //AI direction vector y
10->A   //AI countdown
While S>0
getKey->K
X->U   //player buffer coordinates
Y->V   //player buffer coordinates
0->Z
[ J ](Y,X) -> I

If I >= 24 and I //warp point section
Then
   1->Z
   If I=24 and K=24
      16->X
   If I=25 and K=25
   Then
       If X=4
       Then
          6->X
          8->Y
      End
      If X=12
          8->Y
   End
   If I=26 and K=26
      1->X
   If I=34 and K=34
   Then
      If X=6
      Then
          4->X
          1->Y
       End
       If X=12
          1->Y
   End
   If I != K
      0->Z
End

If Z=0         //Basic Player Move Section
Then
   If K=24
   Then
      If [ J ](Y,X-1) != 1
         X-1->X
   End
   If K=25
   Then
      If [ J ](Y-1,X) != 1
         Y-1->Y
   End
   If K=26
   Then
      If [ J ](Y,X+1) != 1
         X+1->X
   End
   If K=34
   Then
      If [ J ](Y+1,X) != 1
         Y+1->Y
   End
End
A-1->A             //AI start-up section
If A=2
   N-1->N
If A=1
Then
   1 -> [ J ](N,M)
   Output(N,M,"0")
   N-1->N
End
If A=0               //Main AI section
Then
   1->A
   M->W
   N->T
   If (X-M)!=0
      ((X-M)/abs(X-M))->R
   If(Y-N)!=0
      ((Y-N)/abs(Y-N))->C
    2->H
   If E!=0
      1->H
   If H=1
   Then
      R->D
      0->E
      If [ J ](N,M+R) = 1
      Then
         0->D
         C->E
         If [ J ](N+C,M) = 1
         Then
            -R->D
            0->E
            If [ J ](N, M-R) = 1
            Then
               0->D
               -C->E
             End
          End
       End
    End

   If H=2
   Then
      0->D
      C->E
      If [ J ](N+C,M) = 1
      Then
         R->D
         0->E
         If [ J ](N,M+R) = 1
         Then
            0->D
            -C->E
            If [ J ](N-C, M) = 1
            Then
               -R->D
               0->E
             End
          End
       End
    End
    M+D->M
    N+E->N
End
If [ J ](Y,X) = 2
Then
   S-1->S
   3-> [ J ](Y,X)
End
If X=M and Y=N
   Goto L
Output(1,14,S)
Output(V,U,"_")
Output(Y,X,"e")
Output(T,W,"_")
If [ J ](T,W)=2
   Output(T,W,"+")
End
ClrHome
Disp "YOU WIN!"
Pause
Goto0
Lbl L
ClrHome
Disp "LOOOOOSERRR!!!"

21 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Nice, thats a lot of typing! I did forget to mention, the way this program works is by referencing a 8x16 matrix for the level (same size as screen): a 1 is a wall, a 3 is a blank space and a 2 is a coin/food thing (it could be backwards, i'm not sure) 23, 24, 25 and 26 represent the exits. This is the pacman matrix:
    1 1 1 25 1 1 1 1 1 1 1 25 1 1 1 1
    1 2 2 2 2 2 1 1 1 2 2 2 2 2 2 1
    1 2 1 1 1 2 2 2 2 2 1 1 1 1 2 1
    24 2 1 2 2 2 1 0 1 2 2 2 2 2 2 26
    1 2 2 2 1 1 1 0 1 1 1 2 2 1 2 1
    1 2 1 2 2 2 1 1 1 2 2 2 1 1 2 1
    1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1
    1 1 1 1 1 34 1 1 1 1 1 34 1 1 1 1

    i might've messed up a few numbers, but you should see it in the game if that happens! Enjoy!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Uh.. When I start the game I automatically win. Help!

    ReplyDelete
  5. I put this on my ti83 but it just came back with a syntax error at 0->[J](4,8)

    ReplyDelete
    Replies
    1. You put the J inside 2 brackets. Instead, use matrix. Go to the matrix menu, and select [J]. It should all be grouped together. Do that for every [J].

      Delete
  6. Too many errors, pls review the code, could it be that this source code isn't compatible with ti 84 plus?

    ReplyDelete
  7. This source code gives me too many domain errors. Can you please show us the code you used on YouTube? Please!!!!!!

    ReplyDelete
  8. He's not going to tell you because he is too busy with the rest of his life. :( But I have a pacman source code!!

    ReplyDelete
  9. How do you do the _ on a ti-84?

    ReplyDelete
    Replies
    1. do a 10*26 matrix instead-or, or you can do it on you graph screen if you're courageous

      Delete
  10. when i start it it pops up start and quit then when i press start it pops up syntax error please help

    ReplyDelete
  11. When I tried to put this into my TI-83 Plus calculator, it kept saying this part has a either a syntax error or a invalid dim error:
    If (X-M)!=0
    ((X-M)/abs(X-M))->R
    If(Y-N)!=0
    ((Y-N)/abs(Y-N))->C
    2->H
    If E!=0
    1->H
    If H=1
    ...
    If [ J ](N,M+R) = 1
    Then
    0->D
    C->E
    If [ J ](N+C,M) = 1
    Then
    -R->D
    0->E
    If [ J ](N, M-R) = 1
    ...
    If [ J ](N+C,M) = 1
    Then
    R->D
    0->E
    If [ J ](N,M+R) = 1
    Then
    0->D
    -C->E
    If [ J ](N-C, M) = 1
    Is there any way to fix this? I tried, but it wouldn't work.

    ReplyDelete
    Replies
    1. There's a domain error at If (X-M)!=0 and at If (X-M)!=0. How do I fix this?

      Delete
  12. in the movement part of the code, where it says "If [ J ](Y,X-1)!=1" you put it as a typo, its supposed to say "If [ J ](Y,X-1)!=2" because if it says "If [ J ](Y,X-1)!=1" you eat the walls instead of the orbs

    ReplyDelete