FIXED!!! Player getting hurt for no reason (metrovania 4.5.6)

baardbi

Well-known member
In my metroidvania game in NESmaker 4.5.6 my player is sometimes hurt for no apparent reason. It's almost like there are invisible hurt tiles. The problem is that it doesn't happen in the same place every time. Can it be related to the hurt_monster script? I haven't done any tweaking to that script that would explain this behaviour. Has anyone else experienced this?

Here is my hurtPlayer_MetroidVania.asm:

Code:
	;;;;;;;;;;;;;;;;;; Presumes there is a variable called myLives defined in user variables.
	;;;;;;;;;;;;;;;;;; You could also create your own variable for this.

	LDA gameHandler
	AND #%10000000
	BEQ +canHurtPlayer
		JMP +skipHurt
+canHurtPlayer:
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;;;;;;;; is the monster below our feet?
	;;;;;;;;;; and are we moving downward?

+doHurtPlayer	
	TXA
	STA temp
	GetActionStep temp
	CMP #$07
	BNE +canHurtPlayer
		JMP +skipHurt
	+canHurtPlayer
	;;; will presume there is a variable myHealth
	;;; and that player hurt state is action state 7.
	GetActionStep player1_object
	CMP #$07 ;; hurt state.
	BEQ +notAlreadyInHurtState
		DEC myHealth
		
		;PlaySound #sfx_noteDead
		
		BMI +healthBelowZero
		BEQ +healthBelowZero
			JMP +notDeadYet
		+healthBelowZero
			
			JMP +playerHealthIsZero
		+notDeadYet
		UpdateHudElement #$02
		ChangeActionStep player1_object, #$07
			;; recoil
			LDA #$00
			STA Object_h_speed_hi,x
			STA Object_h_speed_lo,x
			STA Object_v_speed_hi,x
			STA Object_v_speed_lo,x
			LDA xPrev
			STA Object_x_hi,x
			LDA yPrev
			STA Object_y_hi,x
	+notAlreadyInHurtState
		LDA Object_x_hi,x
		CLC
		ADC self_center_x
		STA tempA
		LDA Object_y_hi,x
		CLC
		ADC self_center_y
		STA tempB
		TXA 
		PHA
			LDX otherObject
			LDA Object_x_hi,x
			CLC
			ADC other_center_x
			STA tempC
			LDA Object_y_hi,x
			CLC
			ADC other_center_y
			STA tempD
		PLA
		TAX
	
		;;; RECOIL L/R
			;+recoilHor
				LDA tempA
				CMP tempC
				BCS +recoilRight
					LDA Object_direction,x
					AND #%00001111
					ORA #%10000000
					STA Object_direction,x
					JMP +skipHurt

				+recoilRight
					LDA Object_direction,x
					AND #%00001111
					ORA #%11000000
					STA Object_direction,x
					JMP +skipHurt
	
+playerHealthIsZero:

	LDA continueMap
	STA warpMap
	
	LDA continueX
	STA newX
	LDA continueY
	STA newY
	
	LDA continueScreen
	STA warpToScreen
	STA camScreen
	

	LDA myMaxHealth
	STA myHealth
	
	
	
	WarpToScreen warpToMap, warpToScreen, #$02
		;; arg0 = warp to map.  0= map1.  1= map2.
		;; arg1 = screen to warp to.
		;; arg2 = screen transition type - most likely use 1 here.
			;; 1 = warp, where it observes the warp in position for the player.

	
+skipHurt

Here is my hurtMonster_PlatformBase.asm:

Code:
	TXA
	STA temp
	GetActionStep temp
	CMP #$07 ;; we will use action step 7 for hurt.
	;BEQ +doSkipHurtingThisObject ;; if he is hurt, he can't be hurt again.
	BNE +doNotSkipHurtingThisObject
		JMP +doSkipHurtingThisObject
	+doNotSkipHurtingThisObject
		ChangeActionStep temp, #$07
		LDA #$80
		STA Object_action_timer,x
		DEC Object_health,x
		LDA Object_health,x
		BEQ +dontSkipHurtingThisObject
		JMP +doSkipHurtingThisObject
	+dontSkipHurtingThisObject:
			LDA Object_x_hi,x
			STA tempx
			LDA Object_y_hi,x
			STA tempy
			
			LDA Object_screen,x
			STA tempD
			
			DestroyObject
			CreateObjectOnScreen tempx, tempy, #$0E, #$00, tempD
			
			CountObjects #%00001000
			BEQ +zeroCount 
			JMP +notZeroCount
	+zeroCount:
				LDA scrollByte
				ORA #%00000010
				STA scrollByte
				;;; if there are no more monsters left, we want to disable
				;;; the edge check for scrolling.
				LDA ScreenFlags00
				AND #%11101111
				STA ScreenFlags00
				
				LDA screenType
				CMP #$6F
				BNE +notBossRoom
				TriggerScreen #$6F
				StopSound
				PlaySong song_STAGA
	+notBossRoom
				;ChangeTileAtCollision #$06, #$00
			+notZeroCount
	+doSkipHurtingThisObject
 

