CPCWiki forum

General Category => Programming => Topic started by: AMSDOS on 10:25, 02 September 17

Title: BASIC Shoot-Em-Up Engine
Post by: AMSDOS on 10:25, 02 September 17

Back in the day Amstrad Computer User published this Shoot-em-up 10-Liner:


[attachimg=1]


though as @Nich (http://www.cpcwiki.eu/forum/index.php?action=profile;u=53) wrote, it was riddled with problems like being very slow because you could fire as many bullets as you wanted as well as a bad collision detection (bullets passing through the aliens).


Years ago I pulled the program apart into single lines, though the underlining problems obviously still existed, though with a basic idea of what's happening in template, I've decided to write the program structurally.


Obviously this is going to be taking the program out of the confines of a 10-Liner. I've written it using no GOTOs, a main loop is used which controls to move your Square Object as well as to check going to routines to move the alien "@" and to go to the firing sequence if Space is pressed. The original program used QAOP to move your object, though I've opted for Cursor Keys to move your object & Space to Fire a Bullet.


Firing the Bullet is the most critical part from the original program I had added here, much of that is original, however in the original program problems occur with Speed and would eventually lead to a Subscript out of Range error as the bx & by array's are filled to capacity. In my version I've tried to address this slowdown by limiting the number of bullets that can be fired at one time, the limit is 2 Bullets, however if you fire one bullet and it reaches the end of the screen, you only get one shot when another alien emerges, once that bullet has cleared the screen you get 2 back. Shooting an alien though will give you your 2 bullets back (even if 1 of them has missed).


Since everything has been coded to an orderly manner, it's easier to see where problems in the Collision Detection will occur. In the case of the original program, it was only checking at one stage which led to Bullets passing through the Alien. My version checks when the Bullet has either moved a position or the Alien has moved onto the Bullet! A similar problem also occurred for the Ship, where the Ship could move through the Alien. So checks have been added for when either situation has occurred. The only time I've noticed Bullets have passed through the Alien is when the Alien is too close, I guess this the laws from "The Hunt For The Red October" where the Torpedo hasn't had enough time to Arm itself.


Code: [Select]
100 ' Setup Inks and Screen Mode
110 INK 0,0
120 INK 1,26
130 INK 2,20
140 INK 3,18
150 BORDER 11
160 PAPER 0
170 PEN 1
180 MODE 1
200 ' Define Characters & Objects
210 DEFINT a-z
220 s$=CHR$(143)
230 a$="@"
240 b$="-"
250 x=1
260 y=1
270 DIM bx(2)
280 DIM by(2)
290 b=1
300 t=0
310 sc=0
320 ay=1+INT(RND*23)
330 ax=37
340 GOSUB 810 ' Print Ship
350 GOSUB 1010 ' Print Alien
360 LOCATE 1,25
370 PRINT"Score:"
400 ' Main Loop
410 WHILE 1
420   IF INKEY(1)<>-1 AND x<30 THEN GOSUB 910:x=x+1:GOSUB 810
430   IF INKEY(8)<>-1 AND x>1 THEN GOSUB 910:x=x-1:GOSUB 810
440   IF INKEY(0)<>-1 AND y>1 THEN GOSUB 910:y=y-1:GOSUB 810
450   IF INKEY(2)<>-1 AND y<24 THEN GOSUB 910:y=y+1:GOSUB 810
460   GOSUB 710
470   GOSUB 1140 : GOSUB 1010 ' Delete & Reprint Alien
480   IF INKEY(47)<>-1 AND t<>2 THEN t=t+1:bx(t)=x+1:by(t)=y
490   IF t<>0 THEN GOSUB 1210
500 WEND
600 ' Has bullet or alien collided?
610 IF ((bx(1)=ax) AND (by(1)=ay)) OR ((bx(2)=ax) AND (by(2)=ay)) THEN GOSUB 1410
620 RETURN
700 ' Has Alien Collided with Ship?
710 IF (x=ax) AND (y=ay) THEN GOSUB 1410:LOCATE 15,12:PRINT"You're Dead!":END
720 RETURN
800 ' Display Ship
810 LOCATE x,y
820 PEN 1
830 PRINT s$;
840 RETURN
900 ' Delete Ship
910 LOCATE x,y
920 PRINT" ";
930 RETURN
1000 ' Display and Move Alien
1010 LOCATE ax,ay
1020 PEN 2
1030 PRINT a$;
1040 ax=ax-1
1050 GOSUB 710
1060 WHILE ax=0
1070   LOCATE 1,ay
1080   PRINT" ";
1090   ax=37
1100   ay=1+INT(RND*23)
1110 WEND
1120 GOSUB 610
1130 RETURN
1140 LOCATE ax+1,ay
1150 PRINT" ";
1160 RETURN
1200 ' Routine to Move Shots Fired
1210 FOR n=b TO t
1220   LOCATE bx(n),by(n)
1230   PRINT" ";
1240   PEN 3
1250   bx(n)=bx(n)+1
1260   LOCATE bx(n),by(n)
1270   PRINT b$;
1280   IF bx(n)=38 THEN LOCATE 38,by(n):PRINT" ";:b=b+1
1290 NEXT n
1300 IF bx(n-1)=38 AND b=3 THEN GOSUB 1590
1310 GOSUB 610
1320 RETURN
1400 ' Death Sequence for Alien or Ship should they Collide
1410 LOCATE ax,ay
1420 PRINT" ";CHR$(238);
1430 sc=sc+20
1440 LOCATE 8,25
1450 PRINT sc;
1460 ax=39
1470 ay=1+INT(RND*23)
1480 FOR v=15 TO 0 STEP -1
1490   BORDER 6
1500   SOUND 1,0,3,v,,,31
1510   BORDER 11
1520   SOUND 2,1000,3,v,,,31
1530 NEXT v
1540 FOR c=1 TO t
1550   LOCATE bx(c),by(c)
1560   PRINT" ";
1570   bx(c)=0:by(c)=0
1580 NEXT c
1590 b=1:t=0
1600 RETURN



Title: Re: BASIC Shoot-Em-Up Engine
Post by: Dabz on 20:17, 02 September 17
Cute! :)


