cg@myrias.UUCP (Chris Gray) (01/09/86)
*** rEplAcE thIs lInE wIth yOUr mEssAge ***
Two programs are included here. The first is "robots.bas", which actually
plays the game. The second is "makepic.bas" which is a very simple graphics
editor which you must use to create four pictures:
man - the image you want to use for the player
robot - the image you want to use for the robots
bomb - the image you want to use for the bombs
none - all colour 0 ('a') - used to "undraw" moving things
(kludgy, but attempts at using 'drawmode' and modifying an
existing saved image didn't work. Of course, now that I think
about it, the logical thing to do would have been to do a 'GET'
to create 'n%' from a blank screen region. Sigh.)
"robots" reads these four images in when it starts up.
Robots asks you how many robots you want to start with. Pick any number
between 1 and 100. The challenge is to start at 1 and work up to 100 (you
get more if you clear a screenful.) Before any move in a given screenful,
you can type a '0' to relocate yourself. When playing, use the numeric
keypad to move yourself.
Makepic lets you use the mouse to draw an 8 x 8 image for use with Robots.
Typing keys 'a' - 'p' selects the current drawing colour. 'q' exits the
program, 's' saves the image to a named file, and 'r' restores an image
from a named file.
I apologize for the hacky nature of the programs. ABasiC seems to be one of
those BASIC's that is slowed down by many lines, long identifiers and spaces;
so I kept those to a minimum in order to make the programs as responsive
as possible. (This helps a lot on the Mandelbrot program, too.)
This file was created by copying the files from my Amiga through various
computers until it got to this one, so there shouldn't be any typos. If
you type it in yourself, make darn sure you get all the '%'s in.
I haven't tried it, but the programs were set up so that if you change the
initial values of 'width%' and 'height%' in makepic and 'w%' and 'h%'
correspondingly in robots, the size of the images changes to what you pick.
(Larger size means less 'space' on the screen of course.)
----------------------------------------------------------------------------
Here follows "robots.bas":
----------------------------------------------------------------------------
10 screen 0,4: drawmode 1%: randomize -1%: pena 1%: penb 0%
20 ask window nc%,nl%
30 h%=8% : w%=8%: maxrobots%=100%
40 size%=(w%+15%)/16%*4%*h%+4%
50 dim r%(size%),b%(size%),m%(size%),n%(size%)
60 bload "robot",varptr(r%(0%))
70 bload "man",varptr(m%(0%))
80 bload "bomb",varptr(b%(0%))
90 bload "none",varptr(n%(0%))
100 cc%=int(nc%/w%) : lc%=int((nl%-8%)/h%)
110 dim sc%(cc%,lc%)
120 input "Number of robots: ",nr%
130 if nr%<1% or nr%>maxrobots% then print "Bad value. Try again." : goto 120
140 ' Loop here after clearing a screenful.
150 erase rl%,rc%,dl%,dc%
160 dim rl%(nr%),rc%(nr%),dl%(nr%),dc%(nr%)
170 for c%=0% to cc%-1%
180 for l%=0% to lc%-1%
190 sc%(c%,l%)=0%
200 next l%
210 next c%
220 scnclr
230 for i%=0% to nr%*4%-1%
240 l%=int(rnd*lc%) : c%=int(rnd*cc%)
250 if sc%(c%,l%)<>0% then 240
260 sc%(c%,l%)=2%
270 gshape (c%*w%,l%*h%),b%()
280 next i%
290 for i%=0% to nr%-1%
300 l%=int(rnd*lc%) : c%=int(rnd*cc%)
310 if sc%(c%,l%)<>0% then 300
320 sc%(c%,l%)=3%
330 gshape (c%*w%,l%*h%),r%()
340 rl%(i%)=l% : rc%(i%)=c%
350 next i%
360 l%=int(rnd*lc%) : c%=int(rnd*cc%)
370 if sc%(c%,l%)<>0% then 360
380 sc%(c%,l%)=1%
390 mc%=c% : ml%=l%
400 n%=nr%
410 gshape(mc%*w%,ml%*h%),m%()
420 mv%=0%
430 graphic(1%)
440 print at(0%,nl%-2%);
450 if n%=1% then print " One robot left" : goto 470
460 print using "###"; n%; : print " robots left"
470 graphic(0%)
480 get k$ : if k$="" then 480
490 if mv%=1% then 520
500 if k$="0" then sc%(mc%,ml%)=0%: gshape (mc%*w%,ml%*h%),n%(): goto 360
510 mv%=1%
520 if k$<"1" or k$>"9" then gosub 1350: goto 480
530 on asc(k$)-asc("0") goto 650,670,690,600,620,630,540,560,580
540 if ml%=0% or mc%=0% then gosub 1350: goto 480
550 nml%=ml%-1%:nmc%=mc%-1%:goto 710
560 if ml%=0% then gosub 1350: goto 480
570 nml%=ml%-1%:nmc%=mc%: goto 710
580 if ml%=0% or mc%=cc%-1% then gosub 1350: goto 480
590 nml%=ml%-1%:nmc%=mc%+1%: goto 710
600 if mc%=0% then gosub 1350: goto 480
610 nml%=ml%:nmc%=mc%-1%: goto 710
620 nml%=ml%:nmc%=mc%: goto 710
630 if mc%=cc%-1% then gosub 1350: goto 480
640 nml%=ml%:nmc%=mc%+1: goto 710
650 if ml%=lc%-1% or mc%=0% then gosub 1350: goto 480
660 nml%=ml%+1%:nmc%=mc%-1%: goto 710
670 if ml%=lc%-1 then gosub 1350: goto 480
680 nml%=ml%+1%:nmc%=mc%: goto 710
690 if ml%=lc%-1 or mc%=cc%-1 then gosub 1350: goto 480
700 nml%=ml%+1%:nmc%=mc%+1%
710 gshape (mc%*w%,ml%*h%),n%()
720 sc%(mc%,ml%)=0%
730 mc%=nmc%:ml%=nml%
740 gshape (mc%*w%,ml%*h%),m%()
750 if sc%(mc%,ml%)=0% then sc%(mc%,ml%)=1%: goto 800
760 graphic(1%): pena 1%: penb 0%
770 print at(0%,nl%-2%);
780 if sc%(mc%,ml%)=2% then print "You walked into a mine!!": goto 1150
790 print "You walked into a robot!!": goto 1150
800 ' Move the robots (a bit complicated)
810 d%=0%:k%=0%
820 for i%=0% to nr%-1%
830 c%=rc%(i%):if c%<0% then 1000
840 l%=rl%(i%):x%=sc%(c%,l%)
850 gshape (c%*w%,l%*h%),n%()
860 if x%=5% or x%=7% then sc%(c%,l%)=x%-1% else sc%(c%,l%)=0%
870 dl%=l%-ml%:dc%=c%-mc%
880 if abs(dl%)<=2*abs(dc%) then 900
890 l%=l%-dl%/abs(dl%):goto 930
900 if abs(dc%)<=2*abs(dl%) then 920
910 c%=c%-dc%/abs(dc%):goto 930
920 l%=l%-dl%/abs(dl%):c%=c%-dc%/abs(dc%)
930 x%=sc%(c%,l%):rc%(i%)=c%:rl%(i%)=l%
940 on x%+1% goto 950,960,970,980,970,990,1000,1000
950 sc%(c%,l%)=4%:goto 1000
960 d%=1%:goto 1000
970 dl%(k%)=l%:dc%(k%)=c%:k%=k%+1:sc%(c%,l%)=6%:goto 1000
980 sc%(c%,l%)=5%:goto 1000
990 dl%(k%)=l%:dc%(k%)=c%:k%=k%+1%:sc%(c%,l%)=7%
1000 next i%
1010 if d%<>1% then 1030
1020 graphic(1%):print at(0%,nl%-2%);:print "A robot got you!!";: goto 1150
1030 for i%=0% to nr%-1%
1040 c%=rc%(i%):if c%<0% then 1070
1050 l%=rl%(i%)
1060 if sc%(c%,l%)=6% then rc%(i%)=-1%:n%=n%-1% else gshape (c%*w%,l%*h%),r%(): sc%(c%,l%)=3%
1070 next i%
1080 for i%=0% to k%-1%
1090 sc%(dc%(i%),dl%(i%))=0%
1100 gshape (dc%(i%)*w%,dl%(i%)*h%),n%()
1110 next i%
1120 if n%<>0% then 430
1130 graphic(1%):print at(0%,nl%-2%);
1140 print "You got all the robots!!"
1150 gosub 1350
1160 print at(nc%-8%*11%,nl%-2%);: print "PRESS A KEY"
1170 get k$: if k$="" then 1170
1180 print at(0%,nl%-2%);
1190 for i%=0% to cc% : print " "; : next i%
1200 if n%=0% then 1290
1210 print at(0%,nl%-2%);
1220 print "Another game? "
1230 get k$ : if k$ = "" then 1230
1240 if k$<>"y" and k$<>"n" then 1180
1250 if k$="n" then 1330
1260 nr%=nr%-2%
1270 if nr%<=0% then nr%=1%
1280 goto 1310
1290 nr%=int((nr%+1%)*11%/10%)
1300 if nr%>maxrobots% then nr%=maxrobots%
1310 graphic(0%)
1320 goto 150
1330 screen 1,2
1340 end
1350 drawmode 2%: pena 15%: penb 15%
1360 box (-1%,-1%;nc%,nl%),1%
1370 box (-1%,-1%;nc%,nl%),1%
1380 drawmode 1%
1390 pena 1%: penb 0%
1400 return
----------------------------------------------------------------------------
Here follows "makepic.bas":
----------------------------------------------------------------------------
10 screen 0,4 :graphic 0%: scnclr
20 pena 0%: peno 0%: box (0%,0%;7%,7%),1%
30 height% = 8% : width% = 8% : scale% = 10%
40 size% = (width%+15%)/16%*height%*4%+4%
50 dim save%(size%)
60 ask window nc%, nl%
70 x1% = (nc% - width% * scale%) / 2%
80 x2% = x1% + width% * scale%
90 y1% = (nl% - height% * scale%) / 2%
100 y2% = y1% + height% * scale%
110 c% = 1% : pena 1% : penb 1% : peno 1%
120 box (x1%-1%,y1%-1%;x2%,y2%),0%
130 box (40%,40%;60%,60%),1%
140 get k$
150 if k$ <> "" then goto 240
160 ask mouse x%,y%,b%
170 if b% = 0% then goto 140
180 if x% < x1% or x% >= x2% then goto 140
190 if y% < y1% or y% >= y2% then goto 140
200 x%=int((x%-x1%)/scale%)*scale%+x1% : y%=int((y%-y1%)/scale%)*scale%+y1%
210 box(x%,y%;x%+scale%-1%,y%+scale%-1%),1%
220 draw((x%-x1%)/scale%,(y%-y1%)/scale%),c%
230 goto 140
240 if k$<"a" or k$>"p" then goto 290
250 c%=asc(k$)-asc("a")
260 pena c% : penb c% : peno c%
270 box (40%,40%;60%,60%),1%
280 goto 140
290 if k$<> "s" then goto 380
300 sshape (0%,0%;width%,height%),save%()
310 print at(3%,3%);
320 input "File: ", file$
330 if file$ = "" then goto 350
340 bsave file$, varptr(save%(0%)),size%*4%
350 print at (3%,3%);
360 pena 0%: peno 0%: box (0%,16%;nc%-1%,23%),1%: pena c%: peno c%
370 goto 140
380 if k$<>"q" then goto 410
390 screen 1,2
400 end
410 if k$<>"r" then goto 570
420 print at(3%,3%);
430 input "File: ", file$
440 if file$ = "" then goto 540
450 bload file$,varptr(save%(0%))
460 gshape (0%,0%),save%()
470 for x%=0% to width%-1%
480 for y%=0% to height%-1%
490 c%=pixel(x%,y%)
500 peno c% : pena c% : penb c%
510 box (x1%+x%*scale%,y1%+y%*scale%;x1%+(x%+1%)*scale%-1%,y1%+(y%+1%)*scale%-1%),1%
520 next y%
530 next x%
540 box (40%,40%;60%,60%),1%: print at(3%,3%);
550 pena 0%: peno 0%: box (0%,16%;nc%-1%,23%),1%: pena c%: peno c%
560 goto 140
570 drawmode 2%
580 pena 15%
590 box (-1%,-1%;nc%,nl%),1%
600 box (-1%,-1%;nc%,nl%),1%
610 pena c%
620 drawmode 0%
630 goto 140