777ismyname Posted February 4, 2021 Share Posted February 4, 2021 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. Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 4, 2021 Share Posted February 4, 2021 https://github.com/tebe6502/Mad-Pascal/blob/master/samples/demoeffects/starfield.pas starfield.xex 2 Quote Link to comment Share on other sites More sharing options...
xxl Posted February 4, 2021 Share Posted February 4, 2021 (edited) 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 February 4, 2021 by xxl 6 Quote Link to comment Share on other sites More sharing options...
777ismyname Posted February 4, 2021 Author Share Posted February 4, 2021 5 hours ago, zbyti said: https://github.com/tebe6502/Mad-Pascal/blob/master/samples/demoeffects/starfield.pas starfield.xex 1.63 kB · 6 downloads Thank you, @zbyti! Mad Pascal is on my to do list very soon. I will pore over the code this afternoon. 1 Quote Link to comment Share on other sites More sharing options...
777ismyname Posted February 4, 2021 Author Share Posted February 4, 2021 (edited) 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 February 4, 2021 by 777ismyname 1 Quote Link to comment Share on other sites More sharing options...
xxl Posted February 4, 2021 Share Posted February 4, 2021 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 ? 2 Quote Link to comment Share on other sites More sharing options...
billkendrick Posted February 4, 2021 Share Posted February 4, 2021 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. 1 1 Quote Link to comment Share on other sites More sharing options...
777ismyname Posted February 4, 2021 Author Share Posted February 4, 2021 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 Quote Link to comment Share on other sites More sharing options...
snicklin Posted February 6, 2021 Share Posted February 6, 2021 On 2/5/2021 at 2:40 AM, xxl said: use and improve ? I was just sitting here with my headphones on, watching the starfield for 5 minutes. It is mesmerising. 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 6, 2021 Share Posted February 6, 2021 33 minutes ago, snicklin said: I was just sitting here with my headphones on, watching the starfield for 5 minutes. It is mesmerising. Have a few beers, maybe you'll discover a new planet among these stars? 1 Quote Link to comment Share on other sites More sharing options...
snicklin Posted February 7, 2021 Share Posted February 7, 2021 1 hour ago, zbyti said: Have a few beers, maybe you'll discover a new planet among these stars? A very wise suggestion there. Just give me a couple of days... Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 7, 2021 Share Posted February 7, 2021 @xxl code is 244 bytes long, I'm pretty sure he squeezed at least one planet among these stars Quote Link to comment Share on other sites More sharing options...
xxl Posted February 7, 2021 Share Posted February 7, 2021 since last year I have been flying on accelerated Altira to Proxima ... 1 Quote Link to comment Share on other sites More sharing options...
xxl Posted February 10, 2021 Share Posted February 10, 2021 here ROTO version 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.