Jump to content
IGNORED

Twinkling stars


Retrospect

Recommended Posts

Hi all.

 

I'm currently preparing to program "Lunar Mission II" and I had an idea. The sort of idea that actually stops progress of the game because you want it in, but it's not working right.

 

Okay, Parsec ... note the twinkling stars. Just how was this done? I've tried a couple of methods none of which were satisfactory.

I've tried creating stars using different character sets and having those sets switch to black and then back to white, this didn't work as expected (but could be improved later), I've also tried cycling colours through the stars (using lots of char sets obviously) and this had a good effect but not like the one in Parsec.

 

How did the Parsec guys do it? :)

  • Like 1
Link to comment
Share on other sites

Try this. ;)

 

100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*256)::next i
110 p$="010204081020400"::for i=0 to 7::call char(40+i,seg$(p$,i*2+1,2))::next i
120 for i=0 to 5::call hchar(i*3+2,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run
 
   
Edited by sometimes99er
  • Like 3
Link to comment
Share on other sites

Try this. ;)

 

100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*256)::next i
110 p$="010204081020400"::for i=0 to 7::call char(40+i,seg$(p$,i*2+1,2))::next i
120 for i=0 to 5::call hchar(i*3+2,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run
 
   

Hey thanks Karsten, that's really good. I'll have a bash at implementing that into the code

  • Like 1
Link to comment
Share on other sites

It's basically the same method the Parsec guys used.

 

for i=0 to 5::s(i)=int(rnd*256)::next i

The above fills an array with a random star constellation. Each star has a horizontal position in the range 0 to 255.

 

You only have to dimension (DIM) the array if it has more than eleven elements (numbered 0 to 10).

 

Let's try 24 stars ...

 

100 call screen(2)::call clear::call color(2,16,1)::dim s(23)::for i=0 to 23::s(i)=int(rnd*256)::next i
110 p$="010204081020400"::for i=0 to 7::call char(40+i,seg$(p$,i*2+1,2))::next i
120 for i=0 to 23::call hchar(i+1,32-int(s(i)/8),40+(s(i)and 7))::s(i)=(s(i)+1)and 255
130 next i::goto 120
run
 
Edited by sometimes99er
  • Like 1
Link to comment
Share on other sites

110 p$="010204081020400"::for i=0 to 7::call char(40+i,seg$(p$,i*2+1,2))::next i

The above defines 8 characters. If we print these characters at the same position, it will look like a star moving to the left.

 

gallery_11132_2341_22.png

 

Note that the last character has no star. This is the twinkle effect. If we had a star in the eighth character, we'd then have to clear this position (with an empty space) while also printing a star left of this position. So we're actually saving some trouble - or let's call it a neat trick. If all stars used the same character at any given time, then all stars would twinkle in sync, and the overall effect is gone. That's why we assign a unique pixel position for each star - and from that we calculate character to be used and character position.

  • Like 2
Link to comment
Share on other sites

Here's 6 twinkling stars and moving down.

 

100 call screen(2)::call clear::call color(2,16,1)::for i=0 to 5::s(i)=int(rnd*192)::next i
110 for i=0 to 6::call char(40+i,rpt$("00",i)&"1")::next i::call char(47,"")
120 for i=0 to 5::call hchar(int(s(i)/8)+1,i+1,40+(s(i)and 7))::s(i)=(s(i)+1)::if s(i)=192 then s(i)=0
130 next i::goto 120
run
 

And here's 32 stars

 

100 call screen(2)::call clear::call color(2,16,1)::dim s(31)::for i=0 to 31::s(i)=int(rnd*192)::next i
110 for i=0 to 6::call char(40+i,rpt$("00",i)&"1")::next i::call char(47,"")
120 for i=0 to 31::call hchar(int(s(i)/8)+1,i+1,40+(s(i)and 7))::s(i)=(s(i)+1)::if s(i)=192 then s(i)=0
130 next i::goto 120
run
 
Edited by sometimes99er
  • Like 3
Link to comment
Share on other sites

Hey this is really neat! .... This will come in handy for my game, as it will have a screen where you are in outer space (with twinkling stars and animated meteors) and then a screen where you collect the astronauts (the stars wouldn't be moving for this bit as you land on this screen). .... so yeah thanks for these examples and I must say they work really well.

  • Like 3
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...