Dale's Home Page

Dale’s Atari 800 Games › Stan Ockers

Rats' Revenge

By Stan Ockers, in the ACE newsletter of March 1984.

Play Rats' Revenge

Stan’s write-up

I haven't had time to put any special touches on this game, but it should provide a good foundation for any climbing-chase type games. The same approach could be used in a Pac-Man style game. In fact, that's the way this game started out but I think the climbing style is more interesting.

The screen is divided into a matrix of positions, (12X11) where changes of direction can take place. The array ‘allowed’ holds bytes describing which directions are permitted. The lowest four bits contain ‘ones’ for permitted directions which are compliments of the normal joystick directions. The high four bits indicate which type of girder/ladder combination is present at any intersection.

You can create your own scene and save it to disk. The ‘play own’ option will then recall it and you can play it at any level you select. I haven't figured out how to save under a user provided filename yet.

It is quite challenging to provide a proper chase algorithm. In the one I wrote, the rats seem to either ignore you or latch on for dear life. Once they caught on, they were impossible to shake and it was impossible to complete the screen if there was more than one dead end.

I compromised by skipping part of the algorithm at random times. The rats are made to increase their I.Q. with level by comparing a random number to one dependent on the present level. You may notice all three rat moving routines are identical and they should be able to be replaced by one using indexed variables. I tried, but each time I did, the program compiled but locked up when run. Rather than blame the language, I simply took this as an indication I'm still learning to use Action!

—Stan Ockers

Stan Ockers' Rats' Revenge write-up in the March 1984 ACE newsletter
As printed: page 13 of the March 1984 issue.

The program

The listing, “RATS REVENGE IN ACTION! by Stan Ockers”, is on pages 8, 9, 10 of the issue. Stan wrote it in Action!, the compiled language from Optimized Systems Software, and readers needed the Action! cartridge to type it in and compile it. There is no Action! compiler here, so the game page runs a hand translation of the listing into JavaScript: one function for each of Stan’s procedures, with his variable names, sizes and memory addresses, driving the same emulated Atari 800 (its screen, player-missile graphics, collisions and sound) that runs the BASIC games.

Where this copy came from: Written in Action!. The listing was transcribed by hand from the scan (pages 8-10; there is no typed-in copy), and its picture data, character shapes and all three mazes were checked byte for byte against a compiled copy of the game from the Atari archives, along with the start positions and the game loop's timing. The listing as printed has two layout slips that a reader pointed out in the April 1984 issue (page 14, “Typing Aids”): the last six lines of Update sit at the bottom of the next column, and a stray “PROC Rats()” line appears inside Setbar; both are read as that correction says. The game page runs a hand translation of the listing into JavaScript. A maze you build and save goes to “D:MAZE” in your browser instead of a disk; if none is saved yet, PLAY OWN uses the first maze (on the 800 it stopped with ERROR 170).

Show the listing
; RATS REVENGE IN ACTION!
; by Stan Ockers

; ACE Newsletter, 3662 Vine Maple
; Eugene, OR 97405  $12 year
;          March 1984

MODULE ; RATS' REVENGE
  CARD pmbase,dest,source,cnt,source1,
     source2,source3,score,maxscore,
     rndpts,dlist=560
  BYTE pmpage,stk,v,w,col,row,
     vcount=$D40B,consol=53279,dir,all,
     dir1,blkflg,dir2,
     dir3,pos,pos1,pos2,pos3,
     level,dotscnt,hitflg,men,ownflg
  BYTE ARRAY ratup=[0 66 126 60 24 66
   126 90 126 60 36 102 0 0],
   ratrt=[0 32 56 108 62 16 58 126 120
   120 120 44 48 0],ratlt=[0 4 28 54
   124 8 92 126 30 30 28 52 12 0],
   cursor=[34 20 8 20 34],bugup=[0 36
   24 60 126 60 24 60 90 60 24 60
   0 0],bugrt=[0 48 32 120 108
   56 16 56 56 60 56 44 48 0],
   buglt=[0 12 4 30 54 28 8 28 28 60
   28 52 12 0],allowed(132),saveall(133),
   hortop=[3 32 32 32], vertop=[3 32
   6 32],allbot=[3 7 6 7],newall=[3
   135 6 135],horbot=[3 7 7 7],
   dots(132),blk=[3 32 32 32],
   newbot=[3 135 135 135]
  INT delx,dely,delx1,dely1,delx2,
     dely2,delx3,dely3,x,y,x1,y1,
     x2,y2,x3,y3,ax,ay
