Trouble with making a character punch

BlitzPlus Forums/BlitzPlus Beginners Area/Trouble with making a character punch

En929(Posted 2011) [#1]
I'm still having a lot of trouble with a fighting element in part of my game. I'm wondering how do I make it so that HENRY can do a right punch if that frame (h\frame) for punching is 7 (with h\frame 6 being the frame in which HENRY faces the right). Also, I wanted my HENRY character to punch in the Left direction if the frame (h\frame) for that is 9 (with h\frame 8 being the frame in which Henry faces the left before and after punching).

Below, there's a line with notes at the section that I want to fix at Key (25). It's so that the part that I need help with can be easier to find.

Thanks

Graphics 1640, 1000 
SetBuffer BackBuffer()
GameTimer = CreateTimer(60)


Global HENRYIMAGE = LoadAnimImage ("HenryMoveAroundIII.PNG",400,370,0,14)




Type HENRY
	Field x,y	
	Field frame
	Field image 
	Field Time
End Type 


Global h.HENRY = New HENRY
h\x = 500
h\y = 430
h\image = HENRYIMAGE



While Not KeyDown(1)


Cls

WaitTimer (GameTimer) 

HenryCharacteristics()



Flip

Wend  


Function HenryCharacteristics()



DrawImage (h\image,h\x,h\y,h\frame)


If KeyDown (203) Then 

	If h\Time<MilliSecs()
		h\x = h\x - 6



		h\frame = h\frame + 1
		
	        If h\frame > 5 Then ;Frame 5 and 4 are used for walking to the left
			h\frame = 4
	
	
	        EndIf 
	
			If h\frame < 4 Then
				h\frame = 4
			EndIf 
		
		h\Time=MilliSecs()+100

	EndIf 

EndIf 

If KeyDown (205) Then

	If h\Time<MilliSecs()
		h\x = h\x + 6


		h\frame = h\frame +1  

			If h\frame > 2 Then  ;Frames 2 and 1 are used for walking to the right
			h\frame = 1
		
			EndIf 
		
			If h\frame < 1 Then
			h\frame = 1
			EndIf 
			
		h\Time=MilliSecs()+100
	EndIf 
EndIf 
  





If KeyHit(25);---------------------- Here's the part I need help with----------------------------------------------------

;how do I make it so that HENRY can do a right punch using Key (25), if that frame (h\frame) for punching is 7 (with
;h\frame 6 being the frame in which HENRY faces the right). Also with Key (25), I wanted my HENRY character 
;To punch in the Left direction if the frame (h\frame) for that is 9 (with h\frame 8 being the frame
;in which Henry faces the left before and after punching. 


;I'm basically trying to make something like the old NES game Kung Fu, Bad Dudes, etc. But I'm having trouble doing it. 





EndIf 
;-----------------this is all I need help with for now---------------------
	
     			





   				

			
   

 End Function  



Last edited 2011


Midimaster(Posted 2011) [#2]
you should divide key-checks form painting. To do this you could define 4 states:
Global State% , FilmStep%
WALK_LEFT = 4
WALK_RIGHT = 1
PUNCH_LEFT = 8
PUNCH_RIGHT = 6
you see: this Constants will define the first frame number of each 2-step-seqence


Now you check the keys to fix which state is the current:
If KeyDown(25)
     If State=WALK_LEFT
          State = PUNCH_LEFT
     Else
          State = PUNCH_RIGHT
     Endif
ElseIf KeyDown(203)
     State = WALK_LEFT
ElseIf...
     .....
you can add as many state as you like


In last step you select the next image to be painted:
FilmStep = 1-FilmStep 
h\frame = State+FilmStep  
the FilmStep% will alter from 0 to 1 and back. So frame will alter from 8 to 9 and back (in case of PUNCH_RIGHT)


En929(Posted 2011) [#3]
Thanks MidiMaster, I got it to work. Thanks for helping me. I'll come back if I have any more questions.