Box-In

Type
Game
Category
Arcade strategy game (trap the monster with boxes)
Author
J. D. Casten
Published in
Antic, December 1985 (Vol. 4, No. 8)
Year
1985
Language
Atari BASIC (with a short machine-language string)
Requirements
Any Atari 8-bit, Atari BASIC, joystick in port 1
A purple room with a dark red wall, scattered with about a hundred small orange boxes, Harold at top left, Gruck in green at bottom right and a TIME counter below

About the program

J. D. Casten of Eugene, Oregon, wrote a string of Antic hits, including Risky Rescue, Escape From Epsilon and Biffdrop. The December 1985 article tells how the editors, nagging him for another game, learned that his very first game, Box-In, had been accepted back in 1983, when he was a high-school freshman. Nobody at the magazine could find it, apart from a note in a file that it had been accepted. Casten sent a new copy, and within minutes of booting it the editors decided to print it.

Crazy Harold loves a thrill, so he has shut himself in a room with Gruck, a "yucky green Harold-eating monster", and 100 monster-repellent boxes. Harold has to push the boxes around Gruck until the monster can't move in any direction, diagonals included. Gruck isn't fast, but he never stops coming. The article recommended it even to people who dislike arcade games, because it takes so much strategy.

Typing it in

The program is only 43 lines. Line 500 holds a machine-language routine in a string, which copies the character set into RAM. Type it exactly: {inv}…{/inv} is inverse video (press the Atari key before and after), {CTRL-E} means hold CTRL and press E, and {CTRL-,}/{CTRL-.} are CTRL with comma and full stop. Line 510's scrolling message and line 515's title also use inverse and control characters. The magazine printed TYPO II codes for checking.

Two oddities are deliberate. The program never sets N, so it is always 0 and serves as a short zero. And COM D$(86) in line 505 is legal: COM is an old synonym for DIM in Atari BASIC.

How to play

Press SELECT to choose a difficulty from 1 to 5. A higher difficulty means fewer moves for Harold for each step Gruck takes. Press START, then move Harold with the joystick in all eight directions. Walking into a box pushes it, and a whole line of boxes moves if there's a space at the end. Surround Gruck completely to win ("YOU TRAPED HIM"). The time counter shows how long you took. If Gruck reaches you, you lose. Press START to play again.

How it works

  • Harold moves W times (W=D*2-1) for every step Gruck takes. Gruck moves one square toward Harold using SGN(X-H) and SGN(Y-V), and tries the other axis if a box is in the way (lines 155–185).
  • The joystick is read straight from location 632 and turned into X and Y steps with logical expressions (line 155).
  • Lines 190–195 use LOCATE on all eight squares round Gruck. If every one is a box, the wall or Harold, the monster is trapped.
  • The clicks as Harold and Gruck move come from writing straight to POKEY (POKE 53767) and to the console speaker (POKE 53279).

Listing

