Contrôlez Sinbad avec les flèches du clavier pour le déplacer.
Une camera va suivre Sinbad.
- Ctrl + Up ou Down pour diminuer ou augmenter la distance entre la camera et Sinbad.
- Ctrl + Left ou Right pour tourner autour de Sinbad.
J'ai laissé volontairement un débug montrant que très souvent Sindbad n'est pas en contact avec le sol.
Hors j'ai besoin de cette information pour pouvoir coder d'autres actions. Par exemple quand je voudrais lui faire effectuer des sauts et dans ce cas, pas de nuages de poussières. Comment puis je faire autrement ?
Une autre question : La gravité par défaut est celle ce la terre. Hors quand Sinbad tombe dans le vide il tombe au ralenti.
Merci de votre aide.
Code : Tout sélectionner
;[PB 5.60 Minimum]
EnableExplicit
;Font
Global FontInfo = LoadFont(-1, "Arial", 12)
;Material
Global MatGround, MatBox, MatSmoke
;Entities
Global Camera, Player, PlayerSpeed, CurrentAnimation.s, Angle = 0, Distance = 200, Action
Global Ground, Box
;Sprite
Global Bottom
;Init engine
If Not (InitEngine3D() And InitSprite() And InitKeyboard())
End
EndIf
OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))
;The elements are in the examples folder of PureBasic
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)
EnableWorldPhysics(#True)
;-[2D] Create ou load sprite (Help)
Bottom = CreateSprite(-1, ScreenWidth(), 150, #PB_Sprite_AlphaBlending)
;-[3D] Create ou load 3D element
;-Textures
MatGround = CreateMaterial(-1, TextureID(LoadTexture(-1, "Dirt.jpg"))) ;Ground material
MatBox = CreateMaterial(-1, TextureID(LoadTexture(-1, "Caisse.png"))) ;Box materiel
MatSmoke = CreateMaterial(-1, TextureID(LoadTexture(-1, "smoke.png"))) ;Particule materiel
MaterialBlendingMode(MatSmoke, #PB_Material_AlphaBlend)
DisableMaterialLighting(MatSmoke, 1)
;-Camera
Camera = CreateCamera(-1, 0, 0, 100, 100)
;-Sky and fog
SkyBox("desert07.jpg", RGB(255, 255, 255), 1, 900, 6000)
Fog(RGB(255, 255, 255), 1, 100, 1000)
;-Light and shadow
CreateLight(0, RGB(255, 255, 255), -100, 500, 100)
WorldShadows(#PB_Shadow_Additive)
;-Ground
Ground = CreateEntity(-1, MeshID(CreatePlane(-1, 1500, 1500, 1, 1, 20, 20)), MaterialID(MatGround))
CreateEntityBody(Ground, #PB_Entity_StaticBody)
;-Box
Box = CreateEntity(-1, MeshID(CreateCube(-1, 20)), MaterialID(MatBox), 0, 15, 0)
CreateEntityBody(Box, #PB_Entity_BoxBody, 1, 1, 1)
;-Player
Player = CreateEntity(-1, MeshID(LoadMesh(#PB_Any, "sinbad.mesh")), #PB_Material_None, 10, 40, -40)
ScaleEntity(Player, 5, 5, 5)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 20)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, -120, 0)
;- Dust emiter / Emetteur de poussiére
CreateParticleEmitter(0, 10, 10,0, #PB_Particle_Box)
ParticleMaterial(0, MaterialID(MatSmoke))
ParticleSize(0, 20, 20)
ParticleEmissionRate(0, 20)
ParticleEmitterDirection(0,0,1,0)
ParticleVelocity(0, #PB_Particle_Velocity, 20)
ParticleTimeToLive(0, 1, 1)
ParticleColorFader(0,0,0,0,-1)
Repeat
;-
;-[3D] Rendering
If ExamineKeyboard()
;-Test collision
Debug "EntityCollide(Ground, Player) " + Str(EntityCollide(Ground, Player))
;-keyboard events : Distance and move
If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Up)
Distance - 5
ElseIf KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Down)
Distance + 5
ElseIf KeyboardPushed (#PB_Key_Up)
PlayerSpeed = 50
CurrentAnimation = "RunBase"
Angle = 180
Action = #True
ElseIf KeyboardPushed (#PB_Key_Down)
PlayerSpeed = -50
Angle = 0
CurrentAnimation = "RunBase"
Action = #True
Else
CurrentAnimation = "IdleTop"
PlayerSpeed = 0
Action = #False
EndIf
;-keyboard events : Rotation around player and turn
If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Left)
Angle - 5
ElseIf KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Right)
Angle + 5
ElseIf 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 KeyboardReleased(#PB_Key_Escape)
Break
EndIf
EndIf
If Action
DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
;Move player to new position
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
EndIf
;Play animation
If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
StartEntityAnimation(Player, CurrentAnimation)
EndIf
;End of dust if the player does not move or not in contact with the ground
MoveParticleEmitter(0,EntityX(Player), 0 ,EntityZ(Player),#PB_Absolute)
DisableParticleEmitter(0,Bool(action=0))
CameraFollow(Camera, EntityID(Player), Angle, EntityY(Player) + 20, Distance, 0.05, 1, #True)
RenderWorld(50)
;-
;-[2D] Rendering
StartDrawing(SpriteOutput(Bottom))
DrawingFont(FontID(FontInfo))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0, 0, ScreenWidth(), SpriteWidth(Bottom), RGBA(0, 0, 0, 110))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, ". : : Help : : .")
DrawText(10, 40, "Arrow keys - Move player.")
DrawText(10, 70, "Ctrl + Up / Ctrl + Down - Distance between camera and player.")
DrawText(10, 100, "Ctrl + Left ou Ctrl + Right - Turn around the player.")
StopDrawing()
DisplayTransparentSprite(Bottom, 0, ScreenHeight() - SpriteHeight(Bottom))
FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow