Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ------------------------------------------------------------
- ;
- ; Parallax Starfield (4 layers)
- ;
- ; Code by aNdy/AL/Cosine in 2018
- ;
- ; https://andyvaisey.blogspot.com/p/code.html
- ;
- ; ------------------------------------------------------------
- ;- INITIALISE ENVIRONMENT ------------------------------------
- InitKeyboard()
- InitSprite()
- ;- CREATE VARIABLES ------------------------------------------
- #XRES = 800
- #YRES = 600
- #LAYER1SPEED = 1
- #LAYER2SPEED = 3
- #LAYER3SPEED = 5
- #LAYER4SPEED = 10
- ;- PROCEDURES ------------------------------------------------
- Procedure OpenMainWindow()
- OpenWindow(0,0,0,#XRES,#YRES,"Parallax Stars!",#PB_Window_ScreenCentered)
- OpenWindowedScreen(WindowID(0),0,0,#XRES,#YRES)
- EndProcedure
- Procedure CreateStarfields()
- Global sp_BKGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
- StartDrawing(SpriteOutput(sp_BKGRDSTAR))
- For n=0 To 999
- Plot(Random(#XRES-1),Random(#YRES-1),RGB(100,100,100))
- Next
- StopDrawing()
- Global sp_MDGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
- StartDrawing(SpriteOutput(sp_MDGRDSTAR))
- For n=0 To 299
- Plot(Random(#XRES-1),Random(#YRES-1),RGB(150,150,150))
- Next
- StopDrawing()
- Global sp_FTGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
- StartDrawing(SpriteOutput(sp_FTGRDSTAR))
- For n=0 To 199
- Plot(Random(#XRES-1),Random(#YRES-1),RGB(200,200,200))
- Next
- StopDrawing()
- Global sp_CLGRDSTAR = CreateSprite(#PB_Any,#XRES,#YRES)
- StartDrawing(SpriteOutput(sp_CLGRDSTAR))
- For n=0 To 19
- Plot(Random(#XRES-1),Random(#YRES-1),RGB(255,255,255))
- Next
- StopDrawing()
- EndProcedure
- Procedure DrawStarfields()
- Shared bgx1, bgx2, bgx3, bgx4
- For s1 = 0 To 1
- For s2 = 0 To 1
- DisplayTransparentSprite(sp_BKGRDSTAR,#XRES*s1-bgx1,#YRES*s2)
- DisplayTransparentSprite(sp_MDGRDSTAR,#XRES*s1-bgx2,#YRES*s2)
- DisplayTransparentSprite(sp_FTGRDSTAR,#XRES*s1-bgx3,#YRES*s2)
- DisplayTransparentSprite(sp_CLGRDSTAR,#XRES*s1-bgx4,#YRES*s2)
- Next
- Next
- bgx1+#LAYER1SPEED : If bgx1 > #XRES-1 : bgx1=0 : EndIf
- bgx2+#LAYER2SPEED : If bgx2 > #XRES-1 : bgx2=0 : EndIf
- bgx3+#LAYER3SPEED : If bgx3 > #XRES-1 : bgx3=0 : EndIf
- bgx4+#LAYER4SPEED : If bgx4 > #XRES-1 : bgx4=0 : EndIf
- EndProcedure
- ;- BEGIN PROGRAM ----------------------------------------------------
- OpenMainWindow()
- CreateStarfields()
- HideWindow(0,#False)
- ;- MAIN PROGRAM LOOP ------------------------------------------------
- Repeat
- WaitWindowEvent(1)
- ClearScreen(0)
- DrawStarfields()
- FlipBuffers()
- ExamineKeyboard()
- Until KeyboardPushed(#PB_Key_Escape)
- ;- EXIT PROGRAM ----------------------------------------------------
- FreeSprite(#PB_All)
- CloseWindow(#PB_All)
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement