Showing posts with label star trek. Show all posts
Showing posts with label star trek. Show all posts

Saturday, August 25, 2018

Starfield Simulation in Liberty BASIC

Here is the starfield simulation that for the VIC-20 that I posted a few days ago, but ported as simply as possible to Windows using the Liberty BASIC language (http://www.libertybasic.com).  If you compare them side by side you can see that a lot of the original code is preserved across the translation.

Enjoy!

 dim st(9,1)  
 gosub [setup]  
 timer 20, [cycle]  
 [cycle]  
   for c=0 to n  
     xold=st(c,0)  
     yold=st(c,1)  
     st(c,0)=xold*1.23  
     st(c,1)=yold*1.23  
     x=int(st(c,0))  
     y=int(st(c,1))  
     if abs(x)<15 and abs(y)<15 then  
       gosub [clearStar]  
      else  
       if abs(x)>200 or abs(y)>200 then  
         st(c,0)=(rnd(1)-0.5)*3  
         st(c,1)=(rnd(1)-0.5)*3  
        else  
         gosub [drawStar]  
       end if  
     end if  
   next c  
   wait  
   goto [cycle]  
 [clearStar]  
   #starfield "color black ; place "; xCenter + xold; " "; yCenter + yold  
   #starfield "\."  
   return  
 [drawStar]  
   gosub [clearStar]  
   #starfield "color white ; place "; xCenter + x; " "; yCenter + y  
   #starfield "\."  
   return  
 [setup]  
   input"# stars (1-10)";n  
   n=n-1  
   for x=0 to n  
     st(x,0)=(rnd(1)-0.5)*200  
     st(x,1)=(rnd(1)-0.5)*200  
   next x  
   open "starfield" for graphics as #starfield  
   #starfield "home ; posxy xCenter yCenter"  
   #starfield "down ; fill black ; backcolor black"  
   #starfield "trapclose [quit]"  
   return  
 [quit]  
   close #starfield  
   end  

Tuesday, August 21, 2018

Starfield Simulation in Commodore BASIC

I posted a challenge in the VIC-20 group on Facebook.  The idea was to replicate the forward screen of the starship Enterprise from Star Trek.  This shows stars moving from the center of the screen to the edges, simulating forward motion.  It isn't meant to be an accurate 3D simulation.  ;-)

Here is my code of this.  One other person also submitted a version of it.  This could form the basis for a game.

[Update] --- I made a new version of this in Liberty BASIC!  Click to see the new version

 10 gosub 500  
 100 for c=0 to n  
 110 xold=st(c,0)  
 120 yold=st(c,1)  
 130 st(c,0)=xold*1.23  
 140 st(c,1)=yold*1.23  
 150 x=int(st(c,0))  
 160 y=int(st(c,1))  
 165 if abs(x)<2 and abs(y)<2 then 320  
 170 if abs(x)>10 or abs(y)>10 thenst(c,0)=(rnd(1)-.5)*3:st(c,1)=(rnd(1)-.5)*3:goto150  
 180 pstar=center+x+y*22  
 190 poke center+int(xold)+int(yold)*22,32  
 200 poke pstar,108  
 300 next c  
 310 goto 100  
 320 poke center+int(xold)+int(yold)*22,32  
 400 next c  
 410 goto 100  
 500 poke 36879,14  
 501 input"# stars (1-10)";n  
 502 n=n-1  
 505 print"{clrscrn}";  
 510 dim st(9,1)  
 520 for x=0 to n  
 530 st(x,0)=(rnd(1)-.5)*10  
 540 st(x,1)=(rnd(1)-.5)*10  
 550 next x  
 590 center=7932  
 600 return  

Tuesday, May 8, 2007

Star Trek, BASIC and Arrays

I think most of all my early programming ideas were advanced by writing games. When I was still a beginner I decided to create my own version of the classic Super Star Trek game that I played on the Babson College minicomputer on a dialup connection from the Needham Public Library.

I grabbed a yellow lined notepad and started writing code in BASIC. After a half page of code I began to write lots of IF THEN statements, one almost exactly the same as the next. I realized after a bit of this that my program was going to be gigantic!

So while I was walking to the library with my brother Ernie I told him what I ran into while trying to write the program. He explained to me that I needed to learn to use arrays (he called them subscripted variables). I really had no idea what he meant. I can't remember clearly how I learned about arrays, except that Ernie must have shown me how to use them. Along with arrays it was great to learn about nested loops.

With his help I was able to write a version of Star Trek in BASIC for my father's Heathkit H-89. Later I wrote a version for the VIC-20 as well.

So this was a breakthrough moment for me. Arrays make many kinds of game programming practical, and I made good use of them. It was easy to for me to see that to create a game is to craft a simulation (even if for an imagined reality). This insight served me well as I wrote more and more software.

Thursday, April 19, 2007

Summer break, and computing?

In the summer of 1979 the Needham Public Library did something amazing. They set up a couple of telephone lines with acoustic modems and terminals. Anyone could sign up for a half hour of access per day to use a minicomputer at Babson College in Wellesley, MA. I believe the computer was an HP-3000. Between me and my brother Ernie we had a whole hour each day to program in BASIC or Fortran.

We wrote our own programs and we played the classic Star Trek game and some others too. The connect speed was 300 baud. It was pure magic.

I don't know whose idea it was to be so generous with their computers. All I can say to you whoever you are is "THANK YOU!" You really made our summer great. :-)