FIRST GAME NEED HELP WITH GUN/SHOOTING

Blitz3D Forums/Blitz3D Beginners Area/FIRST GAME NEED HELP WITH GUN/SHOOTING

CHALLENGER426(Posted 2008) [#1]
I am making my first game and i'm 17... i can make a gun and bullets but it it doesn't work, i would like a gun that has a sight that can move and shoot with the mouse. i also am wondering if i can set the enemies to shoot at on a loop so they don't leave a certtain area? Heres the code, its not near finished...any advice or code that will help me? THANKS

;Welcome
welcome()
Function welcome()
Graphics 1020,740
screen=LoadImage("title.jpg")
DrawImage screen,0,0
While Not KeyDown(1)
If KeyDown(28) Then Return
Wend
End Function
Graphics3D 640,480
HidePointer

Graphics3D 640,480
SetBuffer BackBuffer()

Global info1$="Driver"

Const GRAVITY#=-.01

Const BODY=1,WHEEL=2,SCENE=3,Water=4,CAM=5,BULLET=6,GUN=7
Graphics3D 1024,768
SetBuffer BackBuffer()



;Creating a plane and texture

terr=CreateTexture(32,32,8)
ScaleTexture terr,10,10
SetBuffer TextureBuffer(terr)
Color 0,0,0:Rect 0,0,32,32
Color 0,0,0:Rect 0,0,32,32,False
SetBuffer BackBuffer()




;create cloud planes
tex=LoadTexture( "cloud_2.bmp",3 )
ScaleTexture tex,1000,1000
p=CreatePlane()
EntityTexture p,tex
EntityFX p,1
PositionEntity p,0,70,0
p=CopyEntity( p )
RotateEntity p,0,0,180



;Load terrain
terr=LoadTerrain( "ground.jpg" )
ScaleEntity terr,20,800,20
PositionEntity terr,-20*512,0,-20*512
EntityFX terr,1
EntityType terr,10

;apply textures to terrain
tex1=LoadTexture( "grass.jpg",1 )
ScaleTexture tex1,10,10
tex2=LoadTexture( "muddy.jpg" )
ScaleTexture tex2,TerrainSize(terr),TerrainSize(terr)
EntityTexture terr,tex1,0,0
EntityTexture terr,tex2,0,1

;and ground plane
plane=CreatePlane()
ScaleEntity plane,20,1,20
PositionEntity plane,-20*512,0,-20*512
EntityTexture plane,tex1,0,0
EntityOrder plane,3
EntityFX plane,1
EntityType plane, SCENE


;create water plane
tex=LoadTexture( "water-2_mip.bmp",3 )
ScaleTexture tex,10,10
p=CreatePlane()
EntityTexture p,tex
EntityBlend p,1
EntityAlpha p,.75
PositionEntity p,0,10,0
EntityFX p,1
EntityType p, WATER




terrain=LoadTerrain("ground.jpg")
ScaleEntity terrain,5,100,5
PositionEntity terrain,-500,0,-500

Texture=LoadTexture("grassy.jpg")
EntityTexture terrain,texture

EntityType terrain,SCENE

;plane

plane=LoadMesh("747.x")
ScaleMesh plane,1,1,-1
FlipMesh plane
FitMesh plane,100,100,-50,100,50,100
PositionEntity plane,150,-110,-100
EntityShininess plane,-10
EntityType plane,SCENE
RotateEntity plane, -5,8,0

;debris
a=LoadMesh("wcrate1.3ds")
ScaleMesh a,1,1,-1
FlipMesh a
FitMesh a,5,5,-5,5,5,5
PositionEntity a,300,-2,-30
EntityShininess a,-10
EntityType a,SCENE
RotateEntity a, -5,8,0

a2=LoadMesh("wcrate1.3ds")
ScaleMesh a2,1,1,-1
FlipMesh a2
FitMesh a2,5,5,-5,5,5,5
PositionEntity a2,280,-5,-30
EntityShininess a2,-10
EntityType a2,SCENE
RotateEntity a2, -5,8,0

a3=LoadMesh("wcrate1.3ds")
ScaleMesh a3,1,1,-1
FlipMesh a3
FitMesh a3,5,5,-5,5,5,5
PositionEntity a3,270,0,-20
EntityShininess a3,-10
EntityType a3,SCENE
RotateEntity a3, -5,8,0

a4=LoadMesh("wcrate1.3ds")
ScaleMesh a4,1,1,-1
FlipMesh a4
FitMesh a4,5,5,-5,5,5,5
PositionEntity a4,250,-6,-10
EntityShininess a4,-10
EntityType a4,SCENE
RotateEntity a4, -5,8,0



;tank
car=LoadMesh("warrior.3ds")
ScaleMesh car,1,1,-1
FlipMesh car
FitMesh car,-1.5,-1,-3,3,2,6
PositionEntity car, 0,70,0
EntityShininess car,.1
EntityType car,BODY

Global wheels[4]

cnt=1
For z#=1.5 To -1.5 Step -3
For x#=-1 To 1 Step 2
wheels[cnt]=CreateSphere( 8,car )
EntityColor wheels[cnt],0,0,0
EntityAlpha wheels[cnt],.5
ScaleEntity wheels[cnt],.5,.5,.5
EntityRadius wheels[cnt],.5
PositionEntity wheels[cnt],x,0,z
EntityType wheels[cnt],WHEEL
cnt=cnt+1
Next
Next

;GUN/SHOOTING





;light
light=CreateLight()
TurnEntity light,45,45,0



target=CreatePivot( car )
PositionEntity target,0,5,-12

camera=CreateCamera()
CameraClsColor camera,0,128,255
EntityType camera, CAM
CameraFogColor camera,100,192,255
CameraFogRange camera,1000,3000

speed#=0
x_vel#=0:prev_x#=EntityX( car )
y_vel#=0:prev_y#=EntityY( car )
z_vel#=0:prev_z#=EntityZ( car )





;ENEMIES
Dim ducks(5)
For x=1 To 1
ducks(x)=LoadMesh("fighter.3ds")
PositionEntity ducks(x),x*15,60,90
EntityColor ducks(x),255,255,0
ScaleEntity ducks(x),0.1,0.1,0.1
EntityType ducks(x), type_gallery
EntityRadius ducks(x),3
Next
Dim seahorse(5)
For x=1 To 1
seahorse(x)=LoadMesh("stealth.3ds")
PositionEntity seahorse(x),x*6,40,45
EntityColor seahorse(x),255,102,0
ScaleEntity seahorse(x),0.03,0.03,0.03
EntityType seahorse(x),type_gallery
EntityRadius seahorse(x),3
Next
Dim Donkey(5)
For x=1 To 1
donkey(x)=LoadMesh("solarsail.3ds")
PositionEntity donkey(x),x*5,50,80
EntityColor donkey(x),204,204,204
ScaleEntity donkey(x),.003,.003,.003
EntityType donkey(x),type_gallery
EntityRadius donkey(x),3
Next
Dim Flamingo(5)
For x=1 To 1
flamingo(x)=LoadMesh("fsaucer1.3ds")
PositionEntity flamingo(x),x*6,45,0
EntityColor flamingo(x),0,0,0
ScaleEntity flamingo(x),0.003,0.003,0.003
EntityType flamingo(x),type_gallery
EntityRadius flamingo(x),3
Next
Dim Dolphin(5)
For x=1 To 1
dolphin(x)=LoadMesh("mak_robotic.3ds")
PositionEntity dolphin(x),x*6,45,0
EntityColor dolphin(x),102,153,255
ScaleEntity dolphin(x),0.3,0.3,0.3
EntityType dolphin(x),type_gallery
EntityRadius dolphin(x),3
Next
Dim snake(5)
For x=1 To 1
snake(x)=LoadMesh("fsaucer1.3ds")
PositionEntity snake(x),x*16,60,10
EntityColor snake(x),153,255,102
ScaleEntity snake(x),0.06,0.06,0.06
EntityType snake(x),type_gallery
EntityRadius snake(x),5
Next





;collisions

Collisions BODY,SCENE,2,3
Collisions WHEEL,SCENE,2,3
Collisions BODY, WATER,2,5
Collisions CAM,SCENE,3,2
Collisions WHEEL,WATER,2,5


While Not KeyHit(1)

;align car to wheels
zx#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2
zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2
zy#=(EntityY( wheels[2],True )+EntityY( wheels[4],True ))/2
zy=zy-(EntityY( wheels[1],True )+EntityY( wheels[3],True ))/2
zz#=(EntityZ( wheels[2],True )+EntityZ( wheels[4],True ))/2
zz=zz-(EntityZ( wheels[1],True )+EntityZ( wheels[3],True ))/2
AlignToVector car,zx,zy,zz,1

zx#=(EntityX( wheels[1],True )+EntityX( wheels[2],True ))/2
zx=zx-(EntityX( wheels[3],True )+EntityX( wheels[4],True ))/2
zy#=(EntityY( wheels[1],True )+EntityY( wheels[2],True ))/2
zy=zy-(EntityY( wheels[3],True )+EntityY( wheels[4],True ))/2
zz#=(EntityZ( wheels[1],True )+EntityZ( wheels[2],True ))/2
zz=zz-(EntityZ( wheels[3],True )+EntityZ( wheels[4],True ))/2
AlignToVector car,zx,zy,zz,3

;calculate car velocities
cx#=EntityX( car ):x_vel=cx-prev_x:prev_x=cx
cy#=EntityY( car ):y_vel=cy-prev_y:prev_y=cy
cz#=EntityZ( car ):z_vel=cz-prev_z:prev_z=cz


cnt=1
For z=1.5 To -1.5 Step -3
For x=-1 To 1 Step 2
; PositionEntity wheels[cnt],0,0,0
; ResetEntity wheels[cnt]
PositionEntity wheels[cnt],x,-1,z
cnt=cnt+1
Next
Next
;Moving the Targets
For a=1 To 1
MoveEntity ducks(a),0.1,0,0
MoveEntity seahorse(a),.2,0,0
MoveEntity donkey(a),0,0,.1
MoveEntity flamingo(a),0.1,0,.2
MoveEntity snake(a),-0.2,0,0
MoveEntity dolphin(a),.1,0,0
Next

;move car

If KeyDown(203) TurnEntity car,0,3,0
If KeyDown(205) TurnEntity car,0,-3,0
If EntityCollided( car,SCENE )
If KeyDown(200)
speed=speed+.02
If speed>.5 speed=.5
Else If KeyDown(208)
speed=speed-.02
If speed<-.5 speed=-.5
Else
speed=speed*.9
EndIf
MoveEntity car,0,0,speed
TranslateEntity car,0,GRAVITY,0
Else
TranslateEntity car,x_vel,y_vel+GRAVITY,z_vel
EndIf
If KeyDown (32) Collisions BODY,SCENE,2,3
If KeyDown (32) Collisions WHEEL,SCENE,2,3

Cls



;get mouse
mxspd#=MouseXSpeed()
myspd#=MouseYSpeed()
MoveMouse 400,300

;turn camera
;note, we change only camera pitch as it's attached to the pivot of the player which
;only changes it's yaw. This for various reasons makes it easy to control.

pitch#=pitch#+myspd*0.1
yaw#=yaw#-mxspd*0.1
RotateEntity camera,pitch,0,0
RotateEntity camera,0,yaw,0


;Help Create Game
If KeyDown(31) HideEntity car
If KeyDown(32) ShowEntity car
; Toggle wireframe enable value between true and false when spacebar is pressed
If KeyHit( 17 )=True Then enable=1-enable
; Enable/disable wireframe rendering
WireFrame enable

;update camera
If speed>=0
dx#=EntityX( target,True )-EntityX( camera )
dy#=EntityY( target,True )-EntityY( camera )
dz#=EntityZ( target,True )-EntityZ( camera )
TranslateEntity camera,dx*.1,dy*.1,dz*.1
EndIf
PointEntity camera,car


;Pausing the game
If KeyDown(25) Then
Cls
pause=LoadImage("image1.jpg")
DrawImage pause,0,0
Flip
WaitMouse
EndIf

UpdateWorld
RenderWorld
Flip
Wend
End


mtnhome3d(Posted 2008) [#2]
http://www.savefile.com/files/1560567
there is a .zip file there that contains a whole fps setup and code use what you want. it uses types though. just scrool down on the screen.


mtnhome3d(Posted 2008) [#3]
did you see this?


Pirate(Posted 2008) [#4]
if challenger did not see it, i sure did...thanks a lot..i am working on a game in caverns and this has helped a lot....pirate


mtnhome3d(Posted 2008) [#5]
your very welcome, i just hoped it helped somebody.


Ross C(Posted 2008) [#6]
Please don't use caps for a topic title :o)


mtnhome3d(Posted 2008) [#7]
hey pirate if you need help understanding the code just ask, it very very messy.


Pirate(Posted 2008) [#8]
hey mtnhome3d,
i am just now getting into studying the code and it might be a little messy but most of mine ends up that way anyway...i appreciate the offer for help...i will take you up on that when and as i need it....pirate


LedgerARC(Posted 2008) [#9]
for the original message, I see that you using the same book I did to learn how to program games. here is some simple code that I use to make bullets in all my games.

;Bullets for player 1
fullcart=100
Dim bullet(fullcart)
For i=0 To fullcart
bullet(i)=CreateSphere()
ScaleEntity bullet(i),0.10,0.10,0.10
EntityColor bullet(i),255,0,0
HideEntity bullet(i)
EntityType bullet(i),type_bullets1
EntityRadius bullet(i),0.2
Next

;player 1's bullets
If KeyHit(29) And t<100 Then
PositionEntity bullet(t) ,EntityX(gun1,1),EntityY(gun1,1),EntityZ(gun1,1)
ShowEntity bullet(t)
RotateEntity bullet(t) ,EntityPitch#(gun1,1),EntityYaw#(gun1,1),EntityRoll#(gun1,1)
t=t+1
EndIf

For e=0 To fullcart
MoveEntity bullet(e),0,1,0
Next

if using functions, you have to make sure that "t" is a global or it wont work.

hoped this helped.


CHALLENGER426(Posted 2008) [#10]
thanks a lot, this really helped