;*****************************************************************************************************
; Progam name : Fireworks.pb
; Version     : 1.00
; Build       : 0001
; PB Version  : 5.62
; Auther      : B.J.Fernhout.
; Copyright   : None
; Date        : 2018
; Discription : Include file to create firwork of stone going over the screen starting from a special
;             : place on the screen
;             :
;*****************************************************************************************************

;Initialize all 60 sparkels
Procedure InitSparkels()
  Protected x
  Protected Recalc.f
  For x = 1 To 60   ;The 0 is forgotten here
    Recalc = (Random(200,1)-100)/1000
    FireWork(x)\DirectionX = Recalc
    Firework(x)\DirectionY = FireWorkMove
    FireWork(x)\PosX = 320.0
    FireWork(x)\PosY = 450.0
    FireWork(x)\Speed = FireWorkMove + (Random(100,1)/700)
    FireWork(x)\JewelPoint = Random(6,1)
  Next
  
EndProcedure
;Just reinitialize one list item
Procedure ReInitSpark(ItemNumber.i)
  Protected Recalc.f
  ;RandomSeed(ElapsedMilliseconds())
  Recalc = (Random(200,1)-100)/1000
  FireWork(ItemNumber)\DirectionX = Recalc
  Firework(ItemNumber)\DirectionY = FireWorkMove
  FireWork(ItemNumber)\PosX = 320.0
  FireWork(ItemNumber)\PosY = 450.0
  FireWork(ItemNumber)\Speed = FireWorkMove + (Random(100,1)/700)
  FireWork(ItemNumber)\JewelPoint = Random(6,1)
  
EndProcedure
Procedure ShowSparkels()
  Protected x
  ClearScreen(0)
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(Im_MainScreen),0,0)
  For x = 1 To 60
    DrawImage(ImageID(JewColors(FireWork(x)\JewelPoint)),FireWork(x)\PosX,FireWork(x)\PosY)
  Next
  StopDrawing()
  FlipBuffers()
EndProcedure
;Let them fly over the screen
Procedure ExecuteSpakels()
  Protected x,y
  Protected Tim_ShowTime  = ElapsedMilliseconds() + 30000
  
  Repeat
    For x = 1 To 60
      If FireWork(x)\PosX < -32 Or FireWork(x)\PosX > 640 Or FireWork(x)\PosY < -32 Or FireWork(x)\jewelPoint = 0
        ;A new sparkel nust be made
        ReInitSpark(x)
      EndIf
      If FireWork(x)\DirectionX <= 0
        FireWork(x)\PosX = FireWork(x)\PosX + FireWork(x)\DirectionX - FireWork(x)\Speed
      Else
        FireWork(x)\PosX = FireWork(x)\PosX + FireWork(x)\DirectionX + FireWork(x)\Speed
      EndIf
      FireWork(x)\PosY = FireWork(x)\PosY - Firework(x)\DirectionY - FireWork(x)\Speed 
      ;check out player action
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape)
        ;Player want to quit the game
        Old_Step = Active_Case
        Active_Case = 25
        ProcedureReturn
      EndIf
      If KeyboardPushed(#PB_Key_Space)
        ;Player want to start the game
        Active_Case = 5
        ProcedureReturn
      EndIf 
    Next
    ShowSparkels()
    ;event = WindowEvent()
  Until ElapsedMilliseconds() > Tim_ShowTime
  Active_Case = 3
  
EndProcedure
;Main call field
Procedure DoFirework()
  
  InitSparkels()
  ExecuteSpakels()
  
EndProcedure


; IDE Options = PureBasic 5.62 (Windows - x64)
; CursorPosition = 84
; FirstLine = 13
; Folding = 5
; EnableXP
; CompileSourceDirectory
; EnableCompileCount = 0
; EnableBuildCount = 0
; EnableExeConstant