Joy Axis hit?

BlitzMax Forums/BlitzMax Programming/Joy Axis hit?

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.

Const joyDeadZone# = 0.5

Rem
'You could do something like this instead
	Global joyDeadZone#
	
	For c=1 To 1000
		If Abs(JoyY()) > joyDeadZone Then joyDeadZone = Abs(JoyX())
		If Abs(JoyY()) > joyDeadZone Then joyDeadZone = Abs(JoyY())
	Next

	joyDeadZone :* 1.1 ' Just to be on the safe side
End Rem

Graphics 800, 600, 0

Local ox = 400, oy = 300

Repeat
	ox :+ (JoyXHit() * 40)
	oy :+ (JoyYHit() * 40)
	
	Cls
	SetColor 200, 200, 0
	DrawOval ox - 20, oy - 20, 40, 40
    
	Flip
Until KeyHit(KEY_ESCAPE)

End


Function JoyXHit(port=0)
	Global centered = True
	Local jx# = JoyX(port)
	
	If centered
		If jx# > joyDeadZone#
			centered = False
			Return 1
		ElseIf jx# < -joyDeadZone#
			centered = False
			Return -1
		EndIf
	ElseIf (jx# >= -joyDeadZone#) And (jx# <= joyDeadZone#)
		centered = True		
	EndIf
End Function

Function JoyYHit(port=0)
	Global centered = True
	Local jy# = JoyY(port)
	
	If centered
		If jy# > joyDeadZone#
			centered = False
			Return 1
		ElseIf jy# < -joyDeadZone#
			centered = False
			Return -1
		EndIf
	ElseIf (jy# >= -joyDeadZone#) And (jy# <= joyDeadZone#)
		centered = True		
	EndIf
End Function