;Name of application AppTitle "My First Terrain And First animated Character" Print "Press F12 to exit" Print "After the wheels start moving" Print "Press Spacebar to move the car." Delay 2000 ;Initialise Graphics mode Graphics3D 800,600,16,1 SetBuffer BackBuffer() Const FPS=500 Const GRAVITY#=-0.01 ;Camera has to be set, so the scene is visible Camera=CreateCamera() ;CameraFogMode camera,1 ;CameraFogColor camera,1,150,150 PositionEntity camera,30,0,1,True ;Light The Scene, so that it doesn't look flat Light=CreateLight() RotateEntity Light,90,0,0 ;Create the "Terrain" Entity... terrain=LoadMesh("Land2.b3d") PositionEntity terrain,40,17,0 RotateEntity terrain,0,0,0 TranslateEntity terrain,30,-20,-.1 ;...and texture it Grass=LoadTexture("terrain-1.jpg") EntityTexture terrain,Grass ;Create a skybox using createsphere command sky=CreateSphere(16) ScaleMesh sky,800,800,800 sky_tex=LoadTexture("sky.bmp") EntityTexture sky,sky_tex EntityFX sky,1 FlipMesh sky FOG_RANGE=70 ;Create the "Box" entity and animate it box=LoadAnimMesh("model\BOX.B3D") ScaleEntity box,.1,.1,.1 PositionEntity box,0,-.9000,5 TranslateEntity box,30,-.70,-.70 EntityShininess box,1 SetAnimKey box,15,True,True,True AddAnimSeq(box,15) Animate box,1,2,0,100 ;Set Collision types fot the "collisions" command 1-player, 2-ground type_box=1 type_terrain=2 EntityType box,1 EntityType terrain,2 ;Adjust Radius of Sphere, that's used for Sphere-Polygon collisions box_radius#=1 EntityRadius box, box_radius ;Initialise Collisions between player and ground Collisions type_box,type_terrain,2,3 Collisions type_terrain,type_box,2,3 ;Dither scene, so that it does look good with 16 Bit Color-Depth ; Toggle dither enable value between true and false when F10 is pressed ;If KeyHit( 68 )=True Then enable=1-enable ;Dither enable ;other information about gravity speed#=0 x_vel#=0:prev_x#=EntityX( box ) y_vel#=0:prev_y#=EntityY( box ) z_vel#=0:prev_z#=EntityZ( box ) ;Main Loop While Not KeyHit(88) ;press F12 To Exit ;Press F11 to see the world in Wireframe mode If KeyHit(87)=True Then enable=1-enable WireFrame enable CameraFogRange camera,1,FOG_RANGE ;calculate box velocities cx#=EntityX( box ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( box ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( box ):z_vel=cz-prev_z:prev_z=cz EntityParent(camera,box,1) ;Keyboard Input (cursor-keys) For moving the player around If KeyHit(57) If move_entities = True move_entities = False Else move_entities = True EndIf EndIf If move_entities = False ;all of your movement code If KeyDown(30) TurnEntity box,0,1,0 If KeyDown(32) TurnEntity box,0,-1,0 If KeyDown(31) MoveEntity box,0,0,-.01 If KeyDown(17) MoveEntity box,0,0,.01 If EntityCollided( box,terrain ) If KeyDown(17) speed=speed+.00 If speed>.0 speed=.0 Else If KeyDown(31) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity box,0,0,speed TranslateEntity box,0,GRAVITY#-.01,0 Else TranslateEntity box,x_vel,y_vel+GRAVITY,z_vel EndIf EndIf TurnEntity sky,0,.02,0 ;Update the animation-Frames and Render the calculated scene, Flip Back- with Frontbuffer after that, so the new frame becomes visible UpdateWorld RenderWorld Flip Wend ;Free the Memory and end the program ClearWorld End
About my First project
Blitz3D Forums/Blitz3D Programming/About my First projectThe forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.