PROC Init()
  SetBlock(allowed,132,0)
  SetBlock(dots,132,1)
  FOR cnt=1 TO 10
  DO allowed(cnt)=76 OD
  allowed(0)=72 allowed(11)=68
RETURN

PROC Pminit()
  BYTE ARRAY fil=[65 85 65 85 65 85 65
    85 0 0 0 0 255 51 204 255 0 0 255 255
    0 24 60 60 24 0 255 255 0 0 0 0
    0 0 255 255 0 0 0]
  pmpage=Peek(106)-16 pmbase=pmpage*256
  Poke(54279,pmpage) Poke(559,62)
  Poke(53277,3) Poke(53248,x) Poke(704,92)
  Poke(705,202) Poke(706,250) Poke(707,186)
  SetBlock(pmbase+1024,1024,0)
  Moveblock(pmbase,57344,1024)
  Poke(756,pmpage)
  FOR cnt=0 TO 39
  DO Poke(pmbase+cnt+560,fil(cnt)) OD
  FOR cnt=6 TO 28
  DO Poke(dlist+cnt,4) OD
RETURN

PROC Ding(BYTE pitch,CARD dly)
  BYTE loud
  CARD wait
   FOR loud=0 TO 15
   DO Sound(0,pitch,10,15-loud)
     FOR wait=1 to dly DO OD OD
   Sndrst()
RETURN

PROC Tracks() ; leave trail
  BYTE newpos,z
 IF newpos<>pos THEN
  newpos=pos v=pos MOD 12 w=pos/12
  z=Locate(3*v+2,2*w+2)
  IF z=7 THEN
    rndpts==+25 Position(21,0)
    PrintC(rndpts)
    Position(3*v+2,2*w+2) dotscnt==-1
    IF allowed(pos)&64 THEN Print(newbot)
    ELSEIF allowed(pos)&16 THEN
       Print(newall) FI FI FI
RETURN
PROC Move() ; move the bug
  stk=Stick(0) ! 15
  IF (y-10) MOD 16=0 AND (x-22) MOD 12=0 THEN
   row=(y-42)/16 col=(x-56)/12
   pos=12*row+col all=allowed(pos)&15
   IF stk=8 AND dir=4 THEN dir=8
   ELSEIF stk=4 AND dir=8 THEN dir=4
   ELSEIF stk=1 AND dir=2 THEN dir=1
   ELSEIF stk=2 AND dir=1 THEN dir=2
   FI
   IF (dir & 3)>0 THEN stk==& 12
   ELSE stk==& 3 FI
   IF(stk & all)>0 THEN dir=stk FI
   WHILE (dir & all)=0
   DO dir=dir RSH 1
      IF dir=0 THEN dir=8 FI OD
   IF dir=1 THEN dely=-1 delx=0
          source=bugup
   ELSEIF dir=2 THEN dely=1 delx=0
          source=bugup
   ELSEIF dir=4 THEN dely=0 delx=-1
          source=buglt
   ELSEIF dir=8 THEN dely=0 delx=1
          source=bugrt FI FI
   x==+delx y==+dely
RETURN

 PROC Move1() ; decide rat #1 movement
  BYTE num,col1,row1
  IF (y1-10) MOD 16=0 AND (x1-22) MOD 12=0 THEN
   row1=(y1-42)/16 col1=(x1-56)/12
   pos1=12*row1+col1 all=allowed(pos1)
   IF Rand(15)>10-level THEN
     ax=x-x1 IF ax<0 THEN ax=-ax FI
     ay=y-y1 IF ay<0 THEN ay=-ay FI
     IF ax>ay THEN
       IF (x1>x) THEN dir1=4
       ELSEIF (x1<x) THEN dir1=8 FI
     ELSE
       IF (y1<y) THEN dir1=2
       ELSEIF (y1>y) THEN dir1=1 FI FI
   FI
   WHILE (dir1 & all)=0
   DO dir1=dir1 RSH 1
     IF dir1=0 THEN dir1=8 FI OD
   IF dir1=1 THEN dely1=-1 delx1=0
        source1=ratup
   ELSEIF dir1=2 THEN dely1=1 delx1=0
        source1=ratup
   ELSEIF dir1=4 THEN dely1=0 delx1=-1
        source1=ratlt
   ELSEIF dir1=8 THEN dely1=0 delx1=1
        source1=ratrt FI FI
 RETURN

 PROC Move2()
  BYTE num,col2,row2
  IF (y2-10) MOD 16=0 AND (x2-22) MOD 12=0 THEN
   row2=(y2-42)/16 col2=(x2-56)/12
   pos2=12*row2+col2 all=allowed(pos2)
   IF Rand(15)>10-level THEN
     ax=x-x2 IF ax<0 THEN ax=-ax FI
     ay=y-y2 IF ay<0 THEN ay=-ay FI
     IF ax>ay THEN
       IF (x2>x) THEN dir2=4
       ELSEIF (x2<x) THEN dir2=8 FI
     ELSE
       IF (y2<y) THEN dir2=2
       ELSEIF (y2>y) THEN dir2=1 FI FI
   FI
   WHILE (dir2 & all)=0
   DO dir2=dir2 RSH 1
     IF dir2=0 THEN dir2=8 FI OD
   IF dir2=1 THEN dely2=-1 delx2=0
        source2=ratup
   ELSEIF dir2=2 THEN dely2=1 delx2=0
        source2=ratup
   ELSEIF dir2=4 THEN dely2=0 delx2=-1
        source2=ratlt
   ELSEIF dir2=8 THEN dely2=0 delx2=1
        source2=ratrt FI FI
