News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Fabrizio Radica

Simple Engine Game in Basic

Started by Fabrizio Radica, 15:48, 29 July 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EgoTrip

Is the INT in lines 320-330 really necessary, as the result is going into an integer variable anyway?


AMSDOS

The INT isn't necessary, but I was getting a Subscript out of range error if the brackets were also removed.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

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


AMSDOS


I was going through a BASIC technical guide on the Wiki last night and discovered using logic conditioning within an IF statement is bad, so made some adjustments to your game:



600 IF NOT(INKEY(8)) THEN IF (TEST(x%-8,y%-6)<>9) THEN IF (TEST(x%-8,y%-14)<>9) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) THEN IF (TEST(x%+32,y%-6)<>9) THEN IF (TEST(x%+32,y%-14)<>9) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) THEN IF (TEST(x%,y%+2)<>9) THEN IF (TEST(x%+28,y%+2)<>9) THEN IF walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) THEN IF (TEST(x%,y%-18)<>9) THEN IF (TEST(x%+20,y%-18)<>9) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000





I've replaced all the ANDs within the IF statements and made a nested IFs out of it all (as suggested in the guide) and tested this which is definitely faster than a single IF with all the conditioning in it.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

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

Fabrizio Radica

Quote from: AMSDOS on 21:17, 04 January 17
I was going through a BASIC technical guide on the Wiki last night and discovered using logic conditioning within an IF statement is bad, so made some adjustments to your game:



600 IF NOT(INKEY() THEN IF (TEST(x%-8,y%-6)<>9) THEN IF (TEST(x%-8,y%-14)<>9) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) THEN IF (TEST(x%+32,y%-6)<>9) THEN IF (TEST(x%+32,y%-14)<>9) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) THEN IF (TEST(x%,y%+2)<>9) THEN IF (TEST(x%+28,y%+2)<>9) THEN IF walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) THEN IF (TEST(x%,y%-18)<>9) THEN IF (TEST(x%+20,y%-18)<>9) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000




I've replaced all the ANDs within the IF statements and made a nested IFs out of it all (as suggested in the guide) and tested this which is definitely faster than a single IF with all the conditioning in it.




WOW Fantastic!!!!

Fabrizio Radica

Quote from: AMSDOS on 21:17, 04 January 17
I was going through a BASIC technical guide on the Wiki last night and discovered using logic conditioning within an IF statement is bad, so made some adjustments to your game:



600 IF NOT(INKEY() THEN IF (TEST(x%-8,y%-6)<>9) THEN IF (TEST(x%-8,y%-14)<>9) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) THEN IF (TEST(x%+32,y%-6)<>9) THEN IF (TEST(x%+32,y%-14)<>9) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) THEN IF (TEST(x%,y%+2)<>9) THEN IF (TEST(x%+28,y%+2)<>9) THEN IF walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) THEN IF (TEST(x%,y%-18)<>9) THEN IF (TEST(x%+20,y%-18)<>9) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000





I've replaced all the ANDs within the IF statements and made a nested IFs out of it all (as suggested in the guide) and tested this which is definitely faster than a single IF with all the conditioning in it.




Sorry AMSDOS, where i find the Basic techical guide?
Tnx ^_^

AMSDOS

Yes I found a small segment called "Speeding up BASIC programs" within the Technical information about Locomotive BASIC, apart from the one I made changes to, the other which may apply in your code is the variable after the NEXT. As the article points out though, this can have the disadvantage of compromising good programming style, which I tend to agree strongly about.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

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

Fabrizio Radica

Quote from: AMSDOS on 22:18, 04 January 17
Yes I found a small segment called "Speeding up BASIC programs" within the Technical information about Locomotive BASIC, apart from the one I made changes to, the other which may apply in your code is the variable after the NEXT. As the article points out though, this can have the disadvantage of compromising good programming style, which I tend to agree strongly about.


uhm, i've found this:
[...] Often recurring subroutines (if necessary) should be at the beginning of RAM to speed up things.

so... should i put line 5000 (for example) at the start?

AMSDOS

Quote from: Fabrizio Radica on 22:49, 04 January 17

uhm, i've found this:
[...] Often recurring subroutines (if necessary) should be at the beginning of RAM to speed up things.

so... should i put line 5000 (for example) at the start?


Unfortunately I don't understand that 1st point, which starts by talking about Avoiding Loops or a Branching program structure if possible, but this last point you're referring to sounds like something different again. I can follow all the other points except this 1st one which is confusing  ???  I've checked with Kevin's original Published article, but it hasn't got the section about Speeding up BASIC Programs, this has been tacked on since by @HAL 6128  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

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

ervin


@Fabrizio
This is looking great!

Just one little thing I noticed... when you drop off a platform and then hold the down arrow key, you'll end up partly stuck in the platform below after landing.

Fabrizio Radica

Quote from: ervin on 23:17, 04 January 17
@Fabrizio
This is looking great!

Just one little thing I noticed... when you drop off a platform and then hold the down arrow key, you'll end up partly stuck in the platform below after landing.


yes i know... seems to be the "TEST" inside the "IF" at line 900...
it's a little bug and i'm going to correct it soon ;)

AMSDOS

Quote from: ervin on 23:17, 04 January 17
@Fabrizio
This is looking great!

Just one little thing I noticed... when you drop off a platform and then hold the down arrow key, you'll end up partly stuck in the platform below after landing.


Yes that was ME! I tried correcting it, but don't know what I was doing wrong!  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

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

Powered by SMFPacks Menu Editor Mod