Jump to content
IGNORED

Starfield in BASIC


Recommended Posts

Does anyone have code snippets, ideas, pointers, or basic guide(s) for creating a simulated moving starfield (similar to Star Raiders) in BASIC or Action! ? 

 

From a quick glance at Star Raiders, it looks like most of the time only 12 are visible and more often I only counted 11 onscreen when pausing a video. I hammered out a little something quickly in Turbo BASIC XL using arrays, but there isn’t any randomness to it, so it doesn’t give the illusion of movement much. 
 

In the end, it isn’t part of an action part of a game, more like part of a cutscene sequence (the sample I was playing with in TBXL was in BASIC GR.7).  It will go into something I’ve been piddling about with in both Advan BASIC and Fast Basic (not sure if the final thing will be written in both). Any help or pointers, etc. would be greatly appreciated. 
 

 

 

 

Link to comment
Share on other sites

10 GOTO 100

20 FOR A=1 TO STAR
30 ZA=Z(A)-SPEED:IF ZA<=1 THEN 95
40 X=XD(X(A)+RX2)/ZA+RX2:IF X<0 OR X>RX THEN 95
60 Y=YD(Y(A)+RY2)/ZA+RY2:IF Y<0 OR Y>RY THEN 95
80 IF IO(A)=1 THEN COLOR 0:PLOT XE(A),YE(A)
81 Z(A)=ZA:XE(A)=X:YE(A)=Y:IO(A)=1:COLOR 2: IF ZA>DEP2 THEN COLOR 1
82 PLOT X,Y
90 NEXT A:GOTO 20

95 IF IO(A)=1 THEN IO(A)=0:C.0:PL.XE(A),YE(A)
96 X(A)=RX*RND(0)-RX2:Y(A)=RY*RND(0)-RY2:Z(A)=DEP:GOTO 90

100 STAR=10:SPEED=5:RX=159:RY=95:DEP=RX:RX2=RX/2:RY2=RY/2:DEP2=DEP/2
120 DIM X(STAR),Y(STAR),Z(STAR),XE(STAR),YE(STAR),IO(STAR),XD(RX),YD(RY)
130 F.A=1 TO STAR:X(A)=RX*RND(0)-RX2:Y(A)=RY*RND(0)-RY2:Z(A)=DEP*RND(0):IO(A)=0:N.A
131 FOR A=1 TO RX: XD(A)=(A-RX2)*DEP: NEXT A
132 FOR A=1 TO RY: YD(A)=(A-RY2)*DEP: NEXT A
140 GRAPHICS 7+16: GOTO 20

 

 

and ASM here: 244 bytes long ? http://a8.fandal.cz/detail.php?files_id=7798

 

 

roto

 

 

Edited by xxl
  • Like 6
Link to comment
Share on other sites

5 hours ago, xxl said:

10 GOTO 100

20 FOR A=1 TO STAR
30 ZA=Z(A)-SPEED:IF ZA<=1 THEN 95
40 X=XD(X(A)+RX2)/ZA+RX2:IF X<0 OR X>RX THEN 95
60 Y=YD(Y(A)+RY2)/ZA+RY2:IF Y<0 OR Y>RY THEN 95
80 IF IO(A)=1 THEN COLOR 0:PLOT XE(A),YE(A)
81 Z(A)=ZA:XE(A)=X:YE(A)=Y:IO(A)=1:COLOR 2: IF ZA>DEP2 THEN COLOR 1
82 PLOT X,Y
90 NEXT A:GOTO 20

95 IF IO(A)=1 THEN IO(A)=0:C.0:PL.XE(A),YE(A)
96 X(A)=RX*RND(0)-RX2:Y(A)=RY*RND(0)-RY2:Z(A)=DEP:GOTO 90

100 STAR=10:SPEED=5:RX=159:RY=95:DEP=RX:RX2=RX/2:RY2=RY/2:DEP2=DEP/2
120 DIM X(STAR),Y(STAR),Z(STAR),XE(STAR),YE(STAR),IO(STAR),XD(RX),YD(RY)
130 F.A=1 TO STAR:X(A)=RX*RND(0)-RX2:Y(A)=RY*RND(0)-RY2:Z(A)=DEP*RND(0):IO(A)=0:N.A
131 FOR A=1 TO RX: XD(A)=(A-RX2)*DEP: NEXT A
132 FOR A=1 TO RY: YD(A)=(A-RY2)*DEP: NEXT A
140 GRAPHICS 7+16: GOTO 20

 

 

and ASM here: 244 bytes long ? http://a8.fandal.cz/detail.php?files_id=7798

 

 

roto

 

 

Thank you, @xxl! That is absolutely awesome and exactly what I had in mind. The roto version is even cooler. 
 

From looking at your code I now see where I was messing up. I’m no good with assembler...though I did buy a couple of books in January. I will change this up (provided you are okay with me using your code as a basis) to fit what I was doing and plug it into Advan  BASIC  and run it through the optimizing compiler. I originally had no intention of making movement possible (like in Star Raiders), but it will definitely be possible now. Thank you very much!!!!

 

Edit: I just realized you have almost double the amount of stars as in Star Raiders. Cool stuff.

Edited by 777ismyname
  • Like 1
Link to comment
Share on other sites

8 minutes ago, 777ismyname said:

I will change this up (provided you are okay with me using your code as a basis) to fit what I was doing and plug it into Advan  BASIC  and run it through the optimizing compiler.

use and improve ?

  • Like 2
Link to comment
Share on other sites

3 hours ago, billkendrick said:

I remember impressing my friends (including my now-wife) back in the 90s by cranking out a starfield in QBASIC on one of our friend's random MSDOS PCs they had at their house. Yeah, I'm great at parties. ;)

It worked for you :) Today it’d be with Python as you stream over Twitch :) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...