Create Monster Pathing

Oonan

New member
I am not sure if it is from my lack of understanding of ASM or my lack on knowledge with NES Maker, probably both. I am not able to alter how monsters move within my game. I am trying to have monsters move up, when they reach a point on the screen, move down. Think of a bouncing ball.

I am using the simple shooter module as a base. I created a script, see below, added it to AI_12 and added it as an action to my monster. I tried to loop and repeat as an end action. I have also swapped out using yPrev with my a user variable I created called previous. I have tried to use the hard coded values as binary and hex, same effect. I can get the monster to move up but it never stops nor comes down, just keeps flying off the screen.

Code:
  LDA Object_y_hi,x
  CMP #$23
  BEQ moveDown
  CMP #$80
  BEQ moveUp
  CMP yPrev
  BCC moveUp

moveDown:
  STA yPrev
  LDA #MOVE_DOWN
  JMP done

moveUp:
  STA yPrev
  LDA #MOVE_UP
  JMP done

done:
  STA Object_movement,x

I feel part of my problem is using yPrev. I think this is only used with aimed physics, which I am not using. That still does not explain why using a variable did not work, maybe I have to reference it differently I am not sure of the value that is actually stored in Object_y_hi and can't really find anything that states its use. I did find many scripts using it and it seems like I am doing things correctly but clearly I am not.

Any help with this would be greatly appreciated. I am really trying to understand all of this but not being able to make a simple script is a major hurdle I need to get over.
 

dale_coop

Moderator
Staff member
When the movement is set... the movement continues until we told it to stop.

So, you could just check your boundaries... if inferior to the top bound, change the move to Down... and if superior to the bottom bound, change the move to up... else, skip the code.

It could look like:
Code:
  LDA Object_y_hi,x
  CMP #$23
  BCC moveDown
  CMP #$80
  BCS moveUp
  ;CMP yPrev
  ;BCC moveUp

  JMP skipMov

moveDown:
  ;STA yPrev
  LDA #MOVE_DOWN
  JMP done

moveUp:
  ;STA yPrev
  LDA #MOVE_UP
  JMP done

done:
  STA Object_movement,x
  
skipMov:


And make sure that "action" is "repeat" every short timer (use a small timer value like "1").
 

Oonan

New member
Thanks Dale, I will try your solution too.

I came to a similar solution, not as concise as yours but it does something similar. After banging my head against a wall on this I was able to get the debugger going in Mesen. I tracked the values and found a couple of interesting things. One: I had my speed set way to hi for the monster. This caused the monster to move off screen before the next cycle of my script. Two: the cycle times it takes to get the script to fire are much slower than I expected. I guess I was expecting that every pixel movement was evaluated, why I thought that, I have no idea. It sometimes take anywhere between 6 - 12 pixels for each execution. In my case with my previous code the comparisons where way out of range. Your solution allows the values to have a larger range, resulting in the object moving up and down.

Thank you again for your insight and help. I have so much to learn and appreciate any guidance I can get. I got my monster to move mostly the way I want, just need to improve the cycle times so I have finer control. This is probably a limitation of the NES CPU which isn't a big deal, I will just need to learn to adapt, which is a good thing.

Thank you again Dale.
 
Top Bottom