Author Topic: BASIC Platform Demostration  (Read 3075 times)

0 Members and 1 Guest are viewing this topic.

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
BASIC Platform Demostration
« on: 04:56, 02 May 15 »
I've come up with a simple demonstration for a platform game:

Code: [Select]
`10 MODE 0:DIM board(8,9)20 GOSUB 1000 : GOSUB 121030 WHILE INKEY(18)=-140 GOSUB 131050 WEND:MODE 2:END1000 RESTORE 11001010 FOR y=1 TO 81020 FOR x=1 TO 91030 READ b1040 board(y,x)=b1050 LOCATE x,y1060 IF board(y,x)=1 THEN PRINT CHR\$(143);1070 NEXT x1080 NEXT y1090 RETURN1100 DATA 0,0,0,0,0,0,0,0,01110 DATA 0,0,0,0,0,0,0,0,01120 DATA 0,0,0,0,0,0,0,0,01130 DATA 1,1,1,1,0,0,0,0,01140 DATA 0,0,0,0,1,1,0,0,01150 DATA 0,0,0,0,0,0,0,0,01160 DATA 0,0,0,0,0,0,1,1,01170 DATA 1,1,1,1,1,1,0,0,01200 ' Initialise Position for Man1210 x=1: y=11220 RETURN1300 ' Print & Move Man also test Array1310 LOCATE x,y:PRINT CHR\$(249);1320 IF board(y+1,x)<>1 THEN oldy=y:y=y+1:LOCATE x,oldy:PRINT" ";1330 IF INKEY(1)<>-1 AND x<8 AND board(y,x+1)<>1 THEN oldx=x:x=x+1:LOCATE oldx,y:PRINT" ";1340 IF INKEY(8)<>-1 AND x>1 AND board(y,x-1)<>1 THEN oldx=x:x=x-1:LOCATE oldx,y:PRINT" ";1350 IF INKEY(0)<>-1 AND board(y-1,x)<>1 THEN oldy=y:y=y-1:LOCATE x,oldy:PRINT" ";1360 RETURN`

For the man I'm using Left/Right & the Up Arrow and everything was working until I got to the Jumping Sequence and am having problems because I can't Jump up - Left, Jump up - Right for example and am assuming I need a subroutine to determine where to move.

Help?
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #1 on: 09:40, 02 May 15 »
I've addressed the issue of the first version:

Code: [Select]
`10 MODE 0:DIM board%(9,20)20 GOSUB 1000 : GOSUB 121030 WHILE INKEY(18)=-140 GOSUB 131050 WEND:WHILE INKEY\$<>"":WEND:MODE 2:END1000 RESTORE 11001010 FOR y%=1 TO 91020 FOR x%=1 TO 201030 READ b%1040 board%(y%,x%)=b%1050 LOCATE x%,y%1060 IF board%(y%,x%)=1 THEN PRINT CHR\$(143);1070 NEXT x%1080 NEXT y%1090 RETURN1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,01110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,01120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,01130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,01140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,01150 DATA 0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,0,01160 DATA 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,01170 DATA 1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,01180 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,01200 ' Initialise Position for Man1210 x%=1: y%=11220 RETURN1300 ' Print & Move Man also test Array1310 LOCATE x%,y%:PRINT CHR\$(249);:CALL &BD19:CALL &BD191320 IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";1330 IF INKEY(1)<>-1 AND x%<20 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,y%:PRINT" ";1340 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,y%:PRINT" ";1350 IF INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 20101360 ' IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";1370 RETURN2000 ' Jump Left or Right2010 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,oldy%:PRINT" ";:RETURN2020 IF INKEY(1)<>-1 AND x%<20 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,oldy%:PRINT" ";:RETURN2030 LOCATE x%,oldy%:PRINT" ";2040 RETURN`

But now it feels like I have a Superbeing who jump anywhere, when they reach top areas on the screen. I think I know how to sort that out, obviously what I've done here is when the Up key is detected it then checks if Left or Right key is being pressed, but it really needs to have the person jump up and fall down - even when the Up Arrow is being pressed.
« Last Edit: 12:00, 04 May 15 by AMSDOS »
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

alex76gr

• CPC664
• Posts: 143
• Country:
• Liked: 93
• Likes Given: 40
Re: BASIC Platform Demostration
« Reply #2 on: 10:20, 04 May 15 »
This is so cool man! So cool!
Excellent job.
I still believe that i got my myopia from the green GT-65 monitor, but i can't prove it!

ronaldo

• Dev
• 6128 Plus
• Posts: 650
• Country:
• Liked: 952
• Likes Given: 836
Re: BASIC Platform Demostration
« Reply #3 on: 11:43, 04 May 15 »
But now it feels like I have a Superbeing who jump anywhere, when they reach top areas on the screen. I think I know how to sort that out, obviously what I've done here is when the Up key is detected it then checks if Left or Right key is being pressed, but it really needs to have the person jump up and fall down - even when the Up Arrow is being pressed.

One possible solution is creating a status variable. For instance, say that status=0 means staying at the floor, status>0 means that you have jumped N cells already and status<0 means -N cells already falled (and falling). You can use it to control the vertical movement of the character, and preventing user from jumping when falling. You just have to code something like this (S%=status):
Code: [Select]
`IF S%>-1 AND S%<3 AND INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 2010 ELSE IF S%>0 THEN S%=-S%`
You let the user jump more or less and, at the same time you control the change from jumping to falling, preventing the user to jumping again when in falling status. You can construct lots of similar solutions to this.

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #4 on: 12:17, 04 May 15 »
One possible solution is creating a status variable. For instance, say that status=0 means staying at the floor, status>0 means that you have jumped N cells already and status<0 means -N cells already falled (and falling). You can use it to control the vertical movement of the character, and preventing user from jumping when falling. You just have to code something like this (S%=status):
Code: [Select]
`IF S%>-1 AND S%<3 AND INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN oldy%=y%:y%=y%-1:GOSUB 2010 ELSE IF S%>0 THEN S%=-S%`
You let the user jump more or less and, at the same time you control the change from jumping to falling, preventing the user to jumping again when in falling status. You can construct lots of similar solutions to this.

Yes that's one of the possibilities I was considering and perhaps the easier approach. The other way I thought about do it was to have a means for the person to come back to earth at the end of the jumping sequence kind of simulating what Line 1320 is doing, but is more coding.
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

• Dev
• 6128 Plus
• Posts: 650
• Country:
• Liked: 952
• Likes Given: 836
Re: BASIC Platform Demostration
« Reply #5 on: 14:06, 04 May 15 »
Technically, it depends on your goal. If you want it to be just for this single character, the status approach is good. If you want to apply it to a lot of entities, I would consider redesigning it to make an entity manager code that takes into account forces and collisions, plus user keyboard input.

However, it usually is better to start easy and grow as required

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #6 on: 10:15, 05 May 15 »
Technically, it depends on your goal. If you want it to be just for this single character, the status approach is good. If you want to apply it to a lot of entities, I would consider redesigning it to make an entity manager code that takes into account forces and collisions, plus user keyboard input.

However, it usually is better to start easy and grow as required

At the moment I was only playing with the idea of creating some platforms and having the person land on them, but writing it in a more structured manner, which works quite well. There is a BASIC game where a person has to dodge a series of balls, a little bit like Home Runner, but a little bit easier, though the programming of it I thought could be improved (as the author of it wrote).
I think this way of using Data statements to define the screen seems to have more advantage - different objects can have different values that depend on how your character interacts.

Will just need to get on my other computer and test some possibilities with the jumping sequence, kind of wondering that I might need to separate Printing the man and having the character inputs separately?
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #7 on: 08:03, 06 May 15 »

Okay, so I've rearranged the array so now there's a couple of distinct platforms, but I'm having problems writing a suitable jumping routine. What I had in mind was something where your character can jump to those platforms from below.

I had a go at trying to implement a status variable (which I kind of have down there), but the trouble is arising when I want to jump the character more than one character, I had variations of this and in one case I had the person jumping a few squares, but had trouble with the animating sequence.

The other little danger is there needs to be a way to check if the y% goes past 1 to prevent an error. Would be more problematic if character is near the top of the screen.

Code: [Select]
`10 MODE 0:DIM board%(9,20)20 GOSUB 1000 : GOSUB 121030 WHILE INKEY(18)=-131 GOSUB 141040 GOSUB 131050 WEND:WHILE INKEY\$<>"":WEND:MODE 2:END1000 RESTORE 11001010 FOR y%=1 TO 91020 FOR x%=1 TO 201030 READ b%1040 board%(y%,x%)=b%1050 LOCATE x%,y%1060 IF board%(y%,x%)=1 THEN PRINT CHR\$(143);1070 NEXT x%1080 NEXT y%1090 RETURN1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,01140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,01150 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,01160 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,01170 DATA 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,01180 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,01200 ' Initialise Position for Man1210 x%=1: y%=11220 RETURN1300 ' Move Man & test Array1310 ' LOCATE x%,y%:PRINT CHR\$(249);:CALL &BD19:CALL &BD191320 IF board%(y%+1,x%)<>1 THEN oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";1330 IF INKEY(1)<>-1 AND x%<19 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,y%:PRINT" ";1340 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,y%:PRINT" ";1350 IF INKEY(0)<>-1 AND y%>1 AND board%(y%-1,x%)<>1 THEN s%=1:oldx%=x%:oldy%=y%:y%=y%-1:GOSUB 1410:GOSUB 1510:GOSUB 20101360 IF s%=1 AND board%(y%+1,x%)<>1 THEN s%=0:oldy%=y%:y%=y%+1:LOCATE x%,oldy%:PRINT" ";1370 RETURN1400 ' Print Man1410 LOCATE x%,y%:PRINT CHR\$(249);:CALL &BD19:CALL &BD191420 RETURN1500 ' Delete Man1510 LOCATE oldx%,y%:PRINT" ";1520 RETURN2000 ' Jump Left or Right2010 IF INKEY(8)<>-1 AND x%>1 AND board%(y%,x%-1)<>1 THEN oldx%=x%:x%=x%-1:LOCATE oldx%,oldy%:PRINT" ";:RETURN2020 IF INKEY(1)<>-1 AND x%<19 AND board%(y%,x%+1)<>1 THEN oldx%=x%:x%=x%+1:LOCATE oldx%,oldy%:PRINT" ";:RETURN2030 LOCATE x%,oldy%:PRINT" ";:s%=02040 RETURN`
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #8 on: 11:40, 06 May 15 »
At the moment, I've come up with a Jumping Simulator, just to get the gist of it:

Code: [Select]
`10 x%=10: y%=25: p%=020 MODE 130 WHILE INKEY\$<>"":WEND40 WHILE INKEY(18)=-150  GOSUB 121060  IF INKEY(0)<>-1 THEN GOSUB 101070 WEND80 WHILE INKEY\$<>"":WEND90 MODE 2:END1000 ' Jump Routine1010 p%=01020 WHILE p%<41030  oldy%=y% : y%=y%-11040  GOSUB 12101050  GOSUB 13101060  p%=p%+11070 WEND1080 WHILE p%>01090  oldy%=y% : y%=y%+11100  GOSUB 12101110  GOSUB 13101120  p%=p%-11130 WEND1140 RETURN1200 ' Print Man1210 LOCATE x%,y% : PRINT CHR\$(249);1220 RETURN1300 ' Delete Man1310 LOCATE x%,oldy% : PRINT" ";1320 RETURN`

All I need to do now is jam the thing in so the person can move left/right with this. The good news is this routine will return the character to where they were, though I don't think it tests the top of the screen.
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

• Dev
• 6128 Plus
• Posts: 650
• Country:
• Liked: 952
• Likes Given: 836
Re: BASIC Platform Demostration
« Reply #9 on: 21:17, 06 May 15 »
I've taken the license to create a modified version of your code to show you what I meant with respect to the status variable. Status variable should control the flow of your program, impeding jump to be performed when you are already jumping, and when you are falling. Gravity should not be applied when you are jumping also.

I've also made some modifications following this logic: Drawing should be done only once, in the drawing routine, and not in many places in the code. The rest of the code takes responsibility for updating logic only. Also, control of the jump has been moved to a subroutine, to make use of it whenever needed. When drawing, it is preferably to wait for VSYNC first, then quickly draw.

You can improve drawing and processing a lot applying several optimization tecniques. Namely:
• Single string drawing
• Using default integers
• Single character variable names
• Reducing lines
• IF-THEN-IF condition checking instead of logic operators
• Removing unnecesary spaces.
If have only applied some of them for illustration purposes, and for not making the code more complex.

Please, let me know if this is what you wanted and if you have any doubt about my proposal. Hope this helps.

Code: [Select]
`10 MODE 0:DIM board%(9,20)20 GOSUB 1000 : GOSUB 121030 WHILE INKEY(18)=-131 GOSUB 141040 GOSUB 131050 WEND:WHILE INKEY\$<>"":WEND:MODE 2:END1000 RESTORE 11001010 FOR y%=1 TO 91020 FOR x%=1 TO 201030 READ b%1040 board%(y%,x%)=b%1050 LOCATE x%,y%1060 IF board%(y%,x%)=1 THEN PRINT CHR\$(143);1070 NEXT x%1080 NEXT y%1090 RETURN1100 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01110 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01120 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,01130 DATA 1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,01140 DATA 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,01150 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,01160 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,01170 DATA 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,01180 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,01200 ' Initialise Position for Man1210 oldx%=1:oldy%=1:x%=1: y%=11220 RETURN1300 ' Move Man & test Array1310 ' LOCATE x%,y%:PRINT CHR\$(249);:CALL &BD19:CALL &BD191320 IF s%>0 THEN GOSUB 3000:GOTO 1350' Control gravity1330 IF board%(y%+1,x%)=0 THEN y%=y%+1:GOTO 1350' Jumping only allowed when not falling1340 IF NOT INKEY(0) THEN IF y%>1 AND board%(y%-1,x%)=0 THEN GOSUB 3000' User keyboard input1350 IF NOT INKEY(1) THEN IF x%<19 AND board%(y%,x%+1)=0 THEN x%=x%+11360 IF NOT INKEY(8) THEN IF x%>1 AND board%(y%,x%-1)=0 THEN x%=x%-11370 RETURN1400 ' Print Man ' Only redraw if there is movement1410 IF oldx%=x% AND oldy%=y% THEN RETURN' Wait for VSYNC1420 CALL &BD19' Redraw1430 LOCATE oldx%,oldy%:PRINT " ";1440 LOCATE x%,y%:PRINT CHR\$(249);' Update coordinates1450 oldx%=x%:oldy%=y%1460 RETURN'' Control Jumping status'3000 s%=s%+1' Check for jump-status ending conditions (max jump, collision, screen top)3010 IF s%>3 OR y%=1 OR board%(y%-1,x%)=1 THEN s%=0:RETURN 3020 y%=y%-13030 RETURN`
« Last Edit: 21:19, 06 May 15 by ronaldo »

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #10 on: 06:13, 07 May 15 »
I've taken the license to create a modified version of your code to show you what I meant with respect to the status variable. Status variable should control the flow of your program, impeding jump to be performed when you are already jumping, and when you are falling. Gravity should not be applied when you are jumping also.

I've also made some modifications following this logic: Drawing should be done only once, in the drawing routine, and not in many places in the code. The rest of the code takes responsibility for updating logic only. Also, control of the jump has been moved to a subroutine, to make use of it whenever needed. When drawing, it is preferably to wait for VSYNC first, then quickly draw.

You can improve drawing and processing a lot applying several optimization tecniques. Namely:
• Single string drawing
• Using default integers
• Single character variable names
• Reducing lines
• IF-THEN-IF condition checking instead of logic operators
• Removing unnecesary spaces.
If have only applied some of them for illustration purposes, and for not making the code more complex.

Please, let me know if this is what you wanted and if you have any doubt about my proposal. Hope this helps.

This is great.

I was tinkering around with this - namely the GOTOs, though there playing a critical role for this routine. The approach I was trying to do with the WHILE jump routine is going to require code for moving Left & Right within it, I tried changing it around a little by making the controls it's own routine (similar to your approach), but had heaps of problems, I think because of the nature of how I'm drawing/deleting the character use of LOCATE varies.

I was trying to write it structurally so I could port it to Pascal. I have got GOTO available in it and your routine seems to be using one Procedure which is fortunate.
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

• Dev
• 6128 Plus
• Posts: 650
• Country:
• Liked: 952
• Likes Given: 836
Re: BASIC Platform Demostration
« Reply #11 on: 11:52, 07 May 15 »
Quote from: AMSDOS
I was tinkering around with this - namely the GOTOs, though there playing a critical role for this routine.

GOTOs used heres are not "propper GOTOs". You can see them as IF-THEN-ELSE branching. As Locomotive BASIC hasn't got ability for multi-line IFs, you have to simulate them with GOTOs. However, you can get rid of the GOTOs in this code, gaining performance but loosing readability. Some comments can make this structure clearer:

Code: [Select]
`' IF s%>0    1320 IF s%>0 THEN GOSUB 3000:GOTO 1350' ELSE IF board%(y%+1,x%)=0    1330 IF board%(y%+1,x%)=0 THEN y%=y%+1:GOTO 1350' ELSE    1340 IF NOT INKEY(0) THEN IF y%>1 AND board%(y%-1,x%)=0 THEN GOSUB 3000' ENDIF`
Optimizing it for speed, we can rewrite everything as:

