JoyHit

BlitzMax Forums/BlitzMax Programming/JoyHit

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'm reading of ppl complaining about JOYHIT, so I'm just posting My version on how I resolved it for my game. Since I'm making a figthing game JoyHit is important so this is how I got around it.

This is my first post here so I don't know how to put the code comments if someone can show me I can edit the post.

Let me know what you guys think
Type JoyButtonHit
	Field JoyButtonHitItemList:TList 	= New TList
	Field LastButtonPressed:buffer 		= New buffer
	
	Method Pressed(ButtonID:Int,ButtonTime:Float)
                Local a:buffer 	= New buffer	
		a.id 			= ButtonID
		a.time 			= ButtonTime
		LastButtonPressed = a
		
		
		JoyButtonHitItemList.AddLast(a)
								
		If  CountList(JoyButtonHitItemList) > 20  Then JoyButtonHitItemList.RemoveFirst() 		
	End Method 
	
	Method gotHIT:Int(ButtonID:Int,ButtonTime:Float=0,Recovery:Float=500)
		Local b:buffer
		Local ok:Int = 1		
		
	
		For b = EachIn JoyButtonHitItemList                
			If b.id = ButtonID Then
				If b.time + Recovery > ButtonTime Then			
					ok = 0 
					Exit		
				EndIf  
			EndIf
		Next
				
		Return ok
	End Method 
	
End Type

Type buffer
	Field id:Int
	Field time:Float
End Type

' Somewhere on your code
Field jButtons:JoyButtonHit = New JoyButtonHit	

If JoyDown(4,0)  Then 								
				
If jButtons.gotHIT(JoyDown(4,0),MilliSecs(),500) = True Then
   ' Process any Hit Actions
Else
   ' Process any Button Hold
EndIf				
				
jButtons.Pressed(JoyDown(4,0),,MilliSecs())
EndIf