twin paradox

New member
This could be completely unrelated but I was having weird issues where I would collide with NPC objects that were on a different screen. Like, the game thought the NPC was on my current screen when it was actually in an adjacent screen. This would result in my player being randomly blocked from moving because the game thought it was colliding with an NPC. My work around for the time being is to make sure that I assigned 4 monsters/objects to EACH Screen. For screens that didn't have actual monsters I just created a "dummy" invisible monster that was not able to collide with the player and placed 4 of them. It seemed to have solved the problem although I wish I understood the underlying cause.
 

baardbi

Well-known member
twin paradox said:
This could be completely unrelated but I was having weird issues where I would collide with NPC objects that were on a different screen. Like, the game thought the NPC was on my current screen when it was actually in an adjacent screen. This would result in my player being randomly blocked from moving because the game thought it was colliding with an NPC. My work around for the time being is to make sure that I assigned 4 monsters/objects to EACH Screen. For screens that didn't have actual monsters I just created a "dummy" invisible monster that was not able to collide with the player and placed 4 of them. It seemed to have solved the problem although I wish I understood the underlying cause.

Thanks for the tip. That's interesting and kinda sounds similar to my problem. I'll try it out.
 

baardbi

Well-known member
twin paradox said:
This could be completely unrelated but I was having weird issues where I would collide with NPC objects that were on a different screen. Like, the game thought the NPC was on my current screen when it was actually in an adjacent screen. This would result in my player being randomly blocked from moving because the game thought it was colliding with an NPC. My work around for the time being is to make sure that I assigned 4 monsters/objects to EACH Screen. For screens that didn't have actual monsters I just created a "dummy" invisible monster that was not able to collide with the player and placed 4 of them. It seemed to have solved the problem although I wish I understood the underlying cause.

I have done some testing on this and I think you're absolutely right. It seems to have something to do with enemy collision. I couldn't fill the screen with enemies like you, because my enemy groups are full, so I don't have room for a dummy enemy and filling the screen with four enemies causes lag in my game. Anyway I hope this bug gets fixed, since I'm pretty sure this has something to do with the scrolling modules in NESmaker.
 

mouse spirit

Well-known member
Yeah i think it has to do with scrolling also. Mainly like when it checks ahead a screen for scrolling. So i bet atleast some of these things may only happen on every other screen.

Im in 4.1.5 but i have had so many "adjacent screen" issues. Screens triggering , solid tiles , monsterlocks, the list goes on. Id say its a tile issue for me mainly.
 

baardbi

Well-known member
mouse spirit said:
Yeah i think it has to do with scrolling also. Mainly like when it checks ahead a screen for scrolling. So i bet atleast some of these things may only happen on every other screen.

Im in 4.1.5 but i have had so many "adjacent screen" issues. Screens triggering , solid tiles , monsterlocks, the list goes on. Id say its a tile issue for me mainly.

Yes. I remember Joe saying something about weird issues could occur in the scrolling modules. It would be awesome if it could be fixed though.
 

PasseGaming

Active member
Same happens in my scrolling shoot'em up. Sometimes the player will just randomly die. It's unfortunate and I haven't figure out a way to fix it.
 

foovax

New member
L2R platform here with same issue of dying while scrolling. I've also noticed some inconsistency with hidden solid blocks that seem to correlate with when this happens. Near the start of the level I jump and player seems to get blocked like it hit a solid tile. When I go back to jump around the area there isn't anything blocking but when moving forward I'll have the random death. Unsure if it's correlated 100%.

My initial thought was that a monster is spawning on top of player and I died and warped out to a death screen before I could see the monster draw.

I changed the monster spawn points to the far right of the screen and it seems to work more as expected.

Can FCEUX "record" the memory for playback or if a recording is taken can it play back to attempt to view what was going on at a specific moment in play?
 

baardbi

Well-known member
The solution to this problem was found last year, but I thought it would be a good idea to link the solution in this thread:


Thank you so much CluckFox for fixing this really annoying bug :) :) :)
 
Top Bottom