1 REM BOX-IN
2 REM BY J.D. CASTEN (Dec. 4, 1982)
3 REM FOR ANTIC PUBLISHING
5 POKE 559,N:GOTO 500
100 FOR I=1 TO W:POSITION 12,23:? #6;PEEK(19);:IF S=15 THEN 155
105 C=71-C:LOCATE X,Y,L:IF L=32 THEN 145
110 IF L=161 THEN 125
115 IF L=132 THEN X=OX:Y=OY:GOTO 150
120 GOTO 400
125 X1=(OX<X)-(OX>X):Y1=(OY<Y)-(OY>Y):X2=X:Y2=Y
130 X2=X2+X1:Y2=Y2+Y1:LOCATE X2,Y2,Z:IF Z=161 THEN 130
135 IF Z=32 THEN COLOR 161:PLOT X2,Y2:GOTO 145
140 X=OX:Y=OY:GOTO 150
145 COLOR 32:PLOT OX,OY:POKE 53767,143:POKE 53767,N
150 COLOR C:PLOT X,Y:OX=X:OY=Y
155 S=PEEK(632):X=X+(S<8)-(S>8 AND S<13):Y=Y+(S=9 OR S=13 OR S=5)-(S=10 OR S=14 OR S=6):NEXT I:H=H+SGN(X-H)
170 V=V+SGN(Y-V):LOCATE H,V,L9:IF (H=OX AND V=OY) OR L9=C THEN 400
175 IF L9=32 THEN 185
180 J=H:H=OH:LOCATE H,V,L9:IF L9>128 THEN V=OV:H=J:LOCATE H,V,L9:IF L9>128 THEN H=OH:GOTO 190
185 IF H<>OH OR V<>OV THEN COLOR 32:PLOT OH,OV:OH=H:OV=V:POKE 53279,N:COLOR 3:PLOT H,V
190 FOR J=-1 TO 1:FOR I=-1 TO 1:LOCATE H+J,V+I,L1:IF L1=3 OR L1=161 OR L1=132 THEN NEXT I:NEXT J:GOTO 200
195 GOTO 100
200 TI=PEEK(19):POSITION 3,22:? #6;"YOU TRAPED HIM":FOR J=N TO 255 STEP 0.5:SOUND N,J,12,15:NEXT J:POKE 53761,N
205 POSITION 3,22:? #6;"  PRESS START ":IF PEEK(53279)<>6 THEN 205
210 TRAP 515
300 FOR J=N TO 23:COLOR 32:PLOT N,J:DRAWTO 19,J:SOUND N,30-J,8,8:NEXT J:POKE 53761,N:RETURN
400 POSITION 6,22:? #6;"YOU LOSE":COLOR 32:PLOT OH,OV:COLOR 3:PLOT OX,OY:FOR J=N TO 255:SOUND N,J,8,15
405 IF J<16 THEN POKE 712,15-J
410 NEXT J:POKE 53761,N:GOTO 205
500 A=PEEK(106)-2:POKE 106,A:GRAPHICS 17:POKE 756,A:A=A*256:X=USR(ADR("h{inv}){/inv}{CTRL-,}{inv}{CTRL-E}K{CTRL-E}M){CTRL-.}{CTRL-E}L%{/inv}j{inv}{CTRL-E}N"{/inv}{CTRL-B}{inv} {/inv}{CTRL-,}{inv}1K{CTRL-Q}M{CTRL-H}PyfLfNJPp{/inv}{CTRL-.}"))
505 FOR J=8+A TO 48+A:READ B:POKE J,B:NEXT J:POKE 559,34:COM D$(86):POKE 708,28:POKE 709,200:POKE 710,154
510 POKE 711,86:D$="%{inv}press {/inv}START{inv} to play box{CTRL-M}in  !  press {/inv}SELECT{inv} to change the difficulty{/inv}{CTRL-C}{inv}       {/inv}%{inv}press {/inv}ST":D=5
515 POSITION 5,7:? #6;"{inv}!{/inv}!{inv}bo{/inv}x{CTRL-M}{inv}in{/inv}!{inv}!{/inv}":POSITION 4,9:? #6;"by jd casten":POSITION 2,3:? #6;"%{inv}!!!{/inv}":POSITION 15,2
520 ? #6;"{inv}!!!{/inv}":POSITION 15,3:? #6;"{inv}!{/inv}{CTRL-C}{inv}!{/inv}":POSITION 15,4:? #6;"{inv}!!!{/inv}":COLOR 161:PLOT N,N:DRAWTO 19,N:DRAWTO 19,21
525 DRAWTO N,21:DRAWTO N,N:PLOT 4,15:DRAWTO 15,15:DRAWTO 15,17:DRAWTO 4,17:PLOT 4,16
530 FOR J=1 TO 77:POSITION 5,16:? #6;D$(J,J+9):I=P:P=PEEK(53279):IF P=5 AND I<>P THEN D=D-1:IF D=N THEN D=5
535 IF P<>6 THEN FOR K=1 TO 15:NEXT K:POSITION 4,11:? #6;"DIFFICULTY:";6-D:NEXT J:GOTO 530
540 GOSUB 300:COLOR 132:PLOT N,N:DRAWTO 19,N:DRAWTO 19,21:DRAWTO N,21:DRAWTO N,N:POKE 53768,5:POSITION 7,23
545 ? #6;"TIME:";:COLOR 161:FOR J=1 TO 100:X=INT(RND(0)*18+1):Y=INT(RND(0)*20+1):PLOT X,Y:SOUND N,8,10,8
550 POKE 53761,N:NEXT J:FOR J=15 TO N STEP -0.2:SOUND N,J,10,J:NEXT J:C=34:H=18:V=20:OH=H:OV=V:X=1:Y=X:OX=X:OY=Y
560 COLOR 34:PLOT X,Y:COLOR 3:PLOT H,V:S=15:W=D*2-1:POKE 19,N:POKE 20,N:GOTO 100
900 DATA 255,129,189,165,165,189,129,255,28,28,9,127,92,28,52,6,66,36,60,90,60,66,189,129,255,255,255,255,255,255
910 DATA 255,255,56,56,144,254,58,56,44,96,0

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: BOXIN.BAS.

Credits