Hello guys,
Not posted for a while due to the fact that I lost nearly all of my original code that I have been writing for the last few years . . . serves me right really for not backing it up . . . I have been messing about with my starfield for ages but recently came up with this . . . and thought I would share.
' Starfield v3 by Andy of RCM - 07/04/09
' Dedicated to my family and friends
#include once "tinyptc_ext.bi"
#include once "crt.bi"
#include once "windows.bi"
const xres = 800
const yres = 600
Dim shared as integer sf
sf=512
Dim shared as double x(sf),y(sf),s(sf)
dim shared as double r,g,b
Dim shared as integer a
Dim shared as String key
Dim shared as integer bib
Dim shared as integer q
Declare Sub DLine(ypos,r as double,g as double,b as double,wid)
Declare Sub Stars
for a=0 to sf-1
x(a)=(int(rnd(1)*xres)-1)
y(a)=1+(int(rnd(1)*yres)-1)
s(a)=1+(int(rnd(1)*8))
next
r=255:g=255:b=255
ptc_allowclose(0)
ptc_setdialog(1,"Would you like to go Fullscreen?",0,1)
If( ptc_open( "Starfield - Again!", XRES, YRES ) = 0 ) Then
End -1
End If
Dim Shared as Integer sb(xres*yres)
#define pp(x,y,argb) sb(y*XRES+x)=argb
Dim Shared As LARGE_INTEGER Frequency
Dim Shared As LARGE_INTEGER LiStart
Dim Shared As LARGE_INTEGER LiStop
Dim Shared As LONGLONG LlTimeDiff
Dim Shared As Double MDuration
QueryPerformanceFrequency( @Frequency )
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
QueryPerformanceCounter( @LiStart )
key = inkey$()
Stars
DLine(0,255,128,16,24)
DLine(yres-25,255,128,16,24)
DLine(24,255,255,255,2)
DLine(yres-25,255,255,255,2)
ptc_update @sb(0)
erase sb
do
QueryPerformanceCounter( @LiStop )
LlTimeDiff = LiStop.QuadPart - LiStart.QuadPart
MDuration = Cast( Double, LlTimeDiff ) * 1000.0 / Cast( Double , Frequency.QuadPart )
Loop While ( MDuration <= 1000.0/60.0 )'60fps Clamp change the 60.0 to whatever fps you need
Wend
ptc_close()
end
Sub Stars
for a=0 to sf-1
x(a)=x(a)-s(a)
bib=int(rnd(1)*8)
if bib=3 and y(a)>1 then y(a)=y(a)-1:r=int(rnd(1)*255):g=r:b=g
if bib=6 and y(a)<yres-1 then y(a)=y(a)+1:r=int(rnd(1)*255):g=r:b=g
if y(a)<1 then y(a)=yres-1
if y(a)>yres-1 then y(a)=1
if x(a)<0 then x(a)=(xres-1):y(a)=1+(int(rnd(1)*yres)-1)
if y(a)<0 then x(a)=1
if y(a)>yres then x(a)=yres-1
pp(x(a),y(a),rgb(r,g,b))
next a
End Sub
Sub DLine(ypos,r as double,g as double,b as double,wid)
for a=0 to xres-1
for q=ypos to ypos+wid
pp(a,q,rgb(r,g,b))
next q
if r>32 then r=r-.2
if g>8 then g=g-.2
if b>4 then b=b-.2
next a
End Sub
Basically it allows for a parallax starfield effect in one routine . . . obviously been done before - just thought I would share my version with you guys?
DrewPee