Branch instructions for AI

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Branch instructions for AI
by on (#809)
I've been using something like:

Code:
   ldx S1_X
   cpx S7_X
   bpl incxE1
   jmp nexte
incxE1:
   inc S7_X
   jmp endAI
nexte:
   dec S7_X


Which works great, but now that I'm coding the last boss I need something different. I want the "enemy" too chase after the main character as a whole, but I'm treating the "whole" enemy as four different sprites (this is pretty much necessary for what I'm doing).

That makes the 4 "parts" of the last boss go on their own accord depending on where they are (an effect of BPL), which eventually makes all 4 "parts" go into one little 8x8 square, but I don't want that.

Basically all I want is to load the main characters sprite's axises and the
boss "part" axises and
IF main sprite X > boss part 1 X THEN boss part 1 X = boss part 1 X - 1
IF NOT THEN boss part 1 X = boss part 1 X + 1
and so on...

Naturally if the main sprite and the boss part are EQUAL TO on either axis it will cause the boss part to constantly switch position, but I want that so it's fine. That would make all the boss parts stay the same difference away from each other *unless* the main character went in the middle of the boss parts (which would then make the boss parts go into each other), I can live with this also, but if there's away around it I really don't want that to happen.

So basically I need some kind of routine to find the greater than...Is there a branch instruction for "greater than" cause I couldn't find one.
thanks

by on (#810)
What you want to do is branch on the CARRY flag - this will get you less-than-or-equal (for BCS) and greater-than (for BCC) - to filter out the 'equals' part, just use a BEQ first.

Code:
LDA value_A
CMP value_B
BEQ a_equals_b
BCC a_greater_than_b
BCS a_less_than_b
Thanks...
by on (#811)
Thanks :-)

I knew what the branches were and what they branched on, but didn't know what the CMP instructions set. Lol, I truthfully don't understand BPL, I accedentally put it in the AI routine thinking it was a "greater than" branch and it ended up with really good AI for some reason. ie. the main characters sprite is Y = 12, and the enemy sprite is Y = 222, the enemy would move down (so to loop around to 00 and eventually get to 12) instead of up (which a greater than instruction would have done) because it's closer that way.

Hmmm, my games just about done. Just need to add an ending and some credits and it's finished :-). It's an NROM 32 KBs PRG, 8 KBs CHR and I guess I'll need to test it on the real NES once I'm done (should be tomorrow, after church), to make sure it works on the real thing.

by on (#812)
CMP works just like SBC, but without using the carry flag and doesn't store the result (except in the status flags). Just so you know.

If you need help with testing before you release it, you can email the file to me whenever it's ready and I could run it on my cart. As long as the mirroring isn't too important (it'd be best if it runs ok in 4-screen mode).
...
by on (#816)
Quote:
CMP works just like SBC, but without using the carry flag and doesn't store the result (except in the status flags). Just so you know.


Ah, that makes sense...thanks.

Quote:
If you need help with testing before you release it, you can email the file to me whenever it's ready and I could run it on my cart. As long as the mirroring isn't too important (it'd be best if it runs ok in 4-screen mode).


If I could, that'd be great. It should work with 4-screen mirroring, I took out the scrolling engine because I didn't have enough memory to store all the nametables,I tried compressing them, which would've allowd me to have 4x the nametable (since each nametable would have been compressed down to 256 bytes), but I couldn't get it working so I gave up (but if I needed to I could prolly accomplish this) because it really was important for such a simple game.

The only time I use somethnig other than nametable A is when I switch the 2 bottom bits of $2000, to get a blank screen so I'm guessing it'll still work.

Overall the premise sort of works like Zelda when your in a dungeon except it's more primitive. Don't mind the story too much, I had to make it for a school project so I needed put an appropriate theme to go along with what kind of story method we were learning in the class and so the story is pretty corny + stupid.

I should get the game done today and I'll prolly send it tomorrow. thanks :-)