StarsFields

Developed or developing a new product in PureBasic? Tell the world about it.
Keph_
User
User
Posts: 13
Joined: Fri Apr 25, 2003 6:10 pm

StarsFields

Post by Keph_ »

Passant
New User
New User
Posts: 9
Joined: Sun May 11, 2003 12:33 am

Post by Passant »

nice work
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: StarsFields

Post by PB »

> http://103683.free.fr/purebasic/stars3d.exe (64 Kb)

Can't run this one on W2K Pro... I get an error saying "Impossible de lire
la police".
starax
User
User
Posts: 26
Joined: Sun Jun 01, 2003 7:28 pm

Stars

Post by starax »

Twinkle twinkle.


;More stars
#scrw = 1600
#scrh = 1200

#centerofscrw = #scrw/2
#centerofscrh = #scrh/2

#scrd = 16

SSum.w = 8000 ; Amount of Stars


Cspeed.f=1
CameraZ.f=0

Gosub InitStarField

;-------- Init all needed Stuff --------
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageBox_ (0,"Can't open DirectX 7 or later", "blahhhh", #MB_ICONINFORMATION|#MB_OK)
End
EndIf

If OpenScreen(#scrw,#scrh,#scrd,"benny's code") = 0
MessageBox_ (0,"Could not open screen", "blahhh blaa", #MB_ICONINFORMATION|#MB_OK)
End
EndIf

SetFrameRate(90)


;-------- MainLoop --------
Repeat
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
DrawingMode(1)
Gosub DrawStarField
Gosub MoveCamera
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End


;--------- Procs / Subs -------------


; #### INITSTARFIELD ####
InitStarField:
; Structure of a star ...
Structure 3DStar
x.f ; X-Coordinate
y.f ; Y-Coordinate
z.f ; Z-Coordinate
EndStructure

; Init Starfield ...
Dim Stars.3DStar(SSum)
For dummy = 0 To SSum-1
Stars(dummy)\x = Random(10000)-5000
Stars(dummy)\y = Random(10000)-5000
Stars(dummy)\z = 100 + Random(1000)
Next dummy
Return


; ### Move Camera ###
MoveCamera:
If CameraZ>1000
Direction=-1
ElseIf CameraZ<-1000
Direction=1
EndIf
If Direction=1 And Cspeed<10
Cspeed=Cspeed+0.01
ElseIf Direction=-1 And Cspeed>-10
Cspeed=Cspeed-0.01
EndIf
CameraZ=CameraZ+Cspeed
Return



; #### Draw StarField ####
DrawStarField:
For dummy = 0 To SSum-1
If Stars(dummy)\z<CameraZ
Stars(dummy)\z=CameraZ+1000
ElseIf Stars(dummy)\z>(CameraZ+1000)
Stars(dummy)\z=CameraZ
EndIf

SX = Stars(dummy)\x / (Stars(dummy)\z-CameraZ)*100+#centerofscrw
SY = Stars(dummy)\y / (Stars(dummy)\z-CameraZ)*100+#centerofscrh

If SX<#scrw And SY<#scrh And SX>0 And SY>0
b.f = 255-(((Stars(dummy)\z)-CameraZ)*(255./1000.))
c=Int(b)
Plot ( SX, SY, RGB(c,c,c))
EndIf

Next dummy
Return
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Re: Stars

Post by TronDoc »

starax wrote:Twinkle twinkle.


;More stars
#scrw = 1600
#scrh = 1200
I had to do this for my "poor" PC:

Code: Select all

;More stars
; #scrw = 1600
; #scrh = 1200
#scrw = 800
#scrh = 600
Joe
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Re: StarsFields

Post by TronDoc »

Keph_ wrote:Just 2 littles progs:
http://103683.free.fr/purebasic/stars3d.exe (64 Kb)
http://103683.free.fr/purebasic/tunnel.exe (108 Kb)
Keph
cool!
after staring at the tunnel and then switching back
to a normal screen it took awhile for it to stop moving! LOL Joe
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

Salut Keph_,

Run without problem under Win98SE.
Nice work.



Denis
A+
Denis
Post Reply