chronicleroflegends
Member
I wanted to include different ways to hurt monsters that did different amounts of damage, so I did some re-arranging and rewriting of the HandleMonsterHurt script.
One of the things I added was a subroutine that destroyed the monster and spawned the monsterdeath object. I had it working when I just killed the monster instantly with the melee weapon, but now that I have made the melee weapon just do damage, and moved this to the HandleMonsterHurt script, it doesn't work.
I have been tinkering with it for a while, but the only thing I have been able to think so far is that x may be getting corrupted at some point before it runs.
Here is my modified HandleMonsterHurt script:
One of the things I added was a subroutine that destroyed the monster and spawned the monsterdeath object. I had it working when I just killed the monster instantly with the melee weapon, but now that I have made the melee weapon just do damage, and moved this to the HandleMonsterHurt script, it doesn't work.
I have been tinkering with it for a while, but the only thing I have been able to think so far is that x may be getting corrupted at some point before it runs.
Here is my modified HandleMonsterHurt script:
Code:
;; Lets this be .included or called as a subroutine.
JSR HurtMonsterNormalSubroutine
JMP afterHurtMonsterSubroutine
HurtMonsterNormalSubroutine:
;;; what should we do with the monster?
;;; monster is loaded in x
LDA Object_vulnerability,x
AND #%00000100 ;; is it weapon immune?
BEQ notWeaponImmune
;PlaySound #SFX_MISS
JMP skipHurtingMonster
notWeaponImmune:
;; Is the monster already hurt? Cannot hurt during its invulnerability period.
LDA Object_status,x
AND #HURT_STATUS_MASK
BEQ dontskipHurtingMonster
JMP skipHurtingMonster
dontskipHurtingMonster:
JSR monsterHurtReaction_RecoilAndTempInvincibility_SR
JSR damageMonster_Normal_SR
skipHurtingMonster:
JSR monster_CleanupProjectiles_SR
RTS
HurtMonsterKickedSubroutine:
;;; what should we do with the monster?
;;; monster is loaded in x
LDA Object_vulnerability,x
AND #%00000100 ;; is it weapon immune?
BEQ notWeaponImmune2
;PlaySound #SFX_MISS
JMP skipHurtingMonster2
notWeaponImmune2:
;; Is the monster already hurt? Cannot hurt during its invulnerability period.
LDA Object_status,x
AND #HURT_STATUS_MASK
BEQ dontskipHurtingMonster2
JMP skipHurtingMonster2
dontskipHurtingMonster2:
JSR monsterHurtReaction_RecoilAndTempInvincibility_SR
JSR damageMonster_Kick_SR
skipHurtingMonster2:
JSR monster_CleanupProjectiles_SR
RTS
;; Monster Hurting Subroutines ===================================================
;; Handles Recoiling the monster and setting them to be temporarily invincible and flash.
monsterHurtReaction_RecoilAndTempInvincibility_SR:
;; Set the monster as hurt
LDA Object_status,x
ORA #%00000001
STA Object_status,x
LDA #HURT_TIMER
STA Object_timer_0,x
;; Set the monster's hurt state
;;; assume idle is in step 0
;ChangeObjectState #$00,#$02 ; WE DO NOT want the monster to reset on getting hit
;; Recoil the monster away from the side it got hurt
;;;; unfortunately this recoil is backwards
;; Is the object on an edge?
LDA Object_status,x
AND #%00000100
BNE +
;; Is the object immune to recoil?
LDA Object_vulnerability,x
AND #%00001000
BNE + ;; skip recoil because bit is flipped to ignore recoil
;; Set recoil direction
LDA selfCenterX
STA recoil_otherX
LDA selfCenterY
STA recoil_otherY
LDA otherCenterX
STA recoil_selfX
LDA otherCenterY
STA recoil_selfY
JSR DetermineRecoilDirection
+:
RTS
;; Does normal damage to a monster, also checks if they should be killed.
damageMonster_Normal_SR:
;; Do damage to the enemy
LDA Object_health,x
SEC
SBC #PLR_NMLDMG
BCC damageMonster_Normal_SR_killmonster ; Less than zero
BEQ damageMonster_Normal_SR_killmonster ; Exactly zero
STA Object_health,x
RTS
damageMonster_Normal_SR_killmonster:
JSR killMonster_SR
RTS
;; Does kick damage to a monster, also checks if they should be killed.
damageMonster_Kick_SR:
;; Do damage to the enemy
LDA Object_health,x
SEC
SBC #PLR_KICKDMG
BCC damageMonster_Kick_SR_killmonster ; Less than zero
BEQ damageMonster_Normal_SR_killmonster ; Exactly zero
STA Object_health,x
RTS
damageMonster_Kick_SR_killmonster:
JSR killMonster_SR
RTS
killMonster_SR:
;; Destroy the monster with animation
LDA Object_x_hi,x
CLC
ADC #ENEMY_DEATHIMG_HOFFSET
STA temp
LDA Object_y_hi,x
CLC
ADC #ENEMY_DEATHIMG_VOFFSET
STA temp1
DeactivateCurrentObject
CreateObject temp, temp1, #OBJ_MONSTER_DEATH, #$00, currentNametable
PlaySound #SND_SPLAT
;;;;;;;;;;;;;;;;;; ok, so now we also add points to score
;LDY Object_type,x
;LDA ObjectWorth,y
;STA temp
; AddValue #$03, GLOBAL_Player1_Score, temp
;arg0 = how many places this value has.
;arg1 = home variable
;arg2 = amount to add ... places?
;; and this should trip the update hud flag?
;;;;
;; Add to the player's score
TXA
STA tempx ;Problem colliding with solid objects
AddValue #$08, myScore, #$01, #$00
;STA hudElementTilesToLoad
; LDA #$00
; STA hudElementTilesMax
; LDA DrawHudBytes
; ora #HUD_myScore
; STA DrawHudBytes
UpdateHud HUD_myScore
LDX tempx
;; Spawn any monster drops
JSR HandleDrops
;; Update monster scrolling info
;JSR HandleToggleScrolling ;; I DISABLED SCROLLING SO NO NEED THIS
;; Check if we killed the last monster
;CountObjects #$00001000, #$00
;BEQ +
;JMP ++
;+
;.include SCR_KILLED_LAST_MONSTER
;++
RTS
monster_CleanupProjectiles_SR:
LDX tempx
; Check if we are already at the hard limit for player projectiles.
LDA projectileLimit
CMP #PLR_MAXPROJECTILES
BEQ skipReturnPlayersProjectile
;; what should we do with the projectile?
INC projectileLimit ; give the player back a bullet
skipReturnPlayersProjectile:
DeactivateCurrentObject
RTS
afterHurtMonsterSubroutine: