Character/Vehicle

Blitz3D Forums/Blitz3D Beginners Area/Character/Vehicle

Here is the entire code for this project.
; Game
; ---------------------
AppTitle "Game"
Graphics3D 1024,768,32,2
SetBuffer BackBuffer()

;Collision Group
Player=1

<img src="http://blitz3dstuff.googlepages.com/untitled.JPG">



Obstacle=2
Ground=3
Car=4


;The controlable Character
char=LoadAnimMesh("dwarf2.b3d")
chartex=LoadTexture("dwarf2.jpg")
PositionEntity char,-50,6,120
ScaleEntity char,.085,.085,.085
EntityType char,Player
EntityRadius char,.2

;Camera
cam1=CreateCamera()
PositionEntity cam1,EntityX(char),EntityY(char)+6,EntityZ(char)-7
EntityParent cam1,char
RotateEntity cam1,25,0,0

;Light
lite1=CreateLight(1)
RotateEntity lite1,90,0,0


;Tree2
tree2=LoadMesh("Tree1.3ds")
PositionEntity tree2, -20,5,116
ScaleEntity tree2,.05,.05,.05
EntityType tree2,Obstacle
;cage
cage=LoadMesh("thecage.3ds")
ScaleEntity cage,.040,.040,.040
PositionEntity cage,EntityX(tree2)+4,EntityY(tree2)+1.2,EntityZ(tree2)-2
Global metal=LoadTexture("metal.jpg")
EntityTexture cage,metal


;The start of a castle

strtwall1=LoadMesh("wall_1.3ds")
walltex=LoadTexture("gothic3.jpg")
EntityTexture strtwall1,walltex
PositionEntity strtwall1,-10,10,263
ScaleEntity strtwall1,.5,.5,.5
RotateEntity strtwall1,-90,0,0
EntityType strtwall1,Obstacle



;The red car
VEHICLE1=LoadMesh("f360.3ds")
Cartex=LoadTexture("fskin.jpg")
EntityTexture VEHICLE1,Cartex
PositionEntity VEHICLE1,-22,6,202
ScaleEntity VEHICLE1,2,2,2
EntityRadius VEHICLE1,.2
EntityType VEHICLE1,Car

;Weapon shop
weapshop=LoadMesh("weapshop.3ds")
weapshoptex=LoadTexture("weapshop.jpg")
EntityTexture weapshop,weapshoptex
PositionEntity weapshop,-59,12.5,178
RotateEntity weapshop,0,90,0
ScaleEntity weapshop,.5,.5,.5
EntityType weapshop,Obstacle
;weapon shop owner
wso=LoadAnimMesh("dwarf1.b3d")
wsotex=LoadTexture("dwarf.jpg")
EntityTexture wso,wsotex
PositionEntity wso,EntityX(weapshop)+1.5,6,EntityZ(weapshop)-2
ScaleEntity wso,.085,.085,.085
EntityType wso,Player
RotateEntity wso,0,-90,0
EntityRadius wso,.2

; shop
shop=LoadMesh("shop.3ds")
shoptex=LoadTexture("shop.jpg")
EntityTexture shop,shoptex
PositionEntity shop,-30,12.5,174
RotateEntity shop,0,270,0
ScaleEntity shop,.5,.5,.5
EntityType shop,Obstacle



;Creating the sky
sky = CreateSphere(60)
FlipMesh sky
ScaleEntity sky,700,700,700
PositionEntity sky, 0,70,0
sky_tex = LoadTexture ( "sky.bmp" )
EntityTexture sky,sky_tex
EntityParent sky,char



;Making water
water_tex=LoadTexture( "water1.jpg" )
ScaleTexture water_tex,6,6
water=CreatePlane()
EntityTexture water,water_tex
PositionEntity water,0,2,0
EntityAlpha water,.5
ScaleEntity water,5,100,5



;loading the terrain
terrain=LoadTerrain ( "HMAP.jpg" )
ScaleEntity terrain,5,100,5
PositionEntity terrain,-758,-21.7,-500
tex=LoadTexture( "GRASS1.jpg" )
EntityTexture terrain,tex 
EntityType terrain,Ground




;Animation extracting
;run
ExtractAnimSeq(char,16,26)

;idle
ExtractAnimSeq (char,292,325)


idle=ExtractAnimSeq (wso,292,325)

;attack
at1=ExtractAnimSeq (char,62,180)


;-----------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------
While Not KeyDown( 1 )

If Not Animating( wso )
		Animate wso,1,.2,idle,1
	EndIf


If EntityDistance (char,VEHICLE1)<1 And KeyHit(32) Then 
EntityParent char,VEHICLE1
HideEntity char
End If 





;Jump
If KeyHit( 57 )=True Then TranslateEntity char,0,9,0

;speed boost
If KeyDown( 16 )=True Then MoveEntity char,0,0,9

; Turn Left and Right
If KeyDown( 203 )=True Then TurnEntity char,0,2,0
If KeyDown( 205 )=True Then TurnEntity char,0,-2,0

;move character forward and animate
If KeyDown(200)
  MoveEntity char,0,0,.3
  If AnimSeq( char )<>1 Animate char,1,.2,1,1  
  Else
  If AnimSeq( char )<>2 Animate char,1,.2,2,1
End If


;move character backward
If KeyDown(208)=True Then MoveEntity char,0,0,-.08

;strafe left x
If KeyDown( 44 )=True Then MoveEntity char,-.5,0,0
;strafe
If KeyDown( 45 )=True Then MoveEntity char,.5,0,0

;Gravity
TranslateEntity char, 0,-0.5,0
TranslateEntity wso, 0,-0.5,0
TranslateEntity VEHICLE1, 0,-0.5,0



;COLLISIONS
Collisions Player,Obstacle,2,2
Collisions Obstacle,Player,2,2
Collisions Ground,Player,2,3
Collisions Player,Ground,2,3
Collisions Player,Car,2,3
Collisions Car,Player,2,3
Collisions Car,Ground,2,3
Collisions Ground,Car,2,3




UpdateWorld




RenderWorld
Text 30,30,"Your location: x= "+EntityX(char)+" y= "+EntityY(char)+" z= "+EntityZ(char) 
Text 30,50,"Hit escape to exit"


Flip
Wend
End   


FreeEntity char
FreeEntity wso 


Edit: I changed the <1 to <5, and when I went inside the car, (screwed up collision, will fix) and pressed 'd' like 5 times it screwed up the text in the top left hand of the screem? Why?