Improved Hurt / Recoil System

Bucket Mouse

Active member
As it is, the big recoil when the player touches an enemy is a cheap method of avoiding repeated damage -- and it doesn't work in every situation; if the recoil pins you against a wall the monster can just poke at you over and over until you're dead.

What we need is two Action Steps: the recoil and a period of invincibility afterward. To do this we must move Hurt to Action Step 06 so the other part can be 07. Setting up the invincibility is pretty simple, since the player is ALSO invincible during the recoil and it is just a skip of the Player Hurt code:

Code:
	CMP #$07
	BNE +canHurtPlayer
		JMP +skipHurt
	+canHurtPlayer

You can just duplicate that for #$06 and have it work in both Action Steps. Then, upon the suggestion of AllDarnDavey below, you alter Action States 6 and 7 of your player character as follows:

recoil1.jpg

Note how the recoil time here is much lower than what Joe sets it at in the tutorial. It's no longer necessary to fling your character clear across the screen if you have a little extra time to move out of the way, and it's also annoying.

recoil2.jpg

Make the invincibility time a bit longer than the recoil....just enough time to get out of the way. Note that your Hurt animation should be of the player flashing, if it's not already.

Now to make it so Step 6 makes you invincible. The following scripts must be altered a bit:

PlayerHurt_Health
doHandleObjectCollisions_AdventureBase2 (the module I'm using...it is present in the other variations of this script as well)
stopMoving
Bank18_AdventureBase

I changed all of these to read both action state 06 and 07 as invincibility states. PlayerHurtHealth should look like this near the beginning:

Code:
	GetActionStep temp
	CMP #$06
	BNE +canHurtPlayer
		JMP +skipHurt
	+canHurtPlayer
			CMP #$07
	BNE +canHurtPlayer2
		JMP +skipHurt
	+canHurtPlayer2

What to change in doHandleObjectCollisions_AdventureBase2:

Code:
	GetActionStep temp
		CMP #$06
	BNE +notHurt1
		JMP +skipObjectCollisionCheck
		+notHurt1
	CMP #$07
	BNE +notHurt2
		JMP +skipObjectCollisionCheck
	+notHurt2

The entirety of the altered StopMoving:

Code:
;;;; 
    TXA
    STA temp ;; assumes the object we want to move is in x. 
   GetActionStep temp
    CMP #$07
    BNE +notHurt
        RTS
    +notHurt   
	    CMP #$06
    BNE +notHurt2
        RTS
    +notHurt2   
    StopMoving temp, #$FF, #$00
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    RTS

And what to do in Bank18:

Code:
					GetActionStep tempz
					CMP #$06
					BNE +notHurtState
						LDA ObjectUpdateByte
						ORA #%00000001 ;; is it solid?
						STA ObjectUpdateByte
						JMP ObjectDoesNotObserveTiles
					+notHurtState
										CMP #$07
					BNE +notHurtState2
						LDA ObjectUpdateByte
						ORA #%00000001 ;; is it solid?
						STA ObjectUpdateByte
						JMP ObjectDoesNotObserveTiles
					+notHurtState2

You get the idea -- you just duplicate the code each time.

Now you stand a fighting chance out there in the dungeons you create.
 

AllDarnDavey

Active member
I hate to bring this up Bucket Mouse, but you didn't need to change all the code references to action 6. You could've kept them as action 7, set action 7's end action to "GoToPrevious", then made action 6's end action "GoToFirst". In essence, just swap the 2 states around... it doesn't have to go 6 before 7.
 

Bucket Mouse

Active member
AllDarnDavey said:
I hate to bring this up Bucket Mouse, but you didn't need to change all the code references to action 6. You could've kept them as action 7, set action 7's end action to "GoToPrevious", then made action 6's end action "GoToFirst". In essence, just swap the 2 states around... it doesn't have to go 6 before 7.

.......You appear to be correct.

HOWEVER....you STILL need to duplicate the invincibility code in most of those scripts, so my day wasn't completely wasted. Just 1/3 wasted.
Update to the first post is coming.
 

Jonny

Well-known member
.......You appear to be correct.

HOWEVER....you STILL need to duplicate the invincibility code in most of those scripts, so my day wasn't completely wasted. Just 1/3 wasted.
Update to the first post is coming.

Just to confirm, the second action state checks can be removed from the code as I only need to check action 7?

I'm gonna try this out. Then, I'd like to remove the recoil completely but parts of the code seem to be spread over several scripts so that might take a while without breaking something.
If my player is still stood on a monster or in front of a gun after the invicibility period it through, its tough titty. Thats life. I think that would be less annoying than getting blasted backwards off a ledge whilst traversing a section of jumps challenges.

-----

Hmm... thats odd. I tried it and my sprite HUD disapears and player wont move. Can't understand why those two thing would be effected.

-----

Sorry for all the edits. Got it working. I had to move the code you provided above a bit further down in script after some other checks.

Works lovely now, thankyou.
 
Last edited:
Top Bottom