moving target

Blitz3D Forums/Blitz3D Programming/moving target

The 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.

I have the most of this already complete... Just a game I developed to learn how to create a missle firing system with tonnes of help from all the Ross' Wolron, Neuromancer et al...

But I can't figure out how to make the targets revolve around the gun.

I think I set the parent\child thingee okay, but when I move them they only slide off the screen. Rotateentity doesn't seem to wrok either.

QUE!!!

; Game 1
; Copyright 2004, 2005 Ralph Wm Dunn & Suspension Software
;

Graphics3D 800,600,16,1	
SetBuffer BackBuffer()
SeedRnd(MilliSecs()) + Pi            ; RANDOM NUMBERS
AppTitle "ALIENbuster - The game for the rest of us!","Do you Quit?"

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- I put all the globals in front for clarity
;											these things have to be gloabls to re use
;
Global camera=CreateCamera()			
PositionEntity camera,0,10,-15			;	Put the camera at 0, 10 UP and -15 BACK
Global main_bullet=LoadMesh("missle.b3d",turret) ; create a bullet that the type objects can copy.
HideEntity main_bullet						; hide it or it will be at 0,0,0
Global turret=LoadMesh("ufo1.b3d")	
Global badman=LoadMesh("badguy.b3d",camera)
HideEntity badman							; hide it too
Global badman2=LoadMesh("badguy2.b3d",camera)
HideEntity badman2	
Global gun_timer=MilliSecs() ; timer to track the difference in millisecs
Global gun_time=125 ; time in milliseconds that the gun will fire
Global score
Global kill
Global boom
Global shotz ;								If IT AIN'T Global YOU CAN'T USE IT IN A Function
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-	You should know what this is...

; =-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-		Create first bullet type CODE BY ROSS

Type bullet
	Field entity
	Field speed#
	Field range
	Field pivot
End Type
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=	Each of these fields will hold info about the BAD DUDES
Type badman
	Field entit
	Field xo
	Field yo
	Field zo
End Type

Type badman2
	Field entit2
	Field xo2
	Field yo2
	Field zo2
End Type

light=CreateLight()				
RotateEntity light,45,0,0		
AmbientLight 32,32,32

PositionEntity turret,0,0,0 ; 				Put the GUN in the center

bip=LoadSound("bip.ogg") ;					Sounds are more fun
happy=LoadSound("fart4.wav")
shootit=LoadSound("laser.wav")
SoundVolume shootit,.5
music=LoadSound("music.ogg")
LoopSound music
SoundPitch music,11000/.5
PlaySound music
MoveMouse 400,300 ; 						center the mouse in 800,600 use later to move GUN

HidePointer ; 								HIDE mouse pointer

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=		OK here is where we use the TYPE commands
;											here I am telling the computer to:
;											make 40 badmans (badman was a TYPE)

For tt= 1 To 20
hit.badman = New badman ;					where did HIT come from... I made it up. I could
hit\entit = CopyEntity (badman) ;			have used a letter or any word not reserved
hit\xo=Rnd(-100,100) ;						NOTE " \ " not " / "
hit\yo=Rnd(-50,50)
hit\zo=Rnd(100,150) ; 						Since B3D uses both + and - nums I had to use Rnd
Next ;										That way my badmans are spread out evenly-ish

For t= 1 To 20
hat.badman2 = New badman2 ;					where did HIT come from... I made it up. I could
hat\entit2 = CopyEntity (badman2) ;			have used a letter or any word not reserved
hat\xo2=Rnd(-100,100) ;						NOTE " \ " not " / "
hat\yo2=Rnd(-50,50)
hat\zo2=Rnd(100,125) ; 						Since B3D uses both + and - nums I had to use Rnd
Next ;	

kill=40
Collisions 1,2,2,1
Collisions 2,1,2,1 ; Set collisions bullet is 1 and badman is 2 (is that backwards)
boom = 0


Timer=MilliSecs()


While Not KeyHit(1)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=		Routine to use mouse to move turret NEEDS WORK
If MouseX()>490 Then MoveMouse 490,MouseY()
If MouseX()<310 Then MoveMouse 310,MouseY()
xx=MouseXSpeed()
yy=MouseYSpeed()

