;; ----------------------------------------------------------------------------
;; Irrlicht Wrapper For Imperative Languages - Purebasic Examples
;; ----------------------------------------------------------------------------
;; Example Irrklang_HelloWorld
;;This example will show how to play sounds using irrKlang.
;; It will play a looped background music and a sound every
;; time the user presses a key.
;; ----------------------------------------------------------------------------

EnableExplicit

;At first we need to Include the right importfile
XIncludeFile #PB_Compiler_Home + "Includes\IrrlichtWrapper_Include.pbi"

;Now doing the nessecary defines
Define Quit.l = #False                             ; Flag for quitting
Define *music_soundsource.l   = #Null     ; Pointer to a SoundSource
Define *fx_soundsource.l   = #Null            ; Pointer to a SoundSource
Define KeyPressed$ =""                          ; Key


;make a simple console programm !
If OpenConsole()
  
  ; Now lets start with irrKlang 3D sound engine example 01, demonstrating simple 2D sound.
  ; start up the sound engine using IrrKlangStart(). you can specify several
  ; Options as parameters when invoking that function, but for This example, the default
  ; parameters are enough.
  
  ; start the sound engine With Default parameters
  If IrrKlangStart()
    
    ;at first we add the Sounds as SoundSource to the engine
    ;We need the pointer to the SoundSource to start a Sound. Also we can
    ;define some initial parameters for playing this SoundSource.
    *music_soundsource = IrrKlangAddSound(".\media\getout.ogg")
    *fx_soundsource = IrrKlangAddSound(".\media\bell.wav")
     
    ; to play a sound, we only to call IrrKlangPlay2D(). the second parameter
    ; tells the engine To play It looped.
    IrrKlangPlay2D(*music_soundsource,#True)
    
    PrintN("Hello World!")
    PrintN("Press any key to play some sound, press 'q' to quit.")

    ;in A loop, wait Until user presses 'q' To exit Or another key To
    ;play another sound.
    Repeat
      KeyPressed$ = Inkey()
      
      If KeyPressed$ <> "" And KeyPressed$ <> "q"
        IrrKlangPlay2D(*fx_soundsource)
        
      ElseIf KeyPressed$ = "q"
        Quit=#True
      Else
        Delay(20) ; We save some time for other Application in our system ;-)
      EndIf
      
    Until Quit
    
  Else
    PrintN("Could not startup engine")
    End
  EndIf
  
  IrrKlangStop()
EndIf

End
  


; jaPBe Version=3.7.5.643
; Build=1
; Language=0x0000 Language Neutral
; FirstLine=22
; CursorPosition=42
; ExecutableFormat=Windows
; Executable=T:\projects\IrrlichtWrapperSVN\IrrlichtWrapper_1_05\PureBasic\Examples\IrrlichtWrapper\IrrKlang\Irrklang_helloworld.exe
; DontSaveDeclare
; EOF