Outils pour utilisateurs

Outils du site


playground:music

14-Music.sb

Voir

14-Music.sb
;Babylon.sbi - Music
 
EnableExplicit
 
IncludeFile "babylon/babylon.sbi"
UseModule BJS
 
Global Scene, Camera, Light, Pop, Ground, GroundTex, GroundMat, Mesh
 
Declare LoadGame()
Declare RenderGame()
 
InitEngine(@LoadGame())
 
Procedure LoadGame()    
  Scene = CreateScene()
  If Scene
 
    ;Load Music
    MusicLoad("Loop", "data/sounds/loop.mp3", #True, #True)
    Pop = MusicLoad("pop", "data/sounds/pop.wav")
 
    ;Camera
    Camera = CreateCamera("camera", 0, 40, 20, #BJS_Free)
    CameraBodySize(Camera, 2, 20, 2)
    CameraLookAt(Camera, 500, 10, 1000)
    ClearScene(RGB(0, 0, 0))
    CreateLight("ambience", 0, 200, 0, 0.4)
    Light = CreateLight("Point", 0, 200, 0, 1, #BJS_Point)
 
    ;Ground
    Ground = CreateGround("Ground", 5000, 5000, 4)
    GroundTex = LoadTexture("Ground", "data/textures/Beton1.png")
    GroundMat = CreateMaterial("Ground")
    SetMaterialTexture(GroundMat, #BJS_Diffuse, GroundTex)
    SetMaterialColor(GroundMat, #BJS_Specular, RGBA(0, 0, 0, 255))
    ScaleMaterial(GroundMat, 40, 40)
    SetMeshMaterial(Ground, GroundMat)    
    CreateMeshBody(Ground, #BJS_PlaneBody, 0, 0, 0)
 
    ;Shadow
    InitShadow(Light, 2048)
    RenderShadows(Ground)
 
    ;!v_bjsengine.hideLoadingUI()
    RenderLoop(@RenderGame())
  EndIf
EndProcedure
 
Procedure RenderGame()  
  Select Random(1000, 1)
    Case 5, 25, 35
 
      Mesh = CreateSphere("sphere", Random(40, 20))
      MoveMesh(Mesh, Random(500, 200), Random(500, 200), Random(500, 200))
      CreateMeshBody(Mesh, #BJS_SphereBody, 10, 0.5, 0.5)
      ShadowEmitter(Mesh)
      MusicPlay(Pop)
 
    Case 10, 20, 30
      Mesh = CreateBox("Box", 1, 1, 1)
      ScaleMesh(Mesh, Random(40, 20), Random(20, 10), Random(40, 20))  
      MoveMesh(Mesh, Random(500, 200), Random(500, 200), Random(500, 200))
      CreatemeshBody(Mesh, #BJS_BoxBody, 10, 0.5, 0.5)
      RotateMesh(Mesh, 0, Random(360), 0)
      ShadowEmitter(Mesh)
      MusicPlay(Pop)
 
  EndSelect
 
  RenderWorld() 
EndProcedure
playground/music.txt · Dernière modification: 2018/01/11 02:02 par falsam