Avec le code ci-dessous, j'affiche notre ami Sinbad.
■ Utilisation.
Pour faire évoluer Sinbad, vous pouvez utiliser les touche fléchées ou bien les touches QZSD habituellement utilisées.
Vous pouvez aussi utiliser la souris pour l'orienter à droite ou à gauche. La souris permet aussi de changer l'angle de vue verticale. La touche Esc permet de quitter ce test.
■ Les soucis rencontrés.
Le cône de lumière qui se déplace avec Sinbad est fluide avec PB 5.73. Ce qui n'est pas le cas avec PB 6.01.
La souris est inutilisable avec PB 5.73. Ce qui n'est pas le cas avec PB 6.01.
Pouvez vous tester ce code et me dire si vous rencontrez ces différences de comportement.
Code : Tout sélectionner
EnableExplicit
Enumeration
#Mainform
EndEnumeration
; Fenetre principale
Global Window, Event
; Sol
Global Ground, GroundMesh, GroundMat
; Player
Global Player, PlayerMesh, Rotation.f, PlayerSpeed.f, CurrentAnimation.s
; Camera
Global Camera, Hight.f = 3, Distance.f = -30
; Lumiere
Global Light
InitEngine3D() : InitKeyboard() : InitSprite() : InitMouse()
Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))
; Localisation des assets
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()
; Configuration du clavier
KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
; Ciel, lumiere et ombre
SkyBox("desert07.jpg")
Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 0, 0, #PB_Light_Spot)
SpotLightRange(Light, 30, 100, 1)
AmbientColor(0)
WorldShadows(#PB_Shadow_Additive, 100, RGB(255, 0, 0), 1024)
; Création du sol
GroundMesh = CreatePlane(#PB_Any, 2000, 2000, 200, 200, 200, 200)
GroundMat = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "Dirt.jpg")))
Ground = CreateEntity(#PB_Any, MeshID(GroundMesh), MaterialID(GroundMat))
CreateEntityBody(Ground, #PB_Entity_StaticBody, 1, 1, 1)
; Player
PlayerMesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(#PB_Any, MeshID(PlayerMesh), #PB_Material_None)
CreateEntityBody(Player, #PB_Entity_BoxBody, 0.1, 0, 0)
EntityAngularFactor(Player, 0, 1, 0)
; Camera
Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
CameraBackColor(Camera, RGB(145, 182, 201))
; Loop
Repeat
; Evenements window
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
; Evenements souris
If ExamineMouse()
; Rotation du player
Rotation = -MouseDeltaX() * 0.25
; Hauteur de la camera
Hight + MouseDeltaY() * 0.1
If Hight < -4
Hight= -4
EndIf
; Distance de la caméra par rapport au player
Distance + MouseWheel()
EndIf
; Evenements claviers
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left) Or KeyboardPushed(#PB_Key_Q)
Rotation = 0.5
ElseIf KeyboardPushed(#PB_Key_Right) Or KeyboardPushed(#PB_Key_D)
Rotation = -0.5
EndIf
If KeyboardPushed(#PB_Key_Up) Or KeyboardPushed(#PB_Key_Z)
PlayerSpeed = 15
CurrentAnimation = "RunBase"
ElseIf KeyboardPushed(#PB_Key_Down) Or KeyboardPushed(#PB_Key_S)
PlayerSpeed = -15
CurrentAnimation = "RunBase"
Else
PlayerSpeed = 0
CurrentAnimation = "IdleTop"
EndIf
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
EndIf
; Action joueur (Position, Rotation, Animation)
RotateEntity(Player, 0, Rotation, 0, #PB_Relative)
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
StartEntityAnimation(Player, CurrentAnimation)
EndIf
; Action camera
CameraFollow(Camera, EntityID(Player), 0, EntityY(Player) + Hight, Distance, 1, 1, #True)
; Action lumiere :
MoveLight(Light, EntityX(Player), 50, EntityZ(Player), #PB_Absolute)
;
; Rendering de la scene
RenderWorld()
FlipBuffers()
ForEver