could anyone point me in right directions pls...
cheers

Code: Select all
MAX_STAR=5000
STAR_SPEED=2
WIDTH=640
HEIGHT=480
Dim star_x(MAX_STAR)
Dim star_y(MAX_STAR)
Dim star_z(MAX_STAR)
OpenScreen(WIDTH,HEIGHT,32,"")
SetFrameRate(60)
setup_stars()
InitKeyboard()
ExamineKeyboard()
Repeat
ClearScreen(0)
UpdateStar()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure setup_stars()
For c=0 To MAX_STAR
star_x(c)=Rnd(-(WIDTH/2),(WIDTH/2))Shl 8
star_y(c)=Rnd(-(HEIGHT/2),(HEIGHT/2))Shl 8
star_z(c)=Rnd(STAR_SPEED,255)
Next
EndProcedure
Procedure UpdateStar()
For c=0 To MAX_STAR
star_z(c)=star_z(c)-STAR_SPEED
If star_z(c)<=STAR_SPEED Then star_z(c)=255
s_x=(star_x(c)/star_z(c))+(WIDTH/2)
s_y=(star_y(c)/star_z(c))+(HEIGHT/2)
col=255-star_z(c)
FrontColor(Col)
Plot s_x,s_y,255
Plot(s_x, s_y, RGB(255), (255), (255))
Next
EndProcedure
Code: Select all
Global MAX_STAR = 25000
Global STAR_SPEED.f = 0.1
Global Width = 1024
Global Height = 768
Structure VECTOR3f
X.f
Y.f
Z.f
EndStructure
Global Dim Star.VECTOR3f(MAX_STAR)
InitSprite()
InitKeyboard()
OpenScreen(Width,Height,32,"")
Procedure setup_stars()
For c=0 To MAX_STAR
Star(c)\X = Random(Width)-(Width/2)
Star(c)\Y = Random(Height)-(Height/2)
Star(c)\Z = (Random(100000)/100000.0)*255
Next
EndProcedure
Procedure UpdateStar()
StartDrawing(ScreenOutput())
For c = 0 To MAX_STAR
Star(c)\Z - STAR_SPEED
If Star(c)\Z < 1 : Star(c)\Z + 255 : EndIf
s_x.f = (Star(c)\X / (Star(c)\Z)+(Width/2.0))
s_y.f = (Star(c)\Y / (Star(c)\Z)+(Height/2.0))
col=255 - Star(c)\Z
If s_x < 0 : s_x = 0 : EndIf
If s_y < 0 : s_y = 0 : EndIf
If s_x >= Width-1 : s_x = Width -1 : EndIf
If s_y >= Height-1 : s_y = Height - 1 : EndIf
Plot(s_x, s_y, RGB(col,col,col))
Next
StopDrawing()
EndProcedure
SetFrameRate(60)
setup_stars()
Repeat
ExamineKeyboard()
ClearScreen(0)
UpdateStar()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Code: Select all
Global Width = 1024
Global Height = 768
Global num_stars = 200
InitSprite()
InitKeyboard()
OpenScreen(Width,Height,32,"")
Dim X(num_stars,4)
Dim y(num_stars,3)
SetFrameRate(60)
; Generate the stars
For i=0 To num_stars-1
x(i,2)=Random(639)+1 ; X
y(i,2)=Random(479)+ 1 ; Y
x(i,3)=Random(5)+1 ; Speed
Next
Repeat
ExamineKeyboard()
ClearScreen(0)
UpdateStar()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure UpdateStar()
StartDrawing(ScreenOutput())
For i = 0 To num_stars-1
x(i,2)= x(i,2)-x(i,3)
;' If Starfield go pass go off the screen
; ' Restart the starfield
If x(i,2)=<0
x(i,2) = 800
;(i,2) = Rnd(479) +1
EndIf
col = 255
Plot(x(i,2), y(i,2), RGB(col,col,col)))
Next
StopDrawing()
EndProcedure
Add this at the top of your code:Swos2009 wrote:thanks everyone
I have try to make 2D Starfields but it wont run for some reason
Code: Select all
Declare UpdateStar()
Code: Select all
Plot(x(i,2), y(i,2), RGB(Col,Col,Col))
Code: Select all
Global Width = 1024
Global Height = 768
Global num_stars = 200
Declare UpdateStar()
InitSprite()
InitKeyboard()
OpenScreen(Width,Height,32,"")
Dim x(num_stars,4)
Dim y(num_stars,3)
SetFrameRate(60)
; Generate the stars
For i=0 To num_stars-1
x(i,2)=Random(639)+1 ; X
y(i,2)=Random(479)+ 1 ; Y
x(i,3)=Random(5)+1 ; Speed
Next
Repeat
ExamineKeyboard()
ClearScreen(0)
UpdateStar()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure UpdateStar()
StartDrawing(ScreenOutput())
For i = 0 To num_stars-1
x(i,2)= x(i,2)-x(i,3) ; <<<< Why error?
;' If Starfield go pass go off the screen
; ' Restart the starfield
If x(i,2)=<0
x(i,2) = 800
;(i,2) = Rnd(479) +1
EndIf
col = 255
Plot(x(i,2), y(i,2), RGB(Col,Col,Col))
Next
StopDrawing()
EndProcedure
Add Global before each of the Dim's.Swos2009 wrote:thanks demivec for pointing out
I still get error saying "is not function , array, marco or linked lists"[/code]
Code: Select all
Global Width = 1024
Global Height = 768
Global num_stars = 200
Declare UpdateStar()
InitSprite()
InitKeyboard()
OpenScreen(Width,Height,32,"")
Global x
Global y
Dim x(num_stars,4)
Dim y(num_stars,3)
SetFrameRate(60)
; Generate the stars
For i=0 To num_stars-1
x(i,2)=Random(639)+1 ; X
y(i,2)=Random(479)+ 1 ; Y
x(i,3)=Random(5)+1 ; Speed
Next
Repeat
ExamineKeyboard()
ClearScreen(0)
UpdateStar()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure UpdateStar()
StartDrawing(ScreenOutput())
For i = 0 To num_stars-1
x(i,2)= x(i,2)-x(i,3)
;' If Starfield go pass go off the screen
; ' Restart the starfield
If x(i,2)=<0
x(i,2) = 800
;(i,2) = Rnd(479) +1
EndIf
col = 255
Plot(x(i,2), y(i,2), RGB(Col,Col,Col))
Next
StopDrawing()
EndProcedure
Code: Select all
Global x
Global y
Dim x(num_stars,4)
Dim y(num_stars,3)
Code: Select all
Global Dim x(num_stars,4)
Global Dim y(num_stars,3)
I didnt know puerbasic could do this and my 2D Starfields is work greatGlobal Dim x(num_stars,4)
Global Dim y(num_stars,3)
You have more than a few choices on how to store the starfield information. For instance you could use an array of structures that each contain {x, y, x_speed, y_speed}. I think you should use whatever you're most comfortable with, most choices are interchangeable with only minor changes.Swos2009 wrote:Thanks Demvic
I didnt know puerbasic could do this and my 2D Starfields is work greatGlobal Dim x(num_stars,4)
Global Dim y(num_stars,3)
Do you think I should do 2D Starfields in Structure rather than Dim Arrays?
My next attept would be 2D Rotation Stafields