Language…
19 users online: Alex No,  AmperSam,  Anorakun, Big Brawler, DanMario24YT, GiraffeKiller, Green, Green Jerry, h.carrell, Hammerer, JikissGamer, LadiesMan217, MaffYuu, Mecke1990, Metal-Yoshi94, Ray Hamilton,  StayAtHomeStegosaurus, Tulip Time Scholarship Games, Zatara - Guests: 300 - Bots: 431
Users: 64,795 (2,369 active)
Latest user: mathew

Adding level end routine to a sprite

I'm trying to add a level ender to the Stationary Magikoopa custom sprite (code) to be activated upon its death. In order to do so I've tried to find the sprite's death routine somewhere, but in vain. Makes me think it uses some 'standard' sprite death routine, hidden inside one of the obscure JSLs.

Where in the code would I need to insert the level ending routine for this to work?
I fiddled around the sprite for fun and didn't expect to get any results, but I got something semi-working. After some testing it's not 100% consistent, maybe somebody can shed some light on this matter.

The original code of the Attacking segment:

Code
Attacking:
    STZ !15D0,x
    JSL $01803A|!BankB              ; interact with Mario and with other sprites
    %SubHorzPos()                   ;\ make sprite face Mario
    TYA                             ; |
    STA !RAM_SpriteDir,x            ;/
    LDA !1540,x                     ;\ if attack cycle not complete,
    BNE .DontReset                  ;/ branch
    LDA #$70                        ;\ reset cycle
    STA !1540,x     


Since this is the beginning of the sprite routine, I thought I could just insert a check for the sprite state in there and end level if it's not alive anymore:

Code
Attacking:
    STZ !15D0,x
    JSL $01803A|!BankB              ; interact with Mario and with other sprites
    %SubHorzPos()                   ;\ make sprite face Mario
    TYA                             ; |
    STA !RAM_SpriteDir,x            ;/
    LDA !14C8,x			    ;\ check sprite state
    CMP #$08	                    ;| don't end level if alive
    BEQ +		            ;/ 
    INC $73C6|!Base2                ;\
    LDA #$FF                        ;| end level
    STA $7493|!Base2                ;|
    LDA.b #!ExitSong                ;|
    STA $7DFB|!Base2                ;/
+   LDA !1540,x                     ;\ if attack cycle not complete,
    BNE .DontReset                  ;/ branch
    LDA #$70                        ;\ reset cycle
    STA !1540,x     


Alright. So, after testing it, it sort of works... most of the time. Doing the fight a few times in succession (about 5-6), I noticed following things:

-) one time, killing the Magikoopa did not end the level
-) sometimes, the Magikoopa magic will spawn different sprites instead of the yellow koopa after hitting a turn block (I've had a moving coin and a thwomp)

Obviously my fiddlings were just for testing purposes, so I didn't expect them to work flawlessly. But maybe someone is able to point out what causes those inconsistencies I witnessed?