baardbi
Well-known member
In NESmaker there's a great macro that lets you count objects with a certain object flag set. However this does not work if you want to count certain objects without an object flag set or just a certain object type. I made a new modified macro based on the default one in NESmaker. It counts a certain object type (number). This could be useful if you have different player weapon objects but you only want to count one of them.
To use this macro, just copy this code into a new file and call it CountObjectType.asm. Then put that file in the Macros folder: ...\GameEngineData\Routines\BASE_4_5\System\Macros
Example:
Object numbers start from 0 at the top (player object) then continues down. The first monster object is object 16, then second monster is 17 and so on.
To use this macro, just copy this code into a new file and call it CountObjectType.asm. Then put that file in the Macros folder: ...\GameEngineData\Routines\BASE_4_5\System\Macros
MACRO CountObjectType arg0
;; arg0 - what object type (number) are we talking about (what objects are we counting?)
LDA arg0
STA tempA
TXA
PHA
TYA
PHA
LDA #$00
STA temp
LDX #$00
countObjectLoop:
LDA Object_status,x
AND #%10000000
BEQ +skipCountingThisObject
LDA Object_type,x
CMP tempA
BNE +skipCountingThisObject
INC temp
+skipCountingThisObject
INX
CPX #TOTAL_MAX_OBJECTS
BNE countObjectLoop
PLA
TAY
PLA
TAX
LDA temp ;; now the accumulator holds the number of that type of object still activated.
ENDM
Example:
CountObjectType #10 ;;; Bomb
CMP #2
BEQ +doThis
JMP +dontDoThis
+doThis
Object numbers start from 0 at the top (player object) then continues down. The first monster object is object 16, then second monster is 17 and so on.