Code : Tout sélectionner
EnableExplicit
Global camera
; Sommaire
Declare Start()
Declare DownLoad(Url.s)
Declare Exit()
CompilerIf Subsystem("OpenGL") = #False
MessageRequester("Information", "Vous devez activer OpenGL dans les options de compilation !")
Exit()
CompilerEndIf
Start()
Procedure Start()
Protected Window, ww, wh, Event
Protected Texture, Material, Mesh
Protected Ground, Box, Player, PlayerSpeed, CurrentAnimation.s
; Initialisation de l'environnemet 3D
If Not (InitEngine3D(#PB_Engine3D_DebugLog) And InitKeyboard() And InitSprite())
MessageRequester("Information", "Impossible d'initialiser l'environnement 3D")
Exit()
EndIf
; Window & Screen 3D
Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
ww = WindowWidth (Window, #PB_Window_InnerCoordinate)
wh = WindowHeight(Window, #PB_Window_InnerCoordinate)
SetWindowColor(Window, 0)
OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
; Localisation des elements 3D
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home +"Examples/3D/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()
KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
; Camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 10, 40)
; Environnement
SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)
CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, -1000)
WorldShadows(#PB_Shadow_Additive)
; Physics
EnableWorldPhysics(#True)
WorldGravity(-20)
;- Entités
Texture = LoadTexture(-1, "Dirt.jpg")
Material = CreateMaterial(-1, TextureID(Texture))
Mesh = CreatePlane(-1, 10000, 10000, 100, 100, 30, 30)
Ground = CreateEntity(-1, MeshID(Mesh), MaterialID(Material))
CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 0, 0)
Mesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 10, 600, -40)
ScaleEntity(Player, 25, 25, 25)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 20)
EntityAngularFactor(Player, 0, 1, 0)
Texture = LoadTexture(-1, "Caisse.png")
Material = CreateMaterial(-1, TextureID(Texture))
Mesh = CreateCube(-1, 100)
Box = CreateEntity(-1, MeshID(Mesh), MaterialID(Material), 200, 600, 500)
CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
; Render
While #True
event = WindowEvent()
ExamineKeyboard()
ExamineKeyboard()
;-Evenement clavier : Déplacement
If KeyboardPushed (#PB_Key_Up)
PlayerSpeed = 300
CurrentAnimation = "RunBase"
ElseIf KeyboardPushed (#PB_Key_Down)
PlayerSpeed = -300
CurrentAnimation = "RunBase"
Else
CurrentAnimation = "IdleTop"
PlayerSpeed = 0
EndIf
;-Evenement clavier : Rotation
If KeyboardPushed (#PB_Key_Left)
RotateEntity(Player, 0, 3, 0, #PB_Relative)
CurrentAnimation = "RunBase"
ElseIf KeyboardPushed (#PB_Key_Right)
RotateEntity(Player, 0, -3, 0, #PB_Relative)
CurrentAnimation = "RunBase"
EndIf
If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
Exit()
EndIf
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 125, 500, 1, #True)
;Play animation
If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
StartEntityAnimation(Player, CurrentAnimation)
EndIf
RenderWorld()
FlipBuffers()
Wend
EndProcedure
Procedure Exit()
End
EndProcedure