Code: [Select]
`1310IF s%>0THEN GOSUB 3000ELSE IF board%(y%+1,x%)=0THEN y%=y%+1ELSE IF NOT INKEY(0)THEN IF y%>1AND board%(y%-1,x%)=0THEN GOSUB 3000`
Getting rid of unneeded spaces and placing everything in one line gives you much better performance in Locomotive BASIC. To get even more in this line, you should rename board% to b% and use DEFINT A-Z and get rid of '%'s. That will save you some memory and CPU cycles.You also can improve performance changing your 1's into -1's in the collision matrix and then changing previous line into:

Code: [Select]
`1310IF s>0THEN GOSUB 3000ELSE IF b(y+1,x)THEN y=y+1ELSE IF NOT INKEY(0)THEN IF y>1AND b(y-1,x)THEN GOSUB 3000`
Doing this, you loose readability but you win memory and performance.

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #12 on: 01:01, 09 May 15 »
Thanks I should of realised.

Unfortunately I liked to use excessive amounts of code to do the job at the same time having it look nice and readable (with unnecessarily spaces). Was under the impression that a "%" is just as good as a DEFINT a-z, though better because it's only using the variables you need rather than defining the whole table as that.

Guess this wouldn't be an issue in a BASIC Compiler?
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ronaldo

• Dev
• 6128 Plus
• Posts: 650
• Country:
• Liked: 952
• Likes Given: 836
Re: BASIC Platform Demostration
« Reply #13 on: 02:12, 09 May 15 »
Unfortunately I liked to use excessive amounts of code to do the job at the same time having it look nice and readable (with unnecessarily spaces). Was under the impression that a "%" is just as good as a DEFINT a-z, though better because it's only using the variables you need rather than defining the whole table as that.

Guess this wouldn't be an issue in a BASIC Compiler?
Unnecesary spaces shouldn't be an issue when compiling. However, I wouldn't risk my neck. Best you can do is running some tests to be sure. You may have FaBaCom for instance, do several versions of your code, compile them and measure results. I wrote a post on FaBaCom monts ago (In spanish). It's an average opcion for compiling Locomotive BASIC and win some performance.

Definitely, using % in BASIC slows down performance. Locomotive BASIC parser goes character by character when interpreting anything that is not a BASIC token. Moreover, when speaking of symbol names (variables) this is even worse, because it has to do a search in the symbol table every time it finds a variable in the code. Because of this, it is always preferible to use short variable names (1 character where possible) and get rid of any unnecesary character. This is the reason why DEFINT is much better. Also, you have to take into account that variable names a and a% are different even when you use DEFINT.

AMSDOS

• Supporter
• 6128 Plus
• Posts: 3.939
• Country:
• Liked: 1159
• Likes Given: 1931
Re: BASIC Platform Demostration
« Reply #14 on: 12:54, 09 May 15 »
Unnecesary spaces shouldn't be an issue when compiling. However, I wouldn't risk my neck. Best you can do is running some tests to be sure. You may have FaBaCom for instance, do several versions of your code, compile them and measure results. I wrote a post on FaBaCom monts ago (In spanish). It's an average opcion for compiling Locomotive BASIC and win some performance.

I've only used the Windows program CPC BASIC 3 which handles Integers as a Default variable type, though handles decimal through RSX routines. Output is very well done according to @Trebmint, Quicker or equal to any C Compiler on the Z80. I have noticed that this code is faster than my Hisoft Pascal 4T code, though todays compilers are going to beat something from 1984.    CPC BASIC 3 Vs. Assembly stacks up well, my Assembly using Firmware appears the same with Assembly being able to generate smaller code.

Quote
Definitely, using % in BASIC slows down performance. Locomotive BASIC parser goes character by character when interpreting anything that is not a BASIC token. Moreover, when speaking of symbol names (variables) this is even worse, because it has to do a search in the symbol table every time it finds a variable in the code. Because of this, it is always preferible to use short variable names (1 character where possible) and get rid of any unnecesary character. This is the reason why DEFINT is much better. Also, you have to take into account that variable names a and a% are different even when you use DEFINT.

Okay.
* Using the old Amstrad Languages    * with the Firmware
* I also like to problem solve code in BASIC    * And type-in Type-Ins!

Home Computing Weekly Programs
Popular Computing Weekly Programs