RETURN

PROC Move3()
  BYTE num,col3,row3
  IF (y3-10) MOD 16=0 AND (x3-22) MOD 12=0 THEN
   row3=(y3-42)/16 col3=(x3-56)/12
   pos3=12*row3+col3 all=allowed(pos3)
   IF Rand(15)>10-level THEN
     ax=x-x3 IF ax<0 THEN ax=-ax FI
     ay=y-y3 IF ay<0 THEN ay=-ay FI
     IF ax>ay THEN
       IF (x3>x) THEN dir3=4
       ELSEIF (x3<x) THEN dir3=8 FI
     ELSE
       IF (y3<y) THEN dir3=2
       ELSEIF (y3>y) THEN dir3=1 FI FI
   FI
   WHILE (dir3 & all)=0
   DO dir3=dir3 RSH 1
     IF dir3=0 THEN dir3=8 FI OD
   IF dir3=1 THEN dely3=-1 delx3=0
        source3=ratup
   ELSEIF dir3=2 THEN dely3=1 delx3=0
        source3=ratup
   ELSEIF dir3=4 THEN dely3=0 delx3=-1
        source3=ratlt
   ELSEIF dir3=8 THEN dely3=0 delx3=1
        source3=ratrt FI FI
RETURN

PROC Update() ; all players move
  DO UNTIL vcount=128 OD
  Poke(53248,x) dest=pmbase+1024+y
  MoveBlock(dest,source,14)
  x1==+delx1 y1==+dely1 Poke(53249,x1)
  dest=pmbase+1280+y1
  MoveBlock(dest,source1,14)
  x2==+delx2 y2==+dely2 Poke(53250,x2)
  dest=pmbase+1536+y2
  MoveBlock(dest,source2,14)
  x3==+delx3 y3==+dely3 Poke(53251,x3)
  dest=pmbase+1792+y3
  MoveBlock(dest,source3,14) Tracks()
RETURN

PROC Bkgd() ; draw ladders & girders
  Graphics(0) Poke(752,1)
  FOR pos=0 TO 131
  DO x=pos MOD 12 y=pos/12
    all=allowed(pos)
    Position(3*x+2,2*y+1)
    IF all&48 THEN Print(vertop)
    ELSE Print(blk) FI
    Position(3*x+2,2*y+2)
    IF all&64 THEN Print(horbot)
    ELSEIF all&32 THEN Print(vertop)
    ELSEIF all&16 THEN Print(allbot)
    ELSE Print(blk) FI OD
  FOR x=1 TO 38
  DO Position(x,23) Put(13) OD
RETURN

PROC Dly(CARD maxcnt)
  CARD cnt
  FOR cnt=1 to maxcnt DO OD
RETURN

PROC Savemaze()
  Open(1,"D:MAZE",8,0)
  FOR pos=0 TO 132
  DO saveall(pos+1)=allowed(pos) OD
  saveall(0)=132 PrintD(1,saveall)
  Close(1)
RETURN

PROC Cleanscr() ; get rid of players
  FOR cnt=53248 TO 53251
    DO Poke(cnt,0) OD
RETURN

PROC Openup() ; pos. above permitted
  IF allowed(pos-12) & 112 THEN
  allowed(pos-12)==%2 allowed(pos)==%1
  FI RETURN

PROC Opendn()
  IF allowed(pos+12) & 48 THEN
  allowed(pos+12)==%1 allowed(pos)==%2
  FI RETURN

PROC Openlt()
  IF allowed(pos-1) & 80 THEN
  allowed(pos-1)==%8 allowed(pos)==%4
  FI RETURN

PROC Openrt()
  IF allowed(pos+1) & 80 THEN
  allowed(pos+1)==%4 allowed(pos)==%8
  FI RETURN