TurnEntity turret,0,xx,0 	; rotate th turret
TurnEntity turret,yy,0,0		; angle the gun

;For tp = 1 To KILLER
;PositionEntity hit\entit,hit\xo,hit\yo,100 ; after we make them we PUT them
;Next

; =-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=	Ross' routine to slow down rate of fire
	If MouseDown(1) And MilliSecs()>gun_time+gun_timer Then
		gun_timer=MilliSecs() ; reset the timer
		create_bullet(turret); call function to create a bullet. Pass across the gun entity to the function
						  ; so the bullet can come from the guns position
		PlaySound(shootit)
	End If
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Caling more functions to update bullet position and put badmans
	put_badmans()
	update_bullet()
	
If boom = 1 PlaySound (bip)
If boom = 2 PlaySound (happy)

UpdateWorld
RenderWorld
Text 0,10,"POINTS: "+ score
Text 0,25,"KILLED: "+ kill
Text 0,40,"SHOTS: "+shotz
total = score-shotz
Text 0,55,"SCORE: "+total
; 							Why make the SCORE like that??? Just a thing to do.
; 							1000 points for killing all - number of shots
; 							it's a skill thing...
Flip

boom = 0

Oval 50,50,100,100,0 
Line 100,100,XXX,YYY 
If MilliSecs()-Timer>1000 
Seconds=Seconds+1 
If Seconds>59 Then 
Seconds=0 
Timer=MilliSecs() 
End If
EndIf

Wend

End

; most of the gun code is from Ross

Function create_bullet(turret_entity)
	b.bullet=New bullet
	
		temp_x=EntityX(turret_entity,True)
		temp_y=EntityY(turret_entity,True)
		temp_z=EntityZ(turret_entity,True)
		
		b\entity=CopyEntity(main_bullet) ; copy the main bullet entity , into the type object
		b\pivot=CreatePivot()
		EntityType b\entity,2
		PositionEntity b\entity,temp_x,temp_y,temp_z
		RotateEntity b\entity,EntityPitch(turret_entity,True),EntityYaw(turret_entity,True),0
		PositionEntity b\pivot,temp_x,temp_y,temp_z
		b\range=259 ; the range of the bullets
		b\speed=5 ; the speed of the bullets
		shotz=shotz+1
End Function

Function update_bullet()
	For b.bullet = Each bullet
		MoveEntity b\entity,0,0,b\speed ; this is my collision modification HERE
			If EntityCollided (b\entity,1) Then ; no one would help with entitycollided
				;kill = kill-1
				score = score+10 	; update socre
				FreeEntity b\entity  ; kill bullet if it hits... note the GOTO
				FreeEntity b\pivot 
				Delete hit.badman
				Delete b.bullet 
				Goto outie			; inelegant but functional
			EndIf
			If EntityDistance#(b\entity,b\pivot) > b\range Then
			FreeEntity b\entity
			FreeEntity b\pivot
			Delete b.bullet
.outie
		End If
	Next
End Function

Function put_badmans()
	For hit.badman = Each badman
		If EntityCollided (hit\entit,2) Then
				boom = 1
				score = score+5 
				kill = kill - 1
		 		FreeEntity hit\entit
		 		FreeEntity xo
		 		FreeEntity yo
				FreeEntity zo
		 		Delete hit.badman
		EndIf
	Next
	For hat.badman2 = Each badman2
		If EntityCollided (hat\entit2,2) Then
				boom = 2
				score = score+25
				kill = kill - 1
		 		FreeEntity hat\entit2
		 		FreeEntity xo2
		 		FreeEntity yo2
				FreeEntity zo2
		 		Delete hat.badman2
		EndIf
	Next
	For hit.badman = Each badman
		EntityType hit\entit,1
		PositionEntity hit\entit,hit\xo,hit\yo,hit\zo
	Next
		For hat.badman2 = Each badman2
		EntityType hat\entit2,1
		PositionEntity hat\entit2,hat\xo2,hat\yo2,hat\zo2
	Next
End Function