Tank Simulator

Blitz3D Forums/Blitz3D Programming/Tank Simulator

sonokong(Posted 2007) [#1]
Okay, I'm making a tank simulator. Problem is, I don't know how to get the camera working to see the tank from the back and NOT the front, as you'll see in the code that I whipped up below. Also, how can I make some realistic gravity? Oh, and please don't say anything about the terrain-I know it's a problem.
;The Forbidden
;By Minkee
Global gfxPlayer
Global gfxAlert
;Set the graphics mode
Graphics3D 640,480
SetBuffer BackBuffer()
;Load An Image
gfxPlayer=LoadImage ("invader.bmp")
;Load Another image
gfxAlert=LoadImage ("alert.bmp")
;Set global on font variables
Global fntArial
;Load fonts to a file handle variables
fntArial=LoadFont ("OCR A Extended",36,False,False,False)
;Set the font and print text
SetFont fntArial
;Okay...
Print "The Forbidden"
fntComic=LoadFont ("Arial",15,False,False,False)
;Set font
SetFont fntComic
;Subtitles
Print "The Forbidden: As the last defender of Britain, you must fight the opposing forces and win the war!"
Print "Press the arrow keys To move forward, backwards, Left, And Right and press the spacebar to fire."
Print "Questions? Comments? Constructive criticism? Feel free to contact me at minkee.s@..."
Print "Code  written by Minkee S"
Print "A GLITCH CITY GAMES CO. PRODUCTION"
;This draws the images
DrawImage gfxPlayer, 500,0,0
DrawImage gfxAlert, 300,300,0
WaitKey 
;Assign the types
type_player=1
type_ground=2
;Create the terrain
terrain=LoadTerrain("texture.bmp")


tadpole=LoadMesh( "btadpole.3ds" )
tex=LoadTexture( "spheremap.bmp",64+1 )
EntityType tadpole, type_player
PositionEntity tadpole, 0,1,5
EntityTexture tadpole,tex
EntityFX tadpole,10
ScaleEntity tadpole, 0.1,0.1,0.1


camera=CreateCamera()
PositionEntity camera,0,0,50

While Not KeyHit(1)
If KeyDown (208) TranslateEntity tadpole, 0,0,-0.3
If KeyDown (200) TranslateEntity tadpole, 0,0,0.3
If KeyDown (205) TranslateEntity tadpole, 0.3,0,0
If KeyDown (203) TranslateEntity tadpole, -0.3,0,0

Collisions type_player,type_ground,2,2
Collisions type_ground,type_player,2,2
	UpdateWorld
	RenderWorld
	Flip
Wend
End



sonokong(Posted 2007) [#2]
Oh and yes, the tadpole is one of the geometrix models included with Blitz3D.


Stevie G(Posted 2007) [#3]
Just position the camera at 0,0,-50 rather than 0,0,50 and you'll see the back.

Take you're collision commands out of the main loop too, you only need to call them once after you assign the types.

Stevie


sonokong(Posted 2007) [#4]
By "back," I meant that I could see the back of the tank, kind of like the games Uru, Gundam Crossfire, and the such where you see the back of the machine. So here's the updated code:
;The Binary Labyrinth
;By Minkee
Global gfxPlayer
Global gfxAlert
;Set the graphics mode
Graphics3D 640,480
SetBuffer BackBuffer()
;Load An Image
gfxPlayer=LoadImage ("invader.bmp")
;Load Another image
gfxAlert=LoadImage ("alert.bmp")
;Set global on font variables
Global fntArial
;Load fonts to a file handle variables
fntArial=LoadFont ("OCR A Extended",36,False,False,False)
;Set the font and print text
SetFont fntArial
;Okay...
Print "The Forbidden"
fntComic=LoadFont ("Arial",15,False,False,False)
;Set font
SetFont fntComic
;Subtitles
Print "The Forbidden: As the last defender of Britain, you must fight the opposing forces and win the war!"
Print "Press the arrow keys To move forward, backwards, Left, And Right and press the spacebar to fire."
Print "Questions? Comments? Constructive criticism? Feel free to contact me at minkee.s@..."
Print "Code  written by Minkee S"
Print "A GLITCH CITY GAMES CO. PRODUCTION"
;This draws the images
DrawImage gfxPlayer, 500,0,0
DrawImage gfxAlert, 300,300,0
WaitKey 
;Create a camera
camera=CreateCamera()
PositionEntity camera,0,0,-50 
;Create a light
light=CreateLight()
;Assign the types
type_player=1
type_ground=2
;Global some sound
Global Music
Music=LoadSound("Dreamland.mp3")
PlaySound Music
;Create some terrain
tex=LoadTexture ("texture.jpg")
ScaleTexture tex,.5,.5
ground=LoadTerrain("spikey.jpg")
ScaleEntity ground,5,100,5
EntityTexture ground, tex
EntityType ground, type_ground
;Load the tank
tadpole=LoadMesh( "btadpole.3ds" )
tex2=LoadTexture( "spheremap.bmp",64+1 )
PositionEntity tadpole, 0,1,5
EntityTexture tadpole,tex2
EntityFX tadpole,10
ScaleEntity tadpole, 0.1,0.1,0.1
PositionEntity tadpole,-20,50,40
EntityType tadpole, type_player
Collisions type_player,type_ground,2,2
Collisions type_ground,type_player,2,2
;Make the program run
While Not KeyHit(1)
;Movement
If KeyDown (208) TranslateEntity tadpole, 0,0,-0.3
If KeyDown (200) TranslateEntity tadpole, 0,0,0.3
If KeyDown (205) TranslateEntity tadpole, 0.3,0,0
If KeyDown (203) TranslateEntity tadpole, -0.3,0,0


	UpdateWorld
	RenderWorld
	Flip
Wend
End



IPete2(Posted 2007) [#5]
Sonokong,

check out the code archives, theres a few funcitons in there which would qualify for this. check out SUPERCAM for example.

IPete2.


sonokong(Posted 2007) [#6]
Hmmm... supercam is good, but I'm not so sure it's right in this case. Is there a way to shoot pre-made missiles out of the "gun barrel" of the tank? I've got the model and everything, all I need is the code for shooting out of the "gun barrel". I'm not so sure it's all possible.


b32(Posted 2007) [#7]
If the missiles are a child of the tank model (EntityParent missile, tank), in every position, the starting/launching position of the missiles are the same.
So, in a separate program, figure out what these coordinates should be (say, with the mouse) and apply them on every launch.


sonokong(Posted 2007) [#8]
Okay


sonokong(Posted 2007) [#9]
Oh yeah, the tank keeps on going through the ground at times because of a glitch.


b32(Posted 2007) [#10]
Maybe use TerrainY() to place the vehicle on the ground? Or use a LinePick from the tank to the ground and place it on PickedX(), PickedY(), PickedZ()
Else, just tweak the code to avoid this glitch.