I would have done this with the box being a RECORD variable in QuickBasic
this BASIC doesn't have that so I'm using multi-dimension arrays.
I never worked with those before and there is something in how they work that I'm missing !!
(its possibly just a STUPID mistake too. !!!)
I've got 2 boxes on the screen but they are somehow ENTANGLED (maybe I'm writing Quantum BASIC..lol)
The ricochets from the sides are locked together and the colors are mixed !!!!
I know I'm saving the boxes correctly because the first several iterations that was messed up.
The program has to know where every box was drawn so it can blank out the last ones.
and that part is working.......
Its bedtime so I'm posting it here..... Maybe someone else can fix it... If not I'll
be back to it in a day or two.....
Code: Select all
10 SCREEN 128
20 RECT 0,0,319,239,16
30 NB = 2: REM NUMBER OF BOXESHAPES ON SCREEN
35 NC = 4: REM NUMBER OF CORNERS FOR THE BOX SHAPES0
40 BD = 8: REM DEPTH TO DRAW BEFORE STARTING ERASURE
45 YLIMIT = 238
50 XLIMIT = 318
60 DIM BX(NB,BD, NC) : REM CORNER X COORDINATES
70 DIM BY(NB,BD, NC) : REM CORNER Y COORDINATES
80 DIM XI(NB, NC) : REM X INCREMENT
90 DIM YI(NB, NC) : REM Y INCREMENT
100 DIM BC(NB) : REM COLOR OF THE BOX
110 P1 = 1 : REM P1, P2 BOX TO DRAW
120 P2 = 1
130 P3 = 1 : REM P3, P4 BOX TO UPDATE
140 P4 = 2
150 P6 = 1 : REM P5, P6 BOX TO DELETE
170 FLAG = 0
180 GOSUB 6000
200 GOSUB 4000
210 GOSUB 3000
220 P1 = P3
230 P3 = P3 + 1:IF P3 > NB THEN P3 = 1
240 GOSUB 4000
250 GOSUB 3000
260 P2 = P4
270 P4 = P4 + 1:IF P4 > BD THEN P4 = 1
280 GOSUB 4000
290 GOSUB 3000
300 IF P4 = BD THEN FLAG = 1
310 IF FLAG = 0 THEN GOTO 200
330 FOR X = 1 TO NB
340 P5 = X
350 GOSUB 5000
360 NEXT X
370 P6 = P6 + 1
380 IF P6 > BD THEN P6 = 1
390 GOTO 220
2999 REM CALCULATE NEXT BOX
3000 FOR C = 1 TO NC
3030 BX(P3, P4, C) = BX(P1,P2,C) + XI(P1,C)
3040 BY(P3, P4, C) = BY(P1,P2,C) + YI(P1,C)
3050 IF BX(P3, P4,C) >= XLIMIT OR BX(P3, P4,C) <=0 THEN GOSUB 3600
3060 IF BY(P3, P4,C) >= YLIMIT OR BY(P3, P4,C) <=0 THEN GOSUB 3700
3070 NEXT C
3080 RETURN
3599 REM RESET X INC
3600 IF BX(P3,P4,C)>XLIMIT THEN BX(P3,P4,C)=XLIMIT
3610 IF BX(P3,P4,C)=XLIMIT THEN XI(P1,C) = -(INT(RND(1)*5)+1)
3620 IF BX(P3,P4,C)<0 THEN BX(P3, P4,C)=0
3630 IF BX(P3,P4,C)=0 THEN XI(P1,C) = INT(RND(1)*5)+1
3640 RETURN
3699 REM RESET Y INC
3700 IF BY(P3,P4,C)>YLIMIT THEN BY(P3,P4,C)=YLIMIT
3710 IF BY(P3,P4,C)=YLIMIT THEN YI(P1,C) = -(INT(RND(1)*5)+1)
3720 IF BY(P3,P4,C)<0 THEN BY(P3,P4,C)=0
3730 IF BY(P3,P4,C)=0 THEN YI(P1,C) = INT(RND(1)*5)+1
3740 RETURN
3999 REM DRAWBOX P1,P2
4000 FOR I = 1 TO NC
4010 X1=BX(P1,P2,I)
4020 Y1=BY(P1,P2,I)
4030 IF I=NC THEN X2=BX(P1,P2,1)
4040 IF I=NC THEN Y2=BY(P1,P2,1)
4050 IF I=NC THEN GOTO 4080
4060 X2=BX(P1,P2,I+1)
4070 Y2=BY(P1,P2,I+1)
4080 LINE X1, Y1,X2,Y2, BC(P1)
4090 NEXT I
4100 RETURN
4999 REM ERASES BOX AT P5, P6
5000 FOR I = 1 TO NC
5010 X1=BX(P5,P6,I)
5020 Y1=BY(P5,P6,I)
5030 IF I=NC THEN X2=BX(P5,P6,1)
5040 IF I=NC THEN Y2=BY(P5,P6,1)
5050 IF I=NC THEN GOTO 5080
5060 X2=BX(P5,P6,I+1)
5070 Y2=BY(P5,P6,I+1)
5080 LINE X1,Y1,X2,Y2, 16
5090 NEXT I
5100 RETURN
5999 REM SETUP VARIABLES
6000 X = INT(RND(-TI))
6005 FOR B = 1 TO NB
6010 BC(B) = INT(RND(1)*255)+1
6020 IF BC(B)=0 OR BC(B)=16 THEN GOTO 6010
6040 FOR C = 1 TO NC
6050 XI(B,C) = INT(RND(1)*5)+1
6060 IF (INT(RND(1)*20)+1) > 10 THEN XI(B,C)= -XI(B,C)
6070 YI(B,C) = INT(RND(1)*5)+1
6080 IF (INT(RND(1)*20)+1) > 10 THEN YI(B,C)= -XI(B,C)
6090 BX(B,1,C) = INT(RND(1)*319) + 1
6100 BY(B,1,C) = INT(RND(1)*239) + 1
6110 NEXT C
6120 NEXT B
6130 RETURN