"Destroy all enemies and monitors on screen" code

Discussion in 'Tutorials Archive' started by MarkeyJester, Jun 5, 2011.

Thread Status:
Not open for further replies.
  1. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    So, I was talking with "PsychoRFG" about his "destroy all enemies" code which didn't work out well for him/her, I decided to write one myself because... well why the hell not, and share it bacause.... well why the hell not.



    ; ===========================================================================
    ; ---------------------------------------------------------------------------


    ; Subroutine to destroy all enemies/monitors/etc on screen


    ; ---------------------------------------------------------------------------


    DestroyEnemies:


    lea ($FFFFD800).w,a1 ; load start of level object ram


    moveq #$5F,d6 ; set repeat times


    DE_CheckNext:


    tst.b (a1) ; is the object valid?


    beq DE_NextObject ; if not, branch


    lea DE_BossList(pc),a2 ; load start of boss ID list


    bra DE_CheckBoss ; continue


    DE_NoEndList:


    cmp.b (a1),d0 ; is it a boss?


    beq DE_NextObject ; if so, branch


    DE_CheckBoss:


    move.b (a2)+,d0 ; load boss ID


    bne DE_NoEndList ; if it's not the end of the list, branch


    cmpi.b #$5F,(a1) ; is it a bomb fuse?


    bne DE_NoBombFuse ; if not, branch


    cmpi.b #$04,$28(a1) ; is it a fuse and not the bomb?


    beq DE_DestroyNoAnimal ; if so, branch


    DE_NoBombFuse:


    tst.b $01(a1) ; is the object displayed on screen?


    bpl DE_NextObject ; if not, branch


    cmpi.b #$20,(a1) ; is it the ball of a ball hog?


    beq DE_DestroyNoAnimal ; if so, branch


    cmpi.b #$5F,(a1) ; is it a bomb?


    bne DE_NoBomb ; if not, branch


    DE_DestroyNoAnimal:


    move.b #$3F,(a1) ; change bomb into an explosion object


    sf.b $24(a1) ; clear routine counter


    bra DE_NextObject ; skip for next object


    DE_NoBomb:


    cmpi.b #$26,(a1) ; is it a monitor?


    bne DE_NoMonitor ; if not, branch


    cmpi.b #$04,$24(a1) ; is the monitor destroyed?


    bge DE_NextObject ; if so, branch


    move.b #$04,$24(a1) ; set to correct destory routine


    bra DE_NextObject ; skip for next object


    DE_NoMonitor:


    cmpi.b #$50,(a1) ; is it a yadrin?


    beq DE_Destory ; if so, branch


    move.b $20(a1),d0 ; load touch type


    beq DE_NextObject ; if it's not valid, branch


    andi.b #$C0,d0 ; get only types


    bne DE_NextObject ; if it's not an enemie, branch


    DE_Destory:


    movem.l d0-a6,-(sp) ; store register data


    move.w $12(a0),-(sp) ; store Y speed


    clr.w $12(a0) ; set no Y speed


    jsr touch_killenemy ; run destroy code


    move.w (sp)+,$12(a0) ; reload Y speed


    movem.l (sp)+,d0-a6 ; reload register data


    DE_NextObject:


    lea $40(a1),a1 ; advance to next object slot


    dbf d6,DE_CheckNext ; repeat til all object slots are done


    rts ; return


    ; ===========================================================================


    ; ---------------------------------------------------------------------------


    ; Boss ID's to check (00 means end of list)


    ; ---------------------------------------------------------------------------


    DE_BossList: dc.b $3D,$73,$75,$77,$7A,$82,$85,$00


    even


    ; ---------------------------------------------------------------------------


    ; ===========================================================================



    Call this routine wherever you want, I'll leave that down to you, but this will destory all enemies that obtain animals, monitors, and the bombs object in SLZ that have no animals, that are currently on screen.


    I've put one aditional thing in by request of PsychoRFG which is:



    cmpi.b #$20,(a1) ; is it the ball of a ball hog?
    beq DE_DestroyNoAnimal ; if so, branch



    Which destroys the projectile of the ball hog, you can remove it, or do the same for the Crabmeat and buzzbomber's projectiles in the same mannor.


    EDIT: Fixing stuff as we go along.
     
    Last edited by a moderator: Jun 5, 2011
  2. Psycho RFG

    Psycho RFG Well-Known Member Member

    Joined:
    Feb 22, 2011
    Messages:
    234
    Thanks for the final code, fixes and all the help. I have to thank Vladikcomper for the help at the begining of the creation of this feature.
     
  3. Crash

    Crash Well-Known Member Member

    Joined:
    Jul 15, 2010
    Messages:
    302
    Location:
    Australia
    If anyone wants to use this with the SVN disassembly, find this line in "\_incObj\sub ReactToItem.asm":



    @breakenemy:



    and change it to:



    @breakenemy:
    Touch_KillEnemy:
     
  4. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Or why not just changing:



    jsr Touch_KillEnemy ; run destroy code



    Into:


    Code:
    		jsr	breakenemy				; run destroy code
    
     
    Last edited by a moderator: Jun 6, 2011
  5. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    @breakenemy is a local label, so this won't work (it will generate a compilation error that the label wasn't defined)


    This can work if only you rename it into "breakenemy" (without @), the idea with adding "Touch_KillEnemy:" is easier though.
     
  6. Hitaxas

    Hitaxas Retro 80's themed Paladins Twich streamer Member

    Joined:
    Aug 13, 2007
    Messages:
    167
    I was talking to you about this just the other day. Thank you so very much for posting this, as I eventually give up (I cannot tell you how many different ways I tried to pull this off and failed).


    Edit: And damn, this looks similar to that S3K routine I was talking about on #SSRG. Well, guess I know what that code did NOW.


    Edit2: Upon testing this, I can say it works with a few tweaks for S2, however it seems that objects loaded by the explosion can also be killed, I tried to make a check for the specific object (flowers from enemies), but the code just doesn't work then. it also seems to create multiples of the flowers from enemies, meaning it runs the code to load explosions multiple times, or even that it also "kills" explosions.
     
    Last edited by a moderator: Jun 8, 2011
  7. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Ah, well good to know.


    Also, what lable/name is that S3K routine? I'm interested in seeing how they did it now =O
     
  8. Hitaxas

    Hitaxas Retro 80's themed Paladins Twich streamer Member

    Joined:
    Aug 13, 2007
    Messages:
    167
    sub_104EA , This is strikingly similar to the code you have posted.


    Also, this is my edit of the code, moddified for 2007 S2 DisASM.



    ; ------------------------------------------------------------------------------------
    ; Subroutine to destroy all enemies on screen


    ; ------------------------------------------------------------------------------------


    INSTAKILL:


    tst.b (Current_Boss_ID).w ; is this a boss fight?


    bne IK_RETURN ; Don't instakill bosses.


    lea (Object_RAM+$400).w,a1 ; load start of level object ram


    moveq #$6F,d6 ; search to the end of table


    IK_CheckNext:


    tst.b (a1) ; is there an object in this slot?


    beq IK_NextObject ; if not, branch


    tst.b $01(a1) ; is the object displayed on screen?


    bpl IK_NextObject ; if not, branch


    move.b collision_flags(a1),d0 ; is the object collidable?


    beq IK_NextObject ; if not, branch


    and.b #$C0,d0 ; is the object an enemy?


    beq IK_LoadExplosion ; if it is, kill the enemies! =D


    bra IK_NextObject ; if not, keep looking


    IK_LoadExplosion:


    move.b #$27,(a1) ; change enemy into an explosion object


    move.b #0,routine(a1) ; Clear the routine counter


    bset #6,render_flags(a1) ; Set render flags to 6


    bra IK_NextObject ; skip for next object


    IK_NextObject:


    lea next_object(a1),a1 ; advance to next object slot


    dbf d6,IK_CheckNext ; repeat til all object slots are done


    IK_RETURN:


    rts ; return


    ; ================================================================================



    EDIT: I cleaned up the code a bit.
     
    Last edited by a moderator: Jun 8, 2011
Thread Status:
Not open for further replies.