keyboard controls for a gun ship

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

Doesn't make much of a difference. Since these conditionals will only run once per frame, it's merely a question of style.

Common wisdom suggests that you should move all "magic numbers" out of your code and name them. Basically, this means that you should use constants.

Here's how I'd do it:

Const GUNSHIP_SPEED#   = 0.2
Const GUNSHIP_Y_RANGE# = 9.0

Const KEY_UP    = 200
Const KEY_LEFT  = 203
Const KEY_RIGHT = 205
Const KEY_DOWN  = 208

;;;

	; let the player move the gunship
	y = y + (KeyDown(KEY_UP) - KeyDown(KEY_DOWN)) * GUNSHIP_SPEED
	
	; restrict the gunship to reasonable bounds
	if y < -GUNSHIP_Y_RANGE then y = -GUNSHIP_Y_RANGE
	if y > GUNSHIP_Y_RANGE  then y = GUNSHIP_Y_RANGE
	
	; let the player fire the jewels
	If KeyDown(KEY_LEFT)  Then Fire_Jewel_Left()
	If KeyDown(KEY_RIGHT) Then Fire_Jewel_Right()


P.S. Don't forget to remove your debug code:
		RenderWorld
		Text 0,60, "fx Position: "+i : Flip
		For t=0 To 10000000 : Next