Hurt Tile

dale_coop

Moderator
Staff member
Sorry... Currenlty, it doesn't exist. You have death tiles or monster objects.

But maybe it would be interesting / useful if someone could make that kind of tiles and share that on the forum ;)
 

Mugi

Member
here you go:

save this as an .asm file, and assign it to a tile type from script settings.
this tile will hurt the player upon collision, and othervise acts as a solid object.
the script assumes that your player's hurt state is 05, adjust if necessary.

Code:
	LDA #TILE_SOLID
	STA tile_solidity

	LDA Object_health,x
	SEC
	SBC #$01 
	CMP #$01
	BCS notPlayerDeath2
	
	PlaySound #SND_HURT_PLAYER
	JSR HandlePlayerDeath
	JMP doneWithPlayerHurt2

notPlayerDeath2:
	STA Object_health,x
	STA myHealth
	
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
	UpdateHud HUD_myHealth
	
	LDA Object_status,x
	ORA #%00000001
	STA Object_status,x	

	LDA #HURT_TIMER
	STA Object_timer_0,x
	ChangeObjectState #$05,#$02 		; uses state #$05 for hurt state.
								; set this to your player's hurt state.
	LDA selfCenterX
	STA recoil_selfX
	LDA selfCenterY
	STA recoil_selfY
	LDA otherCenterX
	STA recoil_otherX
	LDA otherCenterY
	STA recoil_otherY
	
	JSR DetermineRecoilDirection

doneWithPlayerHurt2:

might be slightly buggy but my whole game is slightly buggy at the moment so can't test it too well. it's essentially just a modification of the handleplayerhurt.
 

Cobalt24

New member
Mugi said:
here you go:

save this as an .asm file, and assign it to a tile type from script settings.
this tile will hurt the player upon collision, and othervise acts as a solid object.
the script assumes that your player's hurt state is 05, adjust if necessary.

Code:
	LDA #TILE_SOLID
	STA tile_solidity

	LDA Object_health,x
	SEC
	SBC #$01 
	CMP #$01
	BCS notPlayerDeath2
	
	PlaySound #SND_HURT_PLAYER
	JSR HandlePlayerDeath
	JMP doneWithPlayerHurt2

notPlayerDeath2:
	STA Object_health,x
	STA myHealth
	
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
	UpdateHud HUD_myHealth
	
	LDA Object_status,x
	ORA #%00000001
	STA Object_status,x	

	LDA #HURT_TIMER
	STA Object_timer_0,x
	ChangeObjectState #$05,#$02 		; uses state #$05 for hurt state.
								; set this to your player's hurt state.
	LDA selfCenterX
	STA recoil_selfX
	LDA selfCenterY
	STA recoil_selfY
	LDA otherCenterX
	STA recoil_otherX
	LDA otherCenterY
	STA recoil_otherY
	
	JSR DetermineRecoilDirection

doneWithPlayerHurt2:

might be slightly buggy but my whole game is slightly buggy at the moment so can't test it too well. it's essentially just a modification of the handleplayerhurt.

Thanks for this, I tried to import it and I got "Routines\UserScripts\PlatformGame_Base\TileScripts\hurt.asm(21): Illegal instruction." when trying to launch the game though. I have no idea how the asm files work so sorry if this is a stupid problem to have.
 

Mugi

Member
propably the UpdateHud HUD_myHealth macros dont exist on 4.0.11, since that's what your error message complains about.
 

Cobalt24

New member
Mugi said:
propably the UpdateHud HUD_myHealth macros dont exist on 4.0.11, since that's what your error message complains about.

I heard that I won't be able to move my project file over to 4.1 and I'll have to start from scratch, is that true?
 

dale_coop

