keyboard controls for a gun ship

Blitz3D Forums/Blitz3D Beginners Area/keyboard controls for a gun ship

Oh! Is your problem that you don't know how to get the jewels moving without hijacking execution from the rest of your code?

Keep track of whether or not your jewels are active. If they are, move them forward each frame. Add an Update_Jewels() function call to your main game loop. The Fire_Jewel_*() functions should set the appropriate jewel to be "active" (so that the update function will move it) and position the jewel at beginning of its flight path.

If this is your problem and you want an example, just ask. Right now I'm off to drink as much vodka as possible.

Here's something I wrote four years ago which is somewhat similar. There's an easier way to do the trig too.
; initialize the usual
SeedRnd MilliSecs()
Graphics3D 800, 600
Global camera = CreateCamera()
PositionEntity camera, 0, 10, -20
Global light = CreateLight()
TurnEntity light, 20, 60, 0

; create some minimal scenery
Global plane = CreatePlane()
EntityAlpha plane, 0.6
EntityColor plane, 0, 0, 255
Global mirror = CreateMirror()

; create our cannon: a stretched cube
Global cannon_entity = CreateCube()
Global cannon_pitch#, cannon_yaw#
PositionEntity cannon_entity, 0, 6, 0
ScaleEntity cannon_entity, 1, 1, 5

; our cannonballs will be a linked link of projectiles: entities and a vector for velocity
Type projectile
	Field entity
	Field vx#, vy#, vz#
End Type


While Not KeyHit(1)

	; control movement of cannon
	If KeyDown(200) Then cannon_pitch = cannon_pitch + 0.5
	If KeyDown(208) Then cannon_pitch = cannon_pitch - 0.5
	If KeyDown(203) Then cannon_yaw = cannon_yaw + 0.5
	If KeyDown(205) Then cannon_yaw = cannon_yaw - 0.5
	RotateEntity cannon_entity, cannon_pitch, cannon_yaw, 0

	; fire!
	If KeyHit(57) Then
		Local cannonball.projectile = New projectile
		cannonball\entity = CreateCube()
		PositionEntity cannonball\entity, EntityX(cannon_entity), EntityY(cannon_entity), EntityZ(cannon_entity)
		Local speed# = 0.5
		cannonball\vx = speed * Cos(cannon_pitch) * Sin(-cannon_yaw)
		cannonball\vy = speed * Sin(-cannon_pitch)
		cannonball\vz = speed * Cos(cannon_pitch) * Cos(cannon_yaw)
	EndIf

	; update all projectiles
	For this.projectile = Each projectile

		; apply gravity
		this\vy = this\vy - 0.01

		; move according to our vector
		TranslateEntity this\entity, this\vx, this\vy, this\vz
		RotateEntity this\entity, VectorPitch(this\vx, this\vy, this\vz), VectorYaw(this\vx, this\vy, this\vz), 0

		; remove projectiles which have hit the "ground"
		If EntityY(this\entity) < 0 Then
			FreeEntity this\entity
			Delete this
		EndIf

	Next

	; show the scene
	RenderWorld()
	Text 0, 0, "Arrow keys to move"
	Text 0, 20, "Space to fire"
	Flip
Wend
End