PROC Setbar() ; create screen
  BYTE key
  x=70 y=61 source=cursor
  dest=pmbase+1024+y Poke(764,255)
  SetBlock(pmbase+1024,256,0)
  Position(0,0)
  Print("(1) (2){14}(3)|(4){24}(5)Save")
  Print("(6)Exit (arrows)")
PROC Rats()
  DO
  Poke(53248,x) dest=pmbase+1024+y
  MoveBlock(dest,source,5)
   DO key=Peek(764)
    UNTIL key<>255 OD
  SetBlock(dest,5,0) Poke(764,255)
  IF key=15 AND y<181 THEN y==+16
  ELSEIF key=14 AND y>61 THEN y==-16
  ELSEIF key=7 AND x<178 THEN x==+12
  ELSEIF key=6 AND x>70 THEN x==-12
  FI
  IF consol=5 THEN EXIT FI
  col=(x-58)/12 row=(y-45)/16
  pos=12*row+col
  Position(3*col+2,2*row+1)
  IF key=31 THEN
  Print(blk) allowed(pos)=0
    allowed(pos-1)==&247
    allowed(pos+1)==&251
    allowed(pos-12)==&253
    allowed(pos+12)==&254
  ELSEIF key=30 THEN
    allowed(pos)=64 allowed(pos-12)==&253
    Openrt() Openlt() Opendn()
    Print(hortop)
  ELSEIF (key=26) THEN
    allowed(pos)=32 allowed(pos-1)==&247
    allowed(pos+1)==&251 Openup()
    Opendn() Print(vertop)
  ELSEIF (key=24) THEN
    allowed(pos)=16 Openup() Opendn()
    Openlt() Openrt() Print(vertop)
  FI
  Position(3*col+2,2*row+2)
  IF key=31 THEN Print(blk)
  ELSEIF key=30 THEN Print(horbot)
  ELSEIF key=26 THEN Print(vertop)
  ELSEIF key=24 THEN Print(allbot)
  FI
  IF key=29 THEN Savemaze() FI
  IF key=27 THEN EXIT FI
  DO UNTIL PEEK(764)<>key OD
OD
RETURN

PROC Loadmaze()
  Open(1,"D:MAZE",4,0) InputSD(1,saveall)
  SCopyS(allowed,saveall,2,132)
  allowed(0)=saveall(1) Close(1)
RETURN

PROC Contact() ; hit a rat
  FOR v=50 to 200 STEP 5
    DO Ding(v,v) OD
  hitflg=1
RETURN

PROC Rndover() ; completed screen
  FOR v=50 to 200 STEP 5
    DO Ding(250-v,v) OD
RETURN

PROC Gameover()
  Graphics(18) Position(6,4)
  PrintD(6,"G{inv}Am{/inv}e {inv}O{/inv}vE{inv}r{/inv}")
  Position (0,9)
  PrintD(6,"press START to play")
  DO UNTIL consol=6 OD
  DO UNTIL (consol&7)=7 OD RETURN

PROC Scorecard()
  Position(0,0) Print("MEN=") PrintB(men)
  Position(6,0) Print("SCORE=")
  PrintC(score) Position(17,0)
  Print("Rnd=") PrintC(rndpts)
  Position(26,0) Print("HI=")
  PrintC(maxscore) Position(33,0)
  Print("LVL=") PrintB(level)
RETURN

