I had some free time and wrote this prototype for a thirdperson 3D-game
(If you want to test it, you have to insert some pictures and meshes - Controls are WASD and Arrow-Keys).
But I have still a problem and hope you can help me:
I usually use a 129x129 picture for the terrain and a 1024x1024 jpg as texture.
If I walk and turn the camera in different directions, the character walks at different speed. I think it is why the framerate is very ?small if you look to the opposite edge of the terrain, but I don´t know what to do.
I tried the Fog()-function but it seems it doesn´t work correct - I saw no fog. So I do not know how to ?increase the framerate.
Hope someone can fix the problem and tell me. It would be also nice to make the code better, I´m still not as good as I want in pb.
(When I wrote the code I noticed some strange individualities of pb:
1. If you use MoveCamera(?,KeyX,?,?), the camera moves always forward, the looking-direction does not care, but if you use MoveEntity(?,KeyX,?,?) the Entity is moved along the X-axis of the world.
2. There is no function to get the rotation-angle of an entity. If you rotated an entity an have not save somewhere how much, you have no chance to turn it looking along the x-axis for example. It is also very difficult to turn an entity once (in the gameloop) and let it look in this direction the following frames.
3. If have still no idea how to create a mesh or a world to load in pb. Hope someone can help me with this.)
Sorry for my bad english , here is the code:
Code: Select all
move_x.w = 0
move_y.w = 0
old_angle.l = 0
angle.l = 0
character_speed.w = 10
c_angle = 0
c_distance = 500
way.s = ""
If InitEngine3D()
Add3DArchive("Data\", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
InitMouse()
OpenScreen(1024,768,32,"")
CreateMaterial(0, LoadTexture(0, ""))
CreateTerrain("", MaterialID(0), 400, 30, 400, 0)
SkyBox("")
LoadMesh(0,"")
CreateMaterial(1,LoadTexture(1,""))
CreateEntity(0, MeshID(0), MaterialID(1), 0, 0, 0)
AnimateEntity(0,"")
CreateCamera(0,0,0,100,100)
Repeat
ExamineKeyboard()
way = ""
If KeyboardPushed(#pb_key_w)
way + "w"
EndIf
If KeyboardPushed(#pb_key_s)
way + "s"
EndIf
If KeyboardPushed(#pb_key_a)
way + "a"
EndIf
If KeyboardPushed(#pb_key_d)
way + "d"
EndIf
ReplaceString(way,"ws","")
ReplaceString(way,"ad","")
If KeyboardPushed(#pb_key_left) And KeyboardPushed(#pb_key_right)
ElseIf KeyboardPushed(#pb_key_left)
c_angle + 2
angle + 2
If c_angle > 360
c_angle - 360
EndIf
ElseIf KeyboardPushed(#pb_key_right)
c_angle - 2
angle - 2
If c_angle < 0
c_angle + 360
EndIf
EndIf
If KeyboardPushed(#pb_key_up) And KeyboardPushed(#pb_key_down)
ElseIf KeyboardPushed(#pb_key_up)
c_distance - 10
ElseIf KeyboardPushed(#pb_key_down)
c_distance + 10
EndIf
If c_distance < 300
c_distance = 300
EndIf
If c_distance > 1000
c_distance = 1000
EndIf
old_angle = angle
If way = "w"
angle = 0
ElseIf way = "wa"
angle = 45
ElseIf way = "a"
angle = 90
ElseIf way = "sa"
angle = 135
ElseIf way = "s"
angle = 180
ElseIf way = "sd"
angle = 225
ElseIf way = "d"
angle = 270
ElseIf way = "wd"
angle = 315
EndIf
RotateEntity(0,angle-old_angle,0,0)
If way <> ""
MoveEntity(0,character_speed*Cos(ASin(1)/90*(angle-c_angle)),0,character_speed*Sin(ASin(1)/90*(c_angle-angle)))
EntityLocate(0,EntityX(0),TerrainHeight(EntityX(0),EntityZ(0)),EntityZ(0))
EndIf
CameraLocate(0,EntityX(0)-c_distance*Cos(c_angle*ASin(1)/90),EntityY(0)+100+0.0003*Pow(c_distance,2),EntityZ(0)-c_distance*Sin(c_angle*ASin(1)/90))
CameraLookAt(0,EntityX(0),EntityY(0)+50*500/c_distance,EntityZ(0))
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End