Moderator
Staff member
Yep, the 4.1 is out (yesterday).
A LOT of things changed, you might have to do again your project from scratch (don't reopen your old project in NESMaker4.1). But you might be able to Export some elements from your NESMaker 4.0.11 and import them in the 4.1 (from menus).
First, I would suggest you to watch all the new tutorials on the official website: thenew8bitheroes.com
 

Retrobuster

New member
Sorry to resurrect a kind of old post, but I was looking for this sort of thing and I've got the script working...kind of. I've got my player set to 3 health but this tile seems to kill me immediately. I can't tell if it's just not making me temporarily immune to being hurt, therefore, taking away all 3 health very quickly or if there's something else wrong that's causing me to die right away. I did change the Hurt State to 00 (idle) like the standard HandlePlayerHurt script but that's the only thing I edited. Any thoughts?

Oh, btw, if it matters, I'm using the Maze module.

EDIT: I've also tried mimicking the HandlePlayerDeath script that's in the Tile Scripts section for a simple platformer - where it appears to call the HandlePlayerDeath.asm script in the HurtWinLoseDeath area for scripts. I used this script from above as a new HurtWinLoseDeath script and and called it HandlePlayerHurtTile. Then, I adapted the HandlePlayerDeath tile script to call this new HandlePlayerHurtTile script. But then I get this error - GameData\CodeTargets.asm(92): Need a name. Sorry if this is confusing - I still lack knowledge when it comes to this stuff but in my head it made sense to try this.
 

dale_coop

Moderator
Staff member
You could try adding:

Code:
	LDA Object_status,x
	AND #HURT_STATUS_MASK ;; if the monster is hurt, it can't hurt us
	BEQ +
	JMP doneWithPlayerHurt2
	+

in Mugi's code, at line 3, just after the "sta tile_solidity" like that:

Code:
	LDA #TILE_SOLID
	STA tile_solidity

	LDA Object_status,x
	AND #HURT_STATUS_MASK ;; if the monster is hurt, it can't hurt us
	BEQ +
	JMP doneWithPlayerHurt2
	+
 

Retrobuster

New member
That definitely helped. Now I'm wondering how I can go about removing that tile entirely once I collide with it- like how the collectable tile disappears after you collide with it and is replaced with just a basic walkable tile AND how to subtract from the score in the opposite manner of the collectable tile. Don't tell me just yet! Trying to figure this out for myself, but just still wanted to reply to say you've helped me get this far. Thanks!
 

dale_coop

Moderator
Staff member
Retrobuster said:
That definitely helped. Now I'm wondering how I can go about removing that tile entirely once I collide with it- like how the collectable tile disappears after you collide with it and is replaced with just a basic walkable tile AND how to subtract from the score in the opposite manner of the collectable tile. Don't tell me just yet! Trying to figure this out for myself, but just still wanted to reply to say you've helped me get this far. Thanks!

Ah ah, I almost replied to you with the answer... :p
I let you search, as you said, you can get inspiration from the Collectable.asm script, it's a good practice.
 

Retrobuster

New member
lol ok I figured out how to get the score to subtract (very proud of myself haha) but I can't figure out the part where it hurts the player. I tried adding this to the bottom of my new "CollectableHurt" script:

CPX player1_object
BNE +
JSR HandlePlayerHurt
PlaySound #SND_HURT_PLAYER
+

Because I saw that the Simple Platformer has a script for PlayerDeath that looks like this so I thought if I just swapped out the "Death" text with "Hurt" it'd work, but it didn't seem to like the JSR HandlePlayerHurt line. I got an unknown label error. Not sure if I'm just slightly off or if I'm not even in the ballpark.
 

dale_coop

Moderator
Staff member
The script on page 1 already do the hurt / the death is correct (hurt, then kill you).
You can add the code I wrote some posts before this one.

Your substractValue code you can put it just after the JSR DetermineRecoilDirection (it's the end of the "player" is hurt)

Of course, if you can't find how to... I can give you the script.
 

Retrobuster

New member
That did it! Thank you. I tried something similar but think I messed up where I put my subtractvalue code. Appreciate the help as always!
 

Retrobuster

New member
OK, so I'm having another issue that has appeared since I added monsters to my screen. Whenever a monster collides with this "Collectable Hurt" tile, it would insta-kill me, the player. I changed the monster's health to 0 and it no longer affects me, but the monster still flashes (it's hurt state) whenever it collides with the tile. I can't figure out how to either change it's hurt state so it looks the same as it's normal state or how to just make the tile not interact with the monster.
 

Mugi

Member
CPX player1_object
BEQ +
LDA #TILE_SOLID
STA tile_solidity
RTS
+

the rest of the code you have goes under the +

now the tile is a normal solid tile for everything except the player object. If you want the tile to be absolutely nothing for monsters, just remove 3rd and 4th line.
 

baardbi

Well-known member
This is awesome! Thank you Mugi. However I want to distinguish between the player and monsters, so I added this to the beginning of the script:

Code:
	LDA #TILE_SOLID
	STA tile_solidity

	LDA ObjectFlags,x	;; Is it a monster?
	AND #%00001000
	BNE notAmonster
	RTS
notAmonster:

But now both the player and the monster treat the tile as solid (no hurt whatsoever). Am I using the object flags correctly?

Here is the entire script:

Code:
	LDA #TILE_SOLID
	STA tile_solidity

	LDA ObjectFlags,x	;; Is it a monster?
	AND #%00001000
	BNE notAmonster
	RTS
notAmonster:

	LDA Object_health,x
	SEC
	SBC #$01 
	CMP #$01
	BCS notPlayerDeath2
	
	PlaySound #SND_HURT_PLAYER
	JSR HandlePlayerDeath
	JMP doneWithPlayerHurt2

notPlayerDeath2:
	STA Object_health,x
	STA myHealth
	
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
	UpdateHud HUD_myHealth
	
	LDA Object_status,x
	ORA #%00000001
	STA Object_status,x	

	LDA #HURT_TIMER
	STA Object_timer_0,x
	ChangeObjectState #$04,#$02 		; uses state #$04 for hurt state.
								; set this to your player's hurt state.
	LDA selfCenterX
	STA recoil_selfX
	LDA selfCenterY
	STA recoil_selfY
	LDA otherCenterX
	STA recoil_otherX
	LDA otherCenterY
	STA recoil_otherY
	
	JSR DetermineRecoilDirection

doneWithPlayerHurt2:
 
Top Bottom