WINDOWS MYSTIFY CLONE....ALMOST WORKING

Talk about your programs in progress. Discuss how to implement features, etc.
Forum rules
This section is for testing Commander X16 programs and programs related to the CX16 for other platforms (compilers, data conversion tools, etc.)

Feel free to post works in progress, test builds, prototypes, and tech demos.

Finished works go in the Downloads category. Don't forget to add a hashtag (#) and the version number your program was meant to run on. (ie: #R41).
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

Well In about 5 hrs I've got it kinda sorta working......
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 

kelli217
Posts: 531
Joined: Sun Jul 05, 2020 11:27 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by kelli217 »

It looks pretty good to me. I can't quite tell what the problems are with it, even after you've described them.

I look forward to the assembly version. :D
mwiedmann
Posts: 70
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by mwiedmann »

Very cool! I threw it into a file for the web emulator. Works great.

Try It Now!
Attachments
MYSTIFY.BAS
(2.9 KiB) Downloaded 352 times
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

An assembly version from me is not likely... lol.
I just might try to redo it in C.

I want to get the basic version logic working, with the most readable possible code.

Then I'm going to see how much difference a full optimization of the basic code makes
in performance. (loop unrolling, elimination of GOSUB by putting the code inline, minimizing GOTO'S)
I have the feeling a full optimization is going to make the code somewhat obfuscated.
void_null

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by void_null »

There's an error in line 390: its pointing to line 220, which doesn't exist. Changing it to 230 makes it work. It appears to be working fine on my emulator, assuming the thing is supposed to be entirely one color (it switches to a different color every time I run it). I'm not sure what its supposed to be doing, but it appears to be working for me after changing that one line.

edit: Looking at the one lower down in the online emulator, I see its actually showing two colors rather than one. Guess now I know what's wrong with it, unless there's something else?
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

The two colors are supposed to be two separate shapes on the screen. (or 3 or 4 or 5). I'm trying a different approach
but haven't had much time to put into this lately.
DragWx
Posts: 340
Joined: Tue Mar 07, 2023 9:07 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by DragWx »

Between lines 3000-4000, replace all instances of P1 with P3 and you successfully separate the two boxes. :D

Edit: I've made an update to the program's main loop which doesn't require the above change:

Code: Select all

200 FOR X = 1 TO NB
210 P1 = X
220 P3 = X
230 P5 = X
240 GOSUB 4000: REM DRAW
250 IF FLAG = 1 THEN GOSUB 5000: REM ERASE
260 GOSUB 3000: REM UPDATE
270 NEXT X
280 P2 = P4
290 P4 = P4 +1:IF P4 >BD THEN P4 = 1: FLAG = 1
300 P6 = P4
310 GOTO 200
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

Thanks ... The code changes did seperate the boxes.. ...

Now its not working with 2 corner boxes. (A LINE) (Its drawing but just kinda frozen in place)

More than 2 boxes its kinda working but funky.....

1 or 2 boxes 3 or greater corners its working perfectly (though with the slow performance associated with
8 bit BASIC. Anything greater than 6 corners on the box is painfully slow.
Best display is kinda with 3 corner boxes... (Less overhead).

Code: Select all

10 SCREEN 0:CLS:PRINT
11 PRINT "YOU CAN BREAK THIS PROGRAM BY ENTERING RIDICULOUS VALUES HERE !"
12 PRINT
15 INPUT "NUMBER OF BOXES (1-5):";NB
20 INPUT "SHAPE CORNERS (3-8):";NC
30 INPUT "BOX DEPTH (NUMBER OF LINES TO DRAW) (2-40)";BD
40 INPUT "BLACK THE SCREEN BEFORE START ? (Y/N)";CS$

50 SCREEN 128
60 BLACK=16
70 XLIMIT=319:YLIMIT=239
75 IF LEFT$(CS$,1)="Y" THEN RECT 0,0,XLIMIT,YLIMIT, BLACK

80 DIM BX(NB,BD, NC)  : REM CORNER X COORDINATES
85 DIM BY(NB,BD, NC)  : REM CORNER Y COORDINATES
90 DIM XI(NB, NC)     : REM X INCREMENT
95 DIM YI(NB, NC)     : REM Y INCREMENT
100 DIM BC(NB)        : REM COLOR OF THE BOX

120 P1 = 1            : REM P1, P2 BOX TO DRAW
130 P2 = 1            
140 P3 = 1            : REM P3, P4 BOX TO UPDATE
150 P4 = 2
160 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 P5 = 1 TO NB
350     GOSUB 5000
360 NEXT P5

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(P3,P2,C) + XI(P3,C) 
3040     BY(P3, P4, C)    = BY(P3,P2,C) + YI(P3,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(P3,C) = -(INT(RND(1)*8)+1)
3620 IF BX(P3,P4,C)<0 THEN BX(P3, P4,C)=0
3630 IF BX(P3,P4,C)=0 THEN XI(P3,C) = INT(RND(1)*8)+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(P3,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(P3,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, BLACK 
5090 NEXT I
5100 RETURN 

5999 REM SETUP VARIABLES
6000 X = INT(RND(-TI)) : REM INITIALIZE THE RND FUNCTION
6005 FOR B = 1 TO NB
6010     BC(B) = INT(RND(1)*255)+1
6020     IF BC(B)<20 THEN GOTO 6010
6040     FOR C = 1 TO NC
6050         XI(B,C) = INT(RND(1)*8)+1 : REM INITIAL CORNER MOTION X
6060         IF (INT(RND(1)*20)+1) > 10 THEN XI(B,C)= -XI(B,C)
6070         YI(B,C) = INT(RND(1)*5)+1 : REM INITIAL CORNER MOTION Y
6080         IF (INT(RND(1)*20)+1) > 10 THEN YI(B,C)= -YI(B,C)
6090         BX(B,1,C) = INT(RND(1)*XLIMIT) + 1 : REM SET THE INITIAL X & Y
6100         BY(B,1,C) = INT(RND(1)*YLIMIT) + 1
6110     NEXT C
6120 NEXT B
6130 RETURN 

Last edited by ahenry3068 on Mon May 08, 2023 8:48 am, edited 2 times in total.
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

I'll post code here again soon. (KINDA FIXED :) )
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: WINDOWS MYSTIFY CLONE....ALMOST WORKING

Post by ahenry3068 »

Just want to clarify... The thanks is to anyone who checked it out... But mostly to DragWx who helped mostly, mostly
fix the code...
Post Reply