Tabs

Showing posts with label pacman. Show all posts
Showing posts with label pacman. Show all posts

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!!!"