Hello.
Sinbad and his brother are at the pool and I need help with this code.
Why I have no shadow?
The code is functional and uses the assets of the PureBasic examples.
Thank you for your help.
Code: Select all
EnableExplicit
;Police
Global FontInfo = LoadFont(-1, "Arial", 12)
;Textures
Global MatGround, MatBox, MatBuoy
;Entities
Global Camera, CameraHeight = 125, Brother, Player, PlayerSpeed, CurrentAnimation.s, Angle = 180, Distance = 500
Global Ground, Box, buoy0, buoy1
;Dust emiter / Emetteur de poussieres
Global NewList Emiters()
;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/Water", #PB_3DArchive_FileSystem)
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/waterworld.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)
EnableWorldCollisions(#True)
WorldGravity(-10)
;-[2D] Create ou load sprite
Bottom = CreateSprite(-1, ScreenWidth(), 150, #PB_Sprite_AlphaBlending)
;-[3D] Create ou load 3D element
;-Textures & material
MatGround = CreateMaterial(-1, TextureID(LoadTexture(-1, "Floor02.jpg"))) ;Ground
ScaleMaterial(MatGround, 0.5, 0.5)
MatBox = CreateMaterial(-1, TextureID(LoadTexture(-1, "Caisse.png"))) ;Box
MatBuoy = CreateMaterial(-1, TextureID(LoadTexture(-1, "ogrelogo-small.jpg"))) ;Buoy
;-Camera
Camera = CreateCamera(-1, 0, 0, 100, 100)
;Sky and fog
SkyBox("desert07.jpg")
;-Light and shadow
CreateLight(0, RGB(255, 255, 255), -100, 500, 100)
;WorldShadows(#PB_Shadow_Additive) ;Fontionne pas
WorldShadows(#PB_Shadow_TextureAdditive)
;-Sea
Sun(0, 10000, 10000, RGB(255, 255, 255))
CreateWater(Camera, 0, 135, 0, 0, #PB_World_WaterLowQuality | #PB_World_WaterSmooth)
;-Ground
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 0, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 1000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 1000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 0, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
;-Box
Box = CreateEntity(-1, MeshID(CreateCube(-1, 100)), MaterialID(MatBox), -500, 200, 0)
CreateEntityBody(Box, #PB_Entity_StaticBody)
;-Player
Player = CreateEntity(-1, MeshID(LoadMesh(#PB_Any, "sinbad.mesh")), #PB_Material_None, 10, 275, -40)
ScaleEntity(Player, 25, 25, 35)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 40)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, -120, 0)
;-Brother
Brother = CreateEntity(-1, MeshID(LoadMesh(#PB_Any, "sinbad.mesh")), #PB_Material_None, 27, 120, 1000)
ScaleEntity(Brother, 25, 25, 25)
RotateEntity(Brother, -90, 45, 0)
;-Buoy / Bouéée
buoy0 = CreateEntity(-1, MeshID(CreateTorus(-1, 60, 30)), MaterialID(MatBuoy), 0, 140, 700)
buoy1 = CreateEntity(-1, MeshID(CreateTorus(-1, 60, 30)), MaterialID(MatBuoy), 300, 140, 900)
RotateEntity(buoy1, 0, 90, 0)
Repeat
;-
;-[3D] Rendering
If ExamineKeyboard()
;-keyboard events : Distance and move
If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Up)
Distance - 25
ElseIf KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Down)
Distance + 25
ElseIf KeyboardPushed (#PB_Key_Up)
PlayerSpeed = 400
CurrentAnimation = "RunBase"
Angle = 180
ElseIf KeyboardPushed (#PB_Key_Down)
PlayerSpeed = -400
Angle = 0
CurrentAnimation = "RunBase"
Else
CurrentAnimation = "Dance"
PlayerSpeed = 0
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
;Escape
If KeyboardReleased(#PB_Key_Escape)
Break
EndIf
EndIf
DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
;Play animation
If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
StartEntityAnimation(Player, CurrentAnimation)
EndIf
If EntityAnimationStatus(Brother, "IdleTop") = #PB_EntityAnimation_Stopped
StartEntityAnimation(Brother, "IdleTop")
EndIf
;Update buoy, player and friend
MoveEntity(buoy0, EntityX(buoy0), WaterHeight(Camera, EntityX(buoy0), EntityZ(buoy0)), EntityZ(buoy0), #PB_Absolute)
MoveEntity(buoy1, EntityX(buoy1), WaterHeight(Camera, EntityX(buoy1), EntityZ(buoy1)), EntityZ(buoy1), #PB_Absolute)
MoveEntity(Brother, EntityX(Brother), WaterHeight(Camera, EntityX(Brother), EntityZ(Brother)) - 10, EntityZ(Brother), #PB_Absolute)
CameraFollow(Camera, EntityID(Player), Angle, EntityY(Player) + (CameraHeight), Distance, 0.25, 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