News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_mr_lou

Another unfinished BASIC game project

Started by mr_lou, 16:16, 05 August 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mr_lou

Here is another small unfinished BASIC game project of mine.

This one is nearly complete-able. Just lacks a title screen really... and some handling of game-over.

Anyone wanna wrap this up?
EDIT: Joystick only (at this point).

AMSDOS

#1
I made some extensive changes of the BASIC game you attached here, though have simplified it to standard BASIC keywords and removed the control characters and the extended character set, so it could be posted here, so I hope you don't mind.


I think it maybe possible to write it as a 10-Liner, though the 2 things that need altering is the "JOY(0), ON j GOSUB" routine and the Bombing routine (Lines 640-970). With the JOY routine it creates a Long Line because JOY returns bits, so it's 4 for Left and 8 for Right, maybe if Line 350 has j=(JOY(0) AND 12), Up and Down won't be triggered, but will work for Left and Right, so Line 360 can become IF j=4 THEN GOSUB 430 ELSE IF j=8 THEN GOSUB 440.


Personally though I've just been zapping the Vines away and haven't tested the Bombing routine  ???




100 KEY 0,"ink 0,11:border 11:ink 1,26:pen 1:paper 0:mode 2"+CHR$(13)
110 ENV 1,15,-1,1:ENV 2,15,-1,5:ENT 2,40,2,1:ENV 3,15,-1,10:ENT 3,100,2,2:ENV 4,15,1,1:ENT 4,100,-5,1
120 SYMBOL 249,0,0,0,0,0,0,56,0
130 SYMBOL 250,16,16,56,108,108,254,198,130
140 SYMBOL 251,16,32,32,16,8,8,16,16
150 SYMBOL 252,170,0,0,0,0,0,0,0
160 SYMBOL 253,173,154,170,164,84,72,40,16
170 SYMBOL 254,8,4,4,8,16,16,8,8
180 SYMBOL 255,16,16,16,16,16,16,16,16
190 PAPER 0:INK 0,1:BORDER 0:INK 1,22,18:INK 2,25,24:INK 3,15,24:SPEED INK 3,3
200 MODE 1
210 DEFINT a-z:DIM e(32)
220 FOR n=0 TO 32
230   e(n)=1
240 NEXT
250 x=16:y=23:c=1:f=1:s=12:l=2
260 PEN 1
270 FOR n=1 TO 32
280   SOUND 1,1000-n*10,1,15,1
290   LOCATE n,e(n):PEN 1:PRINT CHR$(253);
300   LOCATE n,21:PEN 2:PRINT CHR$(252);
310 NEXT:r=INT(RND*32)+1:b=29:GOSUB 1000
320 GOSUB 1020
330 WHILE 1
340   c=(c+1) AND 16383
350   j=(JOY(0) AND 31)
360   ON J GOSUB 420,420,420,430,430,430,420,440,440,440,420,420,420,420,420,450,450,450,420,550,550,550,420,560,560,560
370   IF (JOY(0) AND 32) OR INKEY(47)=0 THEN GOSUB 620 ELSE f=1:IF (JOY(0) AND 16)=0 THEN LOCATE 34,5:PRINT c
380   IF (c MOD s)=0 THEN GOSUB 570
390   IF (c MOD l)=0 THEN l=l*2:s=s-1:IF s=0 THEN s=1
400   IF p=x THEN GOSUB 1000
410 WEND
420 RETURN ' Do nothing
430 GOSUB 1110:x=((x-2) AND 31)+1:GOSUB 1020:RETURN
440 GOSUB 1110:x=(x AND 31)+1:GOSUB 1020:RETURN
450 IF b=0 THEN RETURN ELSE SOUND 2,10,10,15,2,2,1 ' Fire
460 a=e(x)-INT(b/50):IF a<2 THEN a=2
470 LOCATE x,e(x)+1:PRINT USING"&";" ";CHR$(8);CHR$(11);:PEN 3
480 FOR n=a TO e(x)
490   PRINT USING "&";CHR$(251);CHR$(8);CHR$(11);
500 NEXT:GOSUB 570:LOCATE x,e(x):
510 FOR n=a+1 TO e(x)
520   PRINT USING "&";" ";CHR$(8);CHR$(11);
530 NEXT:e(x)=a-1
540 b=b-1:LOCATE 34,1:PRINT b:RETURN
550 GOSUB 450:GOSUB 430:RETURN ' Fire + left
560 GOSUB 450:GOSUB 440:RETURN ' Fire + right
570 FOR d=1 TO 2
580  r=INT(RND*32)+1:e(r)=e(r)+1:LOCATE r,e(r):PEN 1:PRINT CHR$(254);:IF e(r)=20 THEN GOTO 980
590 NEXT
600 SOUND 4,INT(RND*500)+200,10,15,1
610 RETURN
620 IF f THEN f=0 ELSE RETURN ' Bomb
630 IF b<10 THEN RETURN
640 SOUND 2,10,50,15,3,3,15:PEN 3:LOCATE x,e(x)+1
650 FOR n=1 TO e(x)
660   PRINT USING"&";CHR$(251);CHR$(8);CHR$(11);
670 NEXT:z=((x-2) AND 31)+1:LOCATE z,e(z)+1
680 FOR n=1 TO e(z)-1
690   PRINT USING"&";CHR$(251);CHR$(8);CHR$(11);
700 NEXT:z=(x AND 31)+1:LOCATE z,e(z)+1
710 FOR n=1 TO e(z)-1
720   PRINT USING"&";CHR$(251);CHR$(8);CHR$(11);
730 NEXT:LOCATE x,e(x)+1
740 FOR n=2 TO e(x)
750   PRINT USING"&";" ";CHR$(8);CHR$(11);
760 NEXT
770 e(x)=1:z=((x-3) AND 31)+1:LOCATE z,e(z)+1
780 FOR n=1 TO e(z)-2
790   PRINT USING"&";CHR$(251);CHR$(8);CHR$(11);
800 NEXT:z=((x+1) AND 31)+1
810 LOCATE z,e(z)+1
820 FOR n=1 TO e(z)-2
830   PRINT USING"&";CHR$(251);CHR$(8);CHR$(11);
840 NEXT:z=((x-2) AND 31)+1:LOCATE z,e(z)+1
850 FOR n=3 TO e(z)
860   PRINT USING"&";" ";CHR$(8);CHR$(11);
870 NEXT:e(z)=1:z=(x AND 31)+1:LOCATE z,e(z)+1
880 FOR n=3 TO e(z)
890   PRINT USING"&";" ";CHR$(8);CHR$(11);
900 NEXT:e(z)=1:z=((x-3) AND 31)+1:LOCATE z,e(z)+1
910 FOR n=4 TO e(z)
920   PRINT USING"&";" ";CHR$(8);CHR$(11);
930 NEXT:e(z)=1:z=((x+1) AND 31)+1:LOCATE z,e(z)+1
940 FOR n=4 TO e(z)
950   PRINT USING"&";" ";CHR$(8);CHR$(11);
960 NEXT:e(z)=1
970 b=b-10:LOCATE 34,1:PRINT b:RETURN
980 PRINT "Dead"
990 END
1000 SOUND 1,478,50,5,4,4:p=INT(RND*32)+1
1010 b=b+5:LOCATE 34,1:PRINT b:RETURN ' New powerup position
1020 LOCATE x,y
1030 PEN 2
1040 PRINT CHR$(250);
1050 PRINT CHR$(22);CHR$(1);
1060 PRINT CHR$(8);
1070 PEN 3
1080 PRINT CHR$(249);
1090 PRINT CHR$(22);CHR$(2);
1100 RETURN
1110 LOCATE x,y
1120 PRINT" "
1130 PEN 3
1140 LOCATE 31,24
1150 RETURN



* 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

mr_lou

Awesome that you took a look at it!

The ON JOY line is used because I think it requires less CPU cycles than several IF lines. So it's all about speed - which we need when doing BASIC.  :)

I'm using the same approach in my current BASIC project (which will probably end up in a similar thread as an unfinished project at some point). You will see several "weird" coding approaches there that invites to be "cleaned up", but they all done with the intention of using less CPU cycles.  :)

AMSDOS

Quote from: mr_lou on 05:20, 04 October 20
Awesome that you took a look at it!

The ON JOY line is used because I think it requires less CPU cycles than several IF lines. So it's all about speed - which we need when doing BASIC.  :)


Yes that seems to be correct when I did some tests between ON J GOSUB and IF..THEN..ELSE IF...


The other trick that can be applied with ON <statement> GOSUB is false Line Numbers, so in places where values aren't returned an 1 can be put in its place. So for example I can do it like this:




350   j=(JOY(0) AND 28)
360   ON J GOSUB 1,1,1,430,1,1,1,440,1,1,1,420,1,1,1,450


so when JOY(0) AND 28 is encountered, numbers between 4 & 16 are 4,8,12,16. 12 is the odd bod in the mix, which strangely occurs when I hold down Left & Right together, I don't know how that's possible with a Joystick, though strangely it occurs, which is why 420 is present and if occurs nothing happens.

QuoteI'm using the same approach in my current BASIC project (which will probably end up in a similar thread as an unfinished project at some point). You will see several "weird" coding approaches there that invites to be "cleaned up", but they all done with the intention of using less CPU cycles.  :)


I noticed the use of a control code string, which was then placed into an address buffer, but then a second variable had to be use, it had to be a Real because a Larger number was returned causing an Overflow on the Integer, but I think the problem was it was Multiplying the 2nd number by 256 instead of the 1st, following by adding the Second number, otherwise it was working with the Real.
* 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

mv

I played with the coding of AMSDOS's version a bit, that's my current approach:

100 KEY 0,"ink 0,11:border 11:ink 1,26:pen 1:paper 0:mode 2"+CHR$(13)
110 ENV 1,15,-1,1:ENV 2,15,-1,5:ENT 2,40,2,1:ENV 3,15,-1,10:ENT 3,100,2,2:ENV 4,15,1,1:ENT 4,100,-5,1
120 SYMBOL 249,0,0,0,0,0,0,56,0
130 SYMBOL 250,16,16,56,108,108,254,198,130
140 SYMBOL 251,16,32,32,16,8,8,16,16
150 SYMBOL 252,170,0,0,0,0,0,0,0
160 SYMBOL 253,173,154,170,164,84,72,40,16
170 SYMBOL 254,8,4,4,8,16,16,8,8
180 SYMBOL 255,16,16,16,16,16,16,16,16
190 PAPER 0:INK 0,1:BORDER 0:INK 1,22:INK 2,25:INK 3,15,24:SPEED INK 3,3
200 MODE 1
205 WINDOW#1,34,40,1,25:PEN#1,2
210 RANDOMIZE TIME:DEFINT a-z:DIM e(31)
250 x=15:y=23:c=1:f=1:s=12:l=2
260 PEN 1
265 s$=CHR$(250)+CHR$(22)+CHR$(1)+CHR$(8)+CHR$(15)+CHR$(3)+CHR$(249)+CHR$(22)+CHR$(2)
270 FOR n=0 TO 31
275   e(n)=1
280   SOUND 1,1000-n*10,1,15,1
290   LOCATE n+1,e(n):PEN 1:PRINT CHR$(253);
300   LOCATE n+1,21:PEN 2:PRINT CHR$(252);
310 NEXT
315 r=INT(RND*32):b=29:GOSUB 1000
320 LOCATE x+1,y:PEN 2:PRINT s$;
330 FOR c=1 TO 16384
335   t!=TIME
350   j=JOY(0)
352   IF j AND 12 THEN LOCATE x+1,y:x=(x+((j AND 4)>0)-((j AND 8)>0)) AND 31:PEN 2:PRINT " ";:LOCATE x+1,y:PRINT s$;
360   IF (j AND 16) AND (b>0) THEN GOSUB 450 ELSE LOCATE#1,1,5:PRINT#1,c
370   IF (j AND 32) OR INKEY(47)=0 THEN GOSUB 620 ELSE f=1
380   IF (c MOD s)=0 THEN GOSUB 570
390   IF (c MOD l)=0 THEN l=l*2:s=s-1:IF s=0 THEN s=1
400   IF p=x THEN GOSUB 1000
406   IF TIME-t!<18 THEN CALL &BD19:GOTO 406
410 NEXT c
412 GOTO 330
425 '
448 'Fire
450 SOUND 2,10,10,15,2,2,1
460 a=e(x)-INT(b/50):IF a<2 THEN a=2
470 LOCATE x+1,e(x)+1:c1=32:n2=1:GOSUB 975:PEN 3
480 c1=251:n2=e(x)-a+1:GOSUB 975:CALL &BD19
500 GOSUB 570:LOCATE x+1,e(x)
510 c1=32:n2=e(x)-a:GOSUB 975:'call &bd19
530 e(x)=a-1
540 b=b-1:GOTO 1015
545 '
570 FOR d=1 TO 2
580  r=INT(RND*32):e(r)=e(r)+1:LOCATE r+1,e(r):PEN 1:PRINT CHR$(254);:IF e(r)=20 THEN 980
590 NEXT
600 SOUND 4,INT(RND*500)+200,10,15,1
610 RETURN
615 '
617 'Bomb
620 IF f THEN f=0 ELSE RETURN
630 IF b<10 THEN RETURN
640 SOUND 2,10,50,15,3,3,15:PEN 3
650 c1=251
655 z=x:n2=e(z):GOSUB 973
670 z=(x-1) AND 31:n2=e(z)-1:GOSUB 973
700 z=(x+1) AND 31:n2=e(z)-1:GOSUB 973
740 z=x:n2=e(z)-1:c1=32:GOSUB 973:c1=251
770 e(x)=1
775 z=(x-2) AND 31:n2=e(z)-2:GOSUB 973
800 z=(x+2) AND 31:n2=e(z)-2:GOSUB 973
840 z=(x-1) AND 31:n2=e(z)-2:c1=32:GOSUB 973
870 e(z)=1:z=(x+1) AND 31:n2=e(z)-2:GOSUB 973
900 e(z)=1:z=(x-2) AND 31:n2=e(z)-3:GOSUB 973
930 e(z)=1:z=(x+2) AND 31:n2=e(z)-3:GOSUB 973
960 e(z)=1
970 b=b-10:GOTO 1015
972 '
973 LOCATE z+1,e(z)+1:GOSUB 975:CALL &BD19:RETURN
974 '
975 FOR n=1 TO n2:PRINT CHR$(c1);CHR$(8);CHR$(11);:NEXT:RETURN
977 '
980 PRINT "Dead"
985 WHILE INKEY$<>"":CALL &BD19:WEND
990 END
995 '
997 'New powerup position
1000 SOUND 1,478,50,5,4,4:p=INT(RND*32)
1010 b=b+5:GOTO 1015
1015 LOCATE#1,1,1:PRINT#1,b:RETURN


- reduced bomb coding, still somehow longish
- changed joystick check (no ON GOSUB...RETURN)
- minimized the time between ship remove and draw, using the original string idea
- use e(0..31), simplifies AND, but you always need +1 in LOCATE
- keep colors for counters
- no blinking all the time

I assume that ON GOSUB with RETURN takes longer than some IF, so I put the ship movement in one line, using the AND 12 idea, and some computation to avoid other IFs:

IF j AND 12 THEN LOCATE x+1,y:x=(x+((j AND 4)>0)-((j AND 8)>0)) AND 31:PEN 2:PRINT " ";:LOCATE x+1,y:PRINT s$;

Still not a 10-liner.
I will put it also on https://benchmarko.github.io/CPCBasic/cpcbasic.html?database=apps&example=games/basgame2

Powered by SMFPacks Menu Editor Mod