Could this be my PC doing something in the background or do you guys get the same thing? Is it a problem with the Code?
Code: Select all
;===========================================================================
;-CONSTANTS
;===========================================================================
#APP_NAME = "Stars v1.0"
#NUMBER_OF_STARS = 500
;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================
Global Quit.b
Fade.l = 0
Structure Star
xPos.f
yPos.f
xStep.f
colour.l
EndStructure
Dim Stars.Star(#NUMBER_OF_STARS)
;===========================================================================
;-PROCEDURES
;===========================================================================
;simple error checking
Procedure HandleError(result, text.s)
If result = 0 : MessageRequester("Error", text, #PB_MessageRequester_Ok) : End : EndIf
EndProcedure
;init stars
Procedure InitStars()
For x = 0 To #NUMBER_OF_STARS - 1
Stars(x)\xPos = Random(640)
Stars(x)\yPos = Random(220)
If x < #NUMBER_OF_STARS / 3
Stars(x)\xStep = (Random(100) / 100) + 0.1
Stars(x)\colour = RGB(70, 70, 70)
ElseIf x >= #NUMBER_OF_STARS / 3 And x < (#NUMBER_OF_STARS / 3) * 2
Stars(x)\xStep = (Random(100) / 100) + 0.2
Stars(x)\colour = RGB(140, 140, 140)
Else
Stars(x)\xStep = (Random(100) / 100) + 0.3
Stars(x)\colour = RGB(255, 255, 255)
EndIf
Next x
EndProcedure
;move stars on the 'x' axis
Procedure MoveStarsX()
For x = 0 To #NUMBER_OF_STARS - 1
Stars(x)\xPos - Stars(x)\xStep
If Stars(x)\xPos < 0
Stars(x)\xPos = 640
Stars(x)\yPos = Random(220)
EndIf
Next x
EndProcedure
;===========================================================================
;-GEOMETRY / SCREEN
;===========================================================================
HandleError(InitSprite(), "Error Initialising DirectX:"+Chr(10)+"Microsoft DirectX v7.0+ must be installed correctly."+Chr(10)+"Offending Command: InitSprite()")
HandleError(InitKeyboard(), "Error Initialising DirectX:"+Chr(10)+"Microsoft DirectX v7.0+ must be installed correctly."+Chr(10)+"Offending Command: InitKeyboard()")
HandleError(OpenScreen(640, 480, 32, #APP_NAME), "640x480 32bit Screen could not be opened correctly.")
ChangeGamma(0, 0, 0, 1)
InitStars()
;===========================================================================
;-MAIN LOOP
;===========================================================================
Repeat
FlipBuffers()
ClearScreen(0, 0, 0)
StartDrawing(ScreenOutput())
For x = 0 To #NUMBER_OF_STARS - 1
Plot(Stars(x)\xPos, Stars(x)\yPos, Stars(x)\colour)
Next x
StopDrawing()
MoveStarsX()
If Fade < 255
Fade + 4
ChangeGamma(Fade, Fade, Fade, 0)
EndIf
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
Repeat
ChangeGamma(Fade, Fade, Fade, 0)
Fade - 4
Until Fade <= 0
Quit = 1
EndIf
Delay(1)
HandleError(IsScreenActive(), "'Alt-Tabbing' is not yet supported.")
Until Quit = 1
End


