; -----------------------------------------------------------------
.include MetroidDefines.txt
;.define DEBUG
TouchingHurtyBlock = $CB
.PATCH 07:E7E6
; Hit test Hijack
; ---------------------------------------------------------
MakeCartRAMPtr = $E96A
IsBlastTile =    $E9BE
Exit16      =    $E81D
HitTestHijack:
     LE7E6:  jsr MakeCartRAMPtr  ;($E96A)Find object position in room RAM.
         ldy #$00
         lda ($04),y     ; get tile value
         cmp #$4E
         beq $E81E
         jsr $95C0
         jsr $D651
         bcc Exit16      ; CF = 0 if tile # < $80 (solid tile)... CRASH!!!
         cmp #$A0 ; is tile >= A0h? (walkable tile)
         bcc +
			jmp IsWalkableTile
		*
         jmp IsBlastTile  ; tile is $80-$9F (blastable tiles)
		 
;--------------------------------------------------------------------
SubtractHealth = $CE92
CheckHealthStatus = $CDFA
.PATCH 07:CAA1

IsWalkableTile:
	ldy IsSamus
	beq ++
    ; special case for Samus
	cmp #$A9 ;hurtyblock?
	bne NotHurtyBlock
		lda #$01 
		sta TouchingHurtyBlock
		sec ;Return, Air block
		rts
	NotHurtyBlock:
	
	pha
	lda #$00
	sta TouchingHurtyBlock
	pla
	dey	     ; = 0
	sty SamusDoorData
	cmp #$A0	; crash with tile #$A0? (scroll toggling door)
	beq +
	cmp #$A1	; crash with tile #$A1? (horizontal scrolling door)
	bne ++
	inc SamusDoorData
*       inc SamusDoorData
*	dex
	beq +
	jsr $E98E
	jmp $E7E6

*	sec	     ; no crash
	;Exit16:
	rts
	
HurtyBlockCheck:
	lda TouchingHurtyBlock
	beq +
		lda #$01
		sta HealthLoChange
		lda #$00
		sta HealthHiChange
		jsr SubtractHealth
	*	jmp CheckHealthStatus
	
	
	
;-----------------------------------------------------------
.PATCH 07:CD7E

	jsr HurtyBlockCheck		;Check if Samus is touching Hurting Blocks