(4.5.9) Hide monster if certain values don't match

DS0

New member
Hello everyone, I've been stuck on this for a good while now. I'm making a game in which enemies can move around rooms across the game. Their visual sprites are represented as monsters on a screen. The enemy's current room is stored as a variable that matches the screen it should be in. If the enemy's room value doesn't match the screen the player is looking at, I want it be hidden from the player's view. However, this has truly thrown me for a loop like nothing else. No matter what I try, this simple concept just won't work how I want it to.

I tried using Action Steps, but I couldn't seem to get it to reliably affect only the monster, it's either changing the Action Step of every single object on screen or none of them. I also tried getting the Object ID of the monster so I could at least only change it, but that also affected either everything or nothing. I tried setting up Monster Bits so I could fix the everything or nothing issue, which didn't work. I feel like I'm missing something super simple, but I just cannot figure it out. Any help would be greatly appreciated.
 

dale_coop

Moderator
Staff member
You could loop through all the objects (in the Post Screen Load script), check if the room matches and if the object is a monster and destroy it ?

Here's a code that loops on object and destroy all the monsrer objects:
Code:
LDX #$00
-loopMonsters:
  LDA Object_type,x
  CMP #$10  ;; any monster object
  BCC +nextObj
      ;; it's monster, what to do with it:
      DestroyObject
  +nextObj:
INX
CPX #TOTAL_MAX_OBJECTS
BNE -loopMonsters
 

DS0

New member
Thanks a ton, Dale! It works really well! I went in and made a couple adjustments so that I could fit in multiple enemies, mostly just adding in bonster bits following James' monster bits tutorial.

Here's what I've ended up with so far, will play with it some more:

Code:
    LDX #00

-monsterLoops:
    LDA Object_type,x
    CMP #10 ;checks for monster
        BCC +nextObj
        TXA
        STA temp ;might take this out, it's just here in case I wanna try using action steps instead of destruction
        LDY Object_type,x
        LDA MonsterBits,y
        AND #%00000100 ;each flag corresponds to a certain enemy, will add more checks for more enemies
        BNE handleBonnie
        
handleBonnie:
    LDA Object_screen
    CMP bonnieRoom
    BEQ +nextObj
        DestroyObject
    
+nextObj:
    INX
    CPX #4
    BNE -monsterLoops
 
Top Bottom