[SOLVED] Destroy Object Help (4.5.6)

5kids2feed

Well-known member
Good morning!

I'm trying to make an input where if I press it, it'll destroy an object. It is my 3rd object.. so I know that would be #$02.

But how would I go about coding with DestroyObject to achieve this?

Thank you as always!
 

SciNEStist

Well-known member
you would have to cycle through the on screen objects and check each if they match. Im doing something similar in my squirrel chaser game. I'll post some code when I get home unless someone else already does.
 

CutterCross

Active member
You'll need to be more specific on whether you want to destroy any object with Object_type #$02 OR destroy the 3rd object drawn to the screen. The latter is easy. Push the current object index in X to the stack, load X with the object index, then use the DestroyObject macro, then restore X with the value pulled off the stack.

Code:
;;;; untested
    TXA
    PHA
    LDX #$02
    DestroyObject
    PLA
    TAX
    RTS


If you meant destroying an object with Object_type #$02, meaning it could be any drawn object on the screen, you'll have to loop through all the objects to find which object index corresponds with that Object_type.

Code:
;;;; untested
    TXA
    PHA
    LDX #$01    ;; Player object is always Object_type #$00,
                ;; so no need to check its Object_type
startObjectTypeLoop:
    LDA Object_type,x
    CMP #$02
    BEQ +    ;; If Object_type is #$02, branch out of the loop.
            ;; Do DestroyObject
    INX
    CPX #TOTAL_MAX_OBJECTS
    BCS ++    ;; If X exceeds total max objects, branch out of the loop.
            ;; Don't destroy anything.
    JMP startObjectTypeLoop
    
    +
    DestroyObject
    
    ++
    PLA
    TAX
    RTS
 

5kids2feed

Well-known member
CutterCross.. you always cut a way into my heart. That was it you sexy S.O.B.!! Thank you so much and thank you for your patience with all of my questions as well.

Thank you for the 1st part of that code too.. I can use that in future projects.
 
Top Bottom