My first game is almost done...but i cannot figure out how to get the enemies to "die" when they are hit by the bullets. i know it has something to do with countcollisions or entitycollided, but i'm not sure how to get it to work. heres the code...
also can anyone show me how to use the mouse to move the sight to shoot the enemies...THANKS AGAIN
;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() Const GRAVITY#=-.01 Const BODY=1,WHEEL=2,SCENE=3,Water=4,CAM=5,SKIES=6,NO=7,ENEMY=8,BULL=9 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 tex2=LoadTexture( "cloud_2.bmp",3 ) ScaleTexture tex2,1000,1000 p2=CreatePlane() EntityTexture p2,tex2 EntityFX p2,1 PositionEntity p2,0,125,0 p2=CopyEntity( p2 ) RotateEntity p2,0,0,180 m=CreateMesh() ;front face b=LoadBrush( file$+"sky_FR.bmp",49) s=CreateSurface( m,b ) AddVertex s,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0 AddVertex s,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;right face b=LoadBrush( file$+"sky_LF.bmp",49) s=CreateSurface( m,b ) AddVertex s,+1,+1,-1,0,0:AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1:AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;back face b=LoadBrush( file$+"sky_BK.bmp",49) s=CreateSurface( m,b ) AddVertex s,+1,+1,+1,0,0:AddVertex s,-1,+1,+1,1,0 AddVertex s,-1,-1,+1,1,1:AddVertex s,+1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;left face b=LoadBrush( file$+"sky_RT.bmp",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,0:AddVertex s,-1,+1,-1,1,0 AddVertex s,-1,-1,-1,1,1:AddVertex s,-1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ;top face b=LoadBrush( file$+"sky_UP.bmp",49 ) s=CreateSurface( m,b ) AddVertex s,-1,+1,+1,0,1:AddVertex s,+1,+1,+1,0,0 AddVertex s,+1,+1,-1,1,0:AddVertex s,-1,+1,-1,1,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush b ScaleMesh m,700,200,600 FlipMesh m EntityFX m,9 EntityType m,SKIES ;boundaries bound=CreateCube() PositionEntity bound,0,70,0 ScaleEntity bound,695,195,595 EntityType bound,NO ;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 ;SIGHTS Global target2=LoadSprite("target.bmp",1,camera) MoveEntity target2,0,10,0 EntityOrder target2,-2 PositionEntity target2, 0, EntityY (car) + 0.85, +30 EntityParent target2, car ;MACHINEGUN fullcart=100 Dim bullet(fullcart) For i=0 To fullcart bullet(i)=CreateSphere() ScaleEntity bullet(i),0.1,0.1,-0.1 EntityColor bullet(i),0,0,0 HideEntity bullet(i) EntityType bullet(i),BULL EntityRadius bullet(i),0 Next ; CANNON spark=LoadSprite("bigspark.bmp") ScaleSprite spark,2,2 EntityOrder spark,-2 HideEntity spark EntityParent spark,target2 EntityType spark, BULL ; Load sounds gunshot=LoadSound("shotgun.wav") gunz=LoadSound("gunshot.wav") ;light light=CreateLight() TurnEntity light,45,45,0 target=CreatePivot( car ) PositionEntity target,0,5,-12 camera=CreateCamera() CameraClsColor camera,0,128,255 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 pivot2=CreatePivot() PositionEntity pivot2,2,3,90 Dim ducks(5) For x=1 To 1 ducks(x)=LoadMesh("solarsail.3ds",pivot2) PositionEntity ducks(x),x*15,60,90 EntityColor ducks(x),255,255,0 ScaleEntity ducks(x),0.003,0.003,0.003 EntityType ducks(x), ENEMY EntityRadius ducks(x),3 Next pivot3=CreatePivot() PositionEntity pivot3,2,3,1 Dim seahorse(5) For x=1 To 1 seahorse(x)=LoadMesh("solarsail.3ds",pivot3) PositionEntity seahorse(x),x*100,40,45 EntityColor seahorse(x),255,102,0 ScaleEntity seahorse(x),0.003,0.003,0.003 EntityType seahorse(x),ENEMY EntityRadius seahorse(x),3 Next pivot4=CreatePivot() PositionEntity pivot4,2,3,3 Dim Donkey(5) For x=1 To 1 donkey(x)=LoadMesh("solarsail.3ds",pivot4) PositionEntity donkey(x),x*5,50,500 EntityColor donkey(x),204,204,204 ScaleEntity donkey(x),.001,.001,.001 EntityType donkey(x),ENEMY EntityRadius donkey(x),3 Next pivot5=CreatePivot() PositionEntity pivot5,2,3,4 Dim Flamingo(5) For x=1 To 1 flamingo(x)=LoadMesh("solarsail.3ds",pivot5) PositionEntity flamingo(x),x*60,45,300 EntityColor flamingo(x),255,0,255 ScaleEntity flamingo(x),0.003,0.003,0.003 EntityType flamingo(x),ENEMY EntityRadius flamingo(x),3 Next pivot6=CreatePivot() PositionEntity pivot6,2,5,1 Dim Dolphin(5) For x=1 To 1 dolphin(x)=LoadMesh("solarsail.3ds",pivot6) PositionEntity dolphin(x),x*200,30,100 EntityColor dolphin(x),102,153,255 ScaleEntity dolphin(x),0.003,0.003,0.003 EntityType dolphin(x),ENEMY EntityRadius dolphin(x),3 Next pivot7=CreatePivot() PositionEntity pivot7,10,3,30 Dim snake(5) For x=1 To 1 snake(x)=LoadMesh("solarsail.3ds",pivot7) PositionEntity snake(x),x*60,60,200 RotateEntity snake(x),90,0,0 EntityColor snake(x),153,255,102 ScaleEntity snake(x),0.003,0.003,0.003 EntityType snake(x),ENEMY EntityRadius snake(x),5 Next pivot8=CreatePivot() PositionEntity pivot8,2,3,1 Dim n(5) For x=1 To 1 n(x)=LoadMesh("solarsail.3ds",pivot8) PositionEntity n(x),x*100,60,100 RotateEntity n(x),90,0,0 EntityColor n(x),236,236,236 ScaleEntity n(x),0.003,0.003,0.003 EntityType n(x),ENEMY EntityRadius n(x),5 Next pivot9=CreatePivot() PositionEntity pivot9,6,3,1 Dim n2(5) For x=1 To 1 n2(x)=LoadMesh("solarsail.3ds",pivot9) PositionEntity n2(x),x*100,60,100 RotateEntity n2(x),90,0,0 EntityColor n2(x),153,255,102 ScaleEntity n2(x),0.003,0.003,0.003 EntityType n2(x),ENEMY EntityRadius n2(x),5 Next pivot10=CreatePivot() PositionEntity pivot10,6,3,1 Dim n3(5) For x=1 To 1 n3(x)=LoadMesh("solarsail.3ds",pivot10) PositionEntity n3(x),x*150,60,200 RotateEntity n3(x),90,0,0 EntityColor n3(x),153,255,102 ScaleEntity n3(x),0.003,0.003,0.003 EntityType n3(x),ENEMY EntityRadius n3(x),5 Next pivot11=CreatePivot() PositionEntity pivot11,6,3,1 Dim n4(5) For x=1 To 1 n4(x)=LoadMesh("solarsail.3ds",pivot11) PositionEntity n4(x),x*100,60,150 RotateEntity n4(x),90,0,0 EntityColor n4(x),153,255,102 ScaleEntity n4(x),0.003,0.003,0.003 EntityType n4(x),ENEMY EntityRadius n4(x),5 Next ;MOTHERSHIP pivot=CreatePivot() PositionEntity pivot,2,3,1 Dim snake2(5) For x=1 To 1 snake2(x)=LoadMesh("fsaucer1.3ds",pivot) PositionEntity snake2(x),x*700,125,10 EntityColor snake2(x),153,255,102 ScaleEntity snake2(x),15,15,15 EntityType snake2(x),type_gallery EntityRadius snake2(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 Collisions SKIES,BODY,2,3 Collisions SKIES,WHEEL,2,3 Collisions NO,BODY,2,3 Collisions NO,WHEEL,2,3 Collisions ENEMY,BULL,2,3 ;STUFF...(GAMEPLAY) While Not KeyHit(1) HideEntity spark ;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 ;move tank 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 ;PIVOTS If Not KeyDown(2) TurnEntity pivot,0,.1,0 If Not KeyDown(2) TurnEntity pivot2,0,.2,0 If Not KeyDown(2) TurnEntity pivot3,0,.1,0 If Not KeyDown(2) TurnEntity pivot4,0,-.1,0 If Not KeyDown(2) TurnEntity pivot5,.4,-.4,0 If Not KeyDown(2) TurnEntity pivot6,.5,-.6,.1 If Not KeyDown(2) TurnEntity pivot7,0,-.4,.4 If Not KeyDown(2) TurnEntity pivot8,0,.1,0 If Not KeyDown(2) TurnEntity pivot9,0,.3,0 If Not KeyDown(2) TurnEntity pivot10,0,-.2,0 If Not KeyDown(2) TurnEntity pivot11,0,-.1,0 ;shoot If MouseHit(1)Then CameraPick camera,-10,0 ShowEntity spark PositionEntity spark, 0, EntityY (target2) -5.5,+50 PlaySound gunshot EndIf If MouseHit(2) And t<100 Then PositionEntity bullet(t) ,EntityX(car,4),EntityY(car,1),EntityZ(car,4) ShowEntity bullet(t) RotateEntity bullet(t) ,EntityPitch#(car,1),EntityYaw#(car,1),EntityRoll#(car,1) t=t+1 PlaySound gunz EndIf For e=0 To fullcart MoveEntity bullet(e),0,0,.5 Next ;DEAD ENEMIES ;RESET TANK If KeyDown(19) PositionEntity car,0,70,0 ;Help Create/Play 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
also can anyone show me how to use the mouse to move the sight to shoot the enemies...THANKS AGAIN