Bug fix patch: Enemy placement at the correct coords

FrankenGraphics

New member
I saw someone lamented in some thread that monster placements are not WYSIWYG (what you see is what you get) between the editor and the actual game. The unintended behaviour is thankfully in the engine, so it can be fixed easily.

I added two lines that corrects the Y position displacement.

download and replace your LoadMonsters.asm with the attached file.


This bug fix was only tested for the adventure module, in other words without gravity. If you're building a platformer and this script gives you trouble, let me know. There's a hypothetical chance monsters get stuck in platforms if spawned right on top of them. It should be fine, but in case someone reports that it isn't, i'll come up with something.


Notes for advanced use:
If you want finer control per object type, you can add exceptions for certain object types right there if you want to place them at a specific pixel offset vs tile position. It's basically the same process as in my earlier tile collision ignore modification, but we use the y register for indexing instead of the x.
 

Attachments

  • LoadMonsters.zip
    1.5 KB · Views: 97

dale_coop

Moderator
Staff member
Thanks FrankenGraphics.
Nice (temporary) fix for that. I hope this will be fixed in the tool itself (as it should be?) ...
(I think there is the same issue with the player placement if taller than 16pixels)
 

FrankenGraphics

New member
Hmm... i'm under the impression the bug is in the game code, not the editor. Monster placement data is stored in the high nybble of the mon1SpawnData array so it can only be a factor of 16; starting at 0. In other words, placement data aligns with the attribute grid. This also aligns well with what the editor shows, so the editor is accurate in this regard. Somewhere (though i didn't care to spend time finding out exactly where), this is offset by 8 pixels. I simply compensated for that by subtracting 8. Not elegant, but works.

On the other hand, i seem to remember the editor has another unrelated display bug in regards to odd-height objects (such as a 3-tile high player object or the like).
Edit: nope, seems i remembered it wrong. My 3-tile high objects are correctly aligned.
 

dale_coop

Moderator
Staff member
Sounds perfect!
I will test your modification tonight.
And check with the editor palcements too.

As usual, thank you FrankenGraphics for your sharing :)
 

FrankenGraphics

New member
Good news! I stumbled upon the root cause of the problem when modifying something else, so you don't need this patch if you want to correct it at its source. Embarrassingly, of course it was the function right above the one the patch modified, haha.

Go to LoadMonsters.asm, string search for plannedIndexForThisMonster. It should look like this:

Code:
plannedIndexForThisMonster: 
    LDa objectID,y
    
    STA ObjectToLoad

    CMP #3
    
    bne +
        lda #24
        sta tempy
        +
    beq +
        lda #8
        STA tempy
        +

What it does is setting an offset (8) for projectiles, and another (24) for all other objects when spawning. If most of your objects(monsters typically are 2 tiles high, then this should be 16, not 24, unless you *want* the placements to be off grid by default which may look good in some games. If you have multiple differently sized enemy objects etc, this is the place to be entering special clauses for each of them so that they are accurately populated according to your editor placement. Or you can offset placements so they are off-grid on purpose if you want more fine-pitched control over enemy placement, although you may need to be a bit clever about what denominator to use (objectID will affect every monster/object of that type).

You may also automate the offset based on size; there should be an object variable for checking height or number of tiles or something like that.

Have fun!
 
Top Bottom