PROC Play()
BYTE ARRAY lvl1=[72 78 76 76 78 76 76
78 76 76 78 68 0 35 0 0 35 0 0 35 0 0
35 0 0 25 76 78 21 0 0 25 78 76 21 0
0 0 0 35 0 0 0 0 35 0 0 0 0 0 74 29 78
76 76 78 29 70 0 0 0 0 35 0 35 0 0 35
0 35 0 0 0 0 25 78 21 0 0 25 78 21 0 0
0 0 0 35 74 76 76 70 35 0 0 0 0 0 0 35
35 0 0 35 35 0 0 0 0 0 0 25 29 76 76
29 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],
lvl4=[72 78 76 76 78 76 78 76 76 76 78
68 0 25 76 76 23 0 27 76 76 76 21 0 0
0 0 0 27 76 23 0 0 0 0 0 0 74 76 76 31
76 31 76 76 76 70 0 0 25 76 76 23 0 27
76 76 76 21 0 0 0 0 0 27 76 23 0 0 0 0
0 0 74 76 76 31 76 31 76 76 76 70 0 0
25 76 76 23 0 27 76 76 76 21 0 0 0 0 0
27 76 23 0 0 0 0 0 0 0 0 72 29 76 29
68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],
lvl7=[72 78 76 78 76 78 78 76 78 76 78
68 0 25 78 29 78 21 35 0 35 0 35 0 0
74 29 78 29 78 29 78 29 78 21 0 0 35
0 35 0 35 74 29 78 29 70 0 0 25 78 29
78 21 35 0 35 0 35 0 0 74 29 78 29 78
29 78 29 78 21 0 0 35 0 35 0 35 74 29
78 29 70 0 0 25 78 29 78 21 35 0 35 0
35 0 0 0 35 0 35 0 25 78 29 78 21 0 0
72 29 76 29 76 76 29 76 29 68 0 0 0 0
0 0 0 0 0 0 0 0 0]
  DO
    IF ownflg=0 THEN
      IF level>0 AND level<4 THEN
      FOR v=0 TO 132
      DO allowed(v)=lvl1(v) OD
      ELSEIF level>3 AND level<7 THEN
      FOR v=0 TO 132
      DO allowed(v)=lvl4(v) OD
      ELSEIF level>6 THEN
      FOR v=0 TO 132
        DO allowed(v)=lvl7(v) OD FI FI
    Bkgd() Pminit() Scorecard()
    x=56 y=42 dir=8 source=ratrt
    SetBlock(pmbase+1024,1024,0)
    y1=42 dir1=4 source1=ratlt
    source2=ratlt
    y2=42 dir2=4 delx=1
    y3=42 dir3=4 source3=ratlt
    pos=0 pos1=11 pos2=11 pos3=11
    dely=0 dely1=0 dely2=0 dely3=0
    delx1=-1 delx2=0 delx3=0 x1=184
    x2=0 x3=0 dotscnt=0
    FOR cnt=0 to 131
      DO w=allowed(cnt)
        IF w&80 THEN dotscnt==+1 FI OD
    w=(level-1)MOD 3
    IF w>0 THEN x2=184 delx2=-1 FI
    IF w>1 THEN x3=184 delx3=-1 FI
    DO FOR cnt=1 TO 10-level
      DO DO UNTIL vcount=1 OD
      UNTIL vcount=128 OD
    Move() Move1() Move2()
    Move3() Update()
    IF dotscnt=0 THEN Rndover()
      EXIT FI
    IF((x=x1)AND(y=y1))OR
      ((x=x2)AND(y=y2))OR
      ((x=x3)AND(y=y3)) THEN
      Contact() EXIT FI
    Poke(77,0)
    OD
  Cleanscr()
  IF dotscnt=0 THEN level==+1
    IF level=10 THEN level=9 FI
    score==+rndpts rndpts=0
    IF maxscore<score THEN
       maxscore=score FI
  ELSEIF hitflg=1 THEN men==-1
    rndpts=0
    IF men=0 THEN Gameover() EXIT FI
  FI
  OD
RETURN

PROC Rats()
  DO
    Graphics(18) Position(4,1)
    PrintD(6,"Ra{inv}tS{/inv}' {inv}R{/inv}eV{inv}eN{/inv}Ge")
    Position(6,3) PrintDE(6," {inv}*{/inv} REGULAR")
    PrintD(6,"option   CREATE")
    Position(9,5) PrintDE(6,"PLAY OWN")
    Position(0,7)
    PrintD(6,"select LVL {inv}1{/inv}23456789")
    Position(0,9) PrintD(6,"start")
    Position(1,11) Poke(dlist+16,6)
    PrintD(6,"WRITTEN IN {inv}ACTION!{/inv}")
    w=3 level=1 ownflg=0 score=0
    maxscore=0 rndpts=0 men=3
    DO
    DO UNTIL(consol&7)<>7 OD
    IF consol=3 THEN position(7,w)
      PutD(6,32) w==+1
      IF w=6 THEN w=3 FI
      Position(7,w) PutD(6,170)
      Ding(121,600)
    ELSEIF consol=5 THEN
      Position(10+level,7)
      PutD(6,48+level) level==+1
      IF level=10 THEN level=1 FI
      Position(10+level,7)
      PutD(6,176+level) Ding(60,600)
    ELSEIF consol=6 THEN
      IF w=4 THEN Init() Bkgd()
        Pminit() Setbar() Cleanscr()
        EXIT
      ELSEIF w=5 THEN Loadmaze()
        ownflg=1 Play() ownflg=0
        Cleanscr() EXIT
      ELSEIF w=3 THEN
        Play() Cleanscr() EXIT
      FI
    FI
    DO UNTIL(consol&7)=7 OD OD OD
RETURN

Play Rats' Revenge