Speaking of the RND function, this is the kind of program I was trying to write yesterday. It is a DOG SLOW side scroller.. well, right now it is just a field of stars scrolling from right to left, but the playfield is 40 columns wide while only 28 columns are displayed simultaneously.
Code: Select all
5 CLS
10 DIMH(40)
11 FORI=1TO40
12 H(I)=RND(5)-RND(1)+1
13 NEXTI
14 A$=" "
15 B$=A$
16 C$=A$
17 D$=A$
18 E$=A$
19 I=1
20 J=5
21 GOSUB100
22 A$=RIGHT$(A$,27)+X$
24 GOSUB100
25 B$=RIGHT$(B$,27)+X$
27 GOSUB100
28 C$=RIGHT$(C$,27)+X$
30 GOSUB100
31 D$=RIGHT$(D$,27)+X$
33 GOSUB100
34 E$=RIGHT$(E$,27)+X$
41 POKE218,2
42 POKE219,208
43 PRINTA$
44 PRINTB$
45 PRINTC$
46 PRINTD$
47 PRINTE$
48 I=I+1
49 IFI>40THENI=1
50 GOTO 20
100 X$=" "
105 IFH(I)>=JTHENX$="*"
107 J=J-1
110 RETURN
Apart from running it in Barry's speed hacked Basic which doesn't seem to handle RND like expected, I'm not yet sure which improvements could be made. I regret that strings may not be kept in arrays, even if it would not make any difference on execution speed.
I tried to use PEEK(3) instead of RND but it behaves in the same way re. speeded Basic.
Update 2: Here is an improved listing, which also may run a little fast as I found a way to use the SGN function. It runs in 1983 Basic, haven't tried the 1982 R1 Basic.
Code: Select all
1 L=60
2 DIMH(L)
3 V=1
4 FORI=1TOL
5 R=RND(3)-RND(1)+1
6 IFR=1ANDV>1THENV=V-1
7 IFR=3ANDV<5THENV=V+1
8 H(I)=V
9 NEXTI
10 A$=" "
11 B$=A$
12 C$=A$
13 D$=A$
14 E$=A$
15 X$=" *"
16 I=1
19 CLS
20 A$=RIGHT$(A$,27)+MID$(X$,1+SGN(H(I)>=5),1)
21 B$=RIGHT$(B$,27)+MID$(X$,1+SGN(H(I)>=4),1)
23 C$=RIGHT$(C$,27)+MID$(X$,1+SGN(H(I)>=3),1)
24 D$=RIGHT$(D$,27)+MID$(X$,1+SGN(H(I)>=2),1)
25 E$=RIGHT$(E$,27)+MID$(X$,1+SGN(H(I)>=1),1)
30 POKE218,2
31 POKE219,210
32 PRINTA$
33 PRINTB$
34 PRINTC$
35 PRINTD$
36 PRINTE$
37 I=I+1
38 IFI>LTHENI=1
39 GOTO 20