Me likes that... Still doesnt beat star dodge though! ;)


Dabz
Title: Re: BASIC Shoot-Em-Up Engine
Post by: AMSDOS on 08:56, 03 September 17
Sorry I'm not sure which Star Dodge program you're referring to (there's a few of them). It seems now with this routine I've developed, there's scope to develop it further. What I had in mind with this was create a 4-way Directional Shoot-em-up, though have struggled making it 2-way by trying to reuse the Routine to Move Shots Fired. Making another one to have the shots fire the other way is probably easier, though is making the routine even larger, though I think a second one is necessary when dealing with firing shots up and down the screen.
Title: Re: BASIC Shoot-Em-Up Engine
Post by: Dabz on 12:10, 03 September 17
Quote
Sorry I'm not sure which Star Dodge program you're referring to (there's a few of them).

https://gamejolt.com/games/asteroid-dodge/22382 (https://gamejolt.com/games/asteroid-dodge/22382)


I did a remake, because well, I get the star dodge itch on occasions and like a quick blast... I did have that on Android as well, but, alas, Atari threatened me, because it had the word "Asteroid" in the title and the game looked similar to their IP, and begrudgingly, I had to take it off the Play store! :(


Now everytime I see the word Atari, or their logo, I look at them in disgust... Because, and here's what I wrote back to their lawyers "ITS NOT THE SAME BLOODY GAME!!!", but they took no notice and kept on hammering me!


Anyway, I digress, I do totally agree with the type-in, that's a nice template for someone to tinker with, I would of been all over that myself! :D


Dabz
Title: Re: BASIC Shoot-Em-Up Engine
Post by: AMSDOS on 12:29, 03 September 17
Maybe they were worried if you'd made a fortune on your game, you'd turn around and buy the company.  8)


P.S. I've taken the program I've posted on here and printed it out onto a page. Hopefully that will make things clearer!  :)
Title: Re: BASIC Shoot-Em-Up Engine
Post by: Dabz on 12:55, 03 September 17
Quote
Maybe they were worried if you'd made a fortune on your game, you'd turn around and buy the company.



lol, I wish, but it was free, so they shouldnt of been scared! :D


Honestly, it'll not be long before you'll have to name your games "Sdfsrgareghaergarga" so you don't get any grief! :D


Ohhhh.... To be back in the 80's when nobody really never tried to own the English language! :D


Anyway, I enjoyed that little type-in, be good to see what comes of it!  8)


Dabz
Title: Re: BASIC Shoot-Em-Up Engine
Post by: AMSDOS on 11:59, 20 February 18

Anyway, I enjoyed that little type-in, be good to see what comes of it!  8)


Dabz


Stay tuned to the BASIC 10-Liners Competition (http://gkanold.wixsite.com/homeputerium/kopie-von-games-list-2018-work), I submitted an entry, though the program got too large.
Title: Re: BASIC Shoot-Em-Up Engine
Post by: Gryzor on 12:59, 21 February 18
Those entries on the list do look very promising :)  Good luck!