Kanbei85
Member
For reasons that remain a complete mystery, Joe and/or the devteam, such as it is, for NESmaker did not see fit to enable the use of the strength and defense system already present in the GUI. Out of the "box", NESmaker will only enable your weapon to do a single hitpoint of damage to any monster, and likewise a monster can only do a single HP of damage to the player.
Out of desperation, I began doing my own study, alongside Francois Brodeur. With his help, and by following a tiny bit of assembly tutorial, I have now got the str/def system working!
First, you will need to add two variables to the Zero Page RAM tab under Project settings: tempDE (for defense) and tempWD (for weapon damage).
Next, add Object_strength and Object_defense as Object Variables.
Last, you will need to add one variable under User Variables: myDefense. This is because I noticed that, for whatever reason, the player1_object variable "defense" value gets cleared to 0 if you die.
Now in your "script/Define Scripts/Subroutines/Create state" Add this between "STA Object_health,x" and "return bank". (Courtesy of Francois)
The result is now that strength and defense are available in the scripts to use as needed for objects (i.e. weapons and monsters). These also work for the player object, but as I said, for some reason they seem to get cleared when the player dies. This could probably be fixed in its own right, but I found it easier to use User Variables myHealth and myDefense instead.
I have gotten this to work for my game (WIP) now in both my Player Hurt and Monster Hurt scripts. I'll include the relevant bits below and you can adapt this to your own scripts as needed. What this does is a simple series of math equasion:
Strength - Defense = Damage
Health - Damage = Updated health
Player Hurt:
Monster Hurt:
Out of desperation, I began doing my own study, alongside Francois Brodeur. With his help, and by following a tiny bit of assembly tutorial, I have now got the str/def system working!
First, you will need to add two variables to the Zero Page RAM tab under Project settings: tempDE (for defense) and tempWD (for weapon damage).
Next, add Object_strength and Object_defense as Object Variables.
Last, you will need to add one variable under User Variables: myDefense. This is because I noticed that, for whatever reason, the player1_object variable "defense" value gets cleared to 0 if you die.
Now in your "script/Define Scripts/Subroutines/Create state" Add this between "STA Object_health,x" and "return bank". (Courtesy of Francois)
Code:
LDA ObjectStrengthDefense,y
AND #%11110000
ROR
ROR
ROR
ROR
STA Object_strength,x
LDA ObjectStrengthDefense,y
AND #%00001111
STA Object_defense,x
The result is now that strength and defense are available in the scripts to use as needed for objects (i.e. weapons and monsters). These also work for the player object, but as I said, for some reason they seem to get cleared when the player dies. This could probably be fixed in its own right, but I found it easier to use User Variables myHealth and myDefense instead.
I have gotten this to work for my game (WIP) now in both my Player Hurt and Monster Hurt scripts. I'll include the relevant bits below and you can adapt this to your own scripts as needed. What this does is a simple series of math equasion:
Strength - Defense = Damage
Health - Damage = Updated health
Player Hurt:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DAMAGE SECTION
;DEC myHealth ;old Code from Joe, just decreases by 1 increment
;LDX player1_object ;This doesn't work because player1_object defense is getting set to 00 after a death
;LDA Object_defense,x
;STA tempDE ;Player Defense stat in tempDE
LDX otherObject ;Loading monster strength
LDA Object_strength,x
SEC ;Strength - player defense
SBC myDefense
STA tempWD ;Monster strength - player defense value set to tempWD
;LDX player1_object ;Loading player health to accumulator
;LDA Object_health,x
LDA myHealth
SEC
SBC tempWD
BMI +healthBelowZero
BEQ +healthBelowZero
JMP +notDeadYet
+healthBelowZero
JMP +playerHealthIsZero
+notDeadYet
;STA Object_health,x ;this would update the Player Object health stat, rather than the User Variable myHealth
STA myHealth
UpdateHudElement #$01 ;;Update HUD Hearts
ChangeActionStep player1_object, #$07 ;;Send player object into Action Step 07
PlaySound #sfx_GetHurt
Monster Hurt:
ChangeActionStep temp, #$07
LDX otherObject
LDA Object_defense,x
STA tempDE ;;tempDE is monster defense
LDX selfObject ;;now Player Weapon Object is in X register
LDA Object_strength,x ;;Weapon Strength is in Accumulator
SEC ;;Start Subtract
SBC tempDE ;; Monster Defense subtracted from Accumulator (Weapon Strength)
BMI +End ;;if the result is negative, then no damage happens, so end.
BEQ +End
STA tempWD ;;tempWD is player weapon damage after going through defense
LDX otherObject ;;Loading Monster Health
LDA Object_health,x
SEC ;;Subtracting Weapon Damage from Health
SBC tempWD
BEQ +killThisObject ;;if health is 0, kill
BMI +killThisObject ;;if health is negative, kill
STA Object_health,x ;;Save monster health
JMP +End
+End
JMP +doSkipKILLINGthisObject ;